Complete the java.util.Arrays#toString family of methods

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin 2013-10-17 15:05:28 -05:00
parent 396c0822cd
commit a9ecf1eaed

View File

@ -17,6 +17,23 @@ public class Arrays {
return asList(a).toString();
}
public static String toString(boolean[] a) {
if (a == null) {
return "null";
} else {
StringBuilder sb = new StringBuilder();
sb.append("[");
for (int i = 0; i < a.length; ++i) {
sb.append(String.valueOf(a[i]));
if (i + 1 != a.length) {
sb.append(", ");
}
}
sb.append("]");
return sb.toString();
}
}
public static String toString(byte[] a) {
if (a == null) {
return "null";
@ -34,6 +51,91 @@ public class Arrays {
}
}
public static String toString(short[] a) {
if (a == null) {
return "null";
} else {
StringBuilder sb = new StringBuilder();
sb.append("[");
for (int i = 0; i < a.length; ++i) {
sb.append(String.valueOf(a[i]));
if (i + 1 != a.length) {
sb.append(", ");
}
}
sb.append("]");
return sb.toString();
}
}
public static String toString(int[] a) {
if (a == null) {
return "null";
} else {
StringBuilder sb = new StringBuilder();
sb.append("[");
for (int i = 0; i < a.length; ++i) {
sb.append(String.valueOf(a[i]));
if (i + 1 != a.length) {
sb.append(", ");
}
}
sb.append("]");
return sb.toString();
}
}
public static String toString(long[] a) {
if (a == null) {
return "null";
} else {
StringBuilder sb = new StringBuilder();
sb.append("[");
for (int i = 0; i < a.length; ++i) {
sb.append(String.valueOf(a[i]));
if (i + 1 != a.length) {
sb.append(", ");
}
}
sb.append("]");
return sb.toString();
}
}
public static String toString(float[] a) {
if (a == null) {
return "null";
} else {
StringBuilder sb = new StringBuilder();
sb.append("[");
for (int i = 0; i < a.length; ++i) {
sb.append(String.valueOf(a[i]));
if (i + 1 != a.length) {
sb.append(", ");
}
}
sb.append("]");
return sb.toString();
}
}
public static String toString(double[] a) {
if (a == null) {
return "null";
} else {
StringBuilder sb = new StringBuilder();
sb.append("[");
for (int i = 0; i < a.length; ++i) {
sb.append(String.valueOf(a[i]));
if (i + 1 != a.length) {
sb.append(", ");
}
}
sb.append("]");
return sb.toString();
}
}
private static boolean equal(Object a, Object b) {
return (a == null && b == null) || (a != null && a.equals(b));
}