Exemplo n.º 1
0
  /**
   * Converts any object to a string. If o is an object array, it invokes {@link ArraysX#toString}
   * to make the string more readable.
   */
  public static final String toString(Object o) {
    if (o == null) return null;
    if (o instanceof Date) return DateFormats.format((Date) o, false);
    if (o instanceof Class) {
      final Class cls = (Class) o;
      final String clsnm = cls.getName();
      if (!clsnm.startsWith("$Proxy")) return "class " + clsnm;

      final Class[] ifs = cls.getInterfaces();
      switch (ifs.length) {
        case 0:
          return "class " + clsnm;
        case 1:
          return "proxy " + Objects.toString(ifs[0]);
        default:
          return "proxy " + Objects.toString(ifs);
      }
    }
    if (o.getClass().isArray()) {
      if (o instanceof Object[]) return ArraysX.toString((Object[]) o);
      if (o instanceof int[]) return ArraysX.toString((int[]) o);
      if (o instanceof short[]) return ArraysX.toString((short[]) o);
      if (o instanceof long[]) return ArraysX.toString((long[]) o);
      if (o instanceof double[]) return ArraysX.toString((double[]) o);
      if (o instanceof byte[]) return ArraysX.toString((byte[]) o);
      if (o instanceof boolean[]) return ArraysX.toString((boolean[]) o);
      if (o instanceof char[]) return ArraysX.toString((char[]) o);
      if (o instanceof float[]) return ArraysX.toString((float[]) o);
    }
    return o.toString();
  }
Exemplo n.º 2
0
  /**
   * Clones the specified object. Use clone() if Cloeable. Otherwise, try to serialize/deserialize
   * it by use of MarshalledObject.
   *
   * <p>If o is null, null is returned.
   *
   * @exception SystemException if failed to clone
   */
  public static final Object clone(Object o) {
    if (o == null) return o;

    try {
      final Class<?> kls = o.getClass();
      if (kls.isArray()) return ArraysX.clone(o);

      if (o instanceof Cloneable) {
        try {
          return kls.getMethod("clone").invoke(o);
        } catch (NoSuchMethodException ex) {
          if (log.debugable()) log.debug("No clone() for " + kls);
        }
      }

      // :TODO: MarshalledObject is said with very bad performance, change it
      // if exists other good deep clone method.
      return new MarshalledObject<Object>(o).get();
    } catch (Exception ex) {
      throw SystemException.Aide.wrap(ex);
    }
  }
Exemplo n.º 3
0
 /**
  * Constructor with an array of data.
  *
  * @param data an array data to be grouping.
  * @param cmpr a comparator implementation help group the data. you could implements {@link
  *     GroupComparator} to do more grouping control.<br>
  *     At 1st phase, it calls {@link Comparator#compare(Object, Object)} or {@link
  *     GroupComparator#compareGroup(Object, Object)} to sort the data.<br>
  *     At 2nd phase, it calls {@link Comparator#compare(Object, Object)} or {@link
  *     GroupComparator#compareGroup(Object, Object)} to decide which data belong to which group.
  *     In this phase it also invoke {@link #createGroupHead(Object[], int, int)} and {@link
  *     #createGroupFoot(Object[], int, int)} to create head of foot Object of each group.<br>
  *     At 3rd phase, it calls {@link Comparator#compare(Object, Object)} to sort data in each
  *     group.<br>
  * @param col column index associate with cmpr.
  * @param clone whether to clone <code>data</code>. If not cloning, data's content will be
  *     changed.
  * @since 5.0.6
  */
 public GroupsModelArray(D[] data, Comparator<D> cmpr, int col, boolean clone) {
   if (data == null || cmpr == null) throw new IllegalArgumentException("null parameter");
   _nativedata = clone ? (D[]) ArraysX.duplicate(data) : data;
   _comparator = cmpr;
   group(_comparator, true, col);
 }