Esempio n. 1
0
  public static @infix void toString(Object o, StringBuilder builder) {
    if (o == null) {
      builder.append("null");
      return;
    }

    Class c = o.getClass();
    if (c == String.class) {
      builder.append((String) o);
      return;
    }
    if (c == boolean[].class) {
      BooleanArray.toString((boolean[]) o, builder);
      return;
    }
    if (c == byte[].class) {
      ByteArray.toString((byte[]) o, builder);
      return;
    }
    if (c == short[].class) {
      ShortArray.toString((short[]) o, builder);
      return;
    }
    if (c == char[].class) {
      CharArray.toString((char[]) o, builder);
      return;
    }
    if (c == int[].class) {
      IntArray.toString((int[]) o, builder);
      return;
    }
    if (c == long[].class) {
      LongArray.toString((long[]) o, builder);
      return;
    }
    if (c == float[].class) {
      FloatArray.toString((float[]) o, builder);
      return;
    }
    if (c == double[].class) {
      DoubleArray.toString((double[]) o, builder);
      return;
    }
    if (c.isArray()) {
      deepToString((Object[]) o, builder);
      return;
    }

    builder.append(o.toString());
  }
Esempio n. 2
0
  public static @infix <T> String toString(T[] array) {
    if (array == null) {
      return "null";
    }

    int len = array.length;
    if (len <= 0) {
      return "[]";
    }

    StringBuilder buf = new StringBuilder(len * 10);
    buf.append('[').append(array[0]);
    for (int i = 1; i < len; i++) {
      buf.append(", ");
      buf.append(array[i]);
    }
    return buf.append(']').toString();
  }
Esempio n. 3
0
  public static @infix void deepToString(Object[] array, StringBuilder builder) {
    if (array == null) {
      builder.append("null");
      return;
    }

    int len = array.length;
    if (len <= 0) {
      builder.append("[]");
      return;
    }

    builder.append('[');
    toString(array[0], builder);
    for (int i = 1; i < len; i++) {
      builder.append(", ");
      toString(array[i], builder);
    }
    builder.append(']');
  }