//---------------------------------------------------------------------//Convenience methods for toString output//---------------------------------------------------------------------
/*** Return a String representation of an object's overall identity.
*@paramobj the object (may be {@codenull})
*@returnthe object's identity as String representation,
* or an empty String if the object was {@codenull}*/
public staticString identityToString(Object obj) {if (obj == null) {returnEMPTY_STRING;
}return obj.getClass().getName() + "@" +getIdentityHexString(obj);
}/*** Return a hex String form of an object's identity hash code.
*@paramobj the object
*@returnthe object's identity code in hex notation*/
public staticString getIdentityHexString(Object obj) {returnInteger.toHexString(System.identityHashCode(obj));
}/*** Return a content-based String representation if {@codeobj} is
* not {@codenull}; otherwise returns an empty String.
*
Differs from {@link#nullSafeToString(Object)} in that it returns
* an empty String rather than "null" for a {@codenull} value.
*@paramobj the object to build a display String for
*@returna display String representation of {@codeobj}
*@see#nullSafeToString(Object)*/
public staticString getDisplayString(Object obj) {if (obj == null) {returnEMPTY_STRING;
}returnnullSafeToString(obj);
}/*** Determine the class name for the given object.
*
Returns {@code"null"} if {@codeobj} is {@codenull}.
*@paramobj the object to introspect (may be {@codenull})
*@returnthe corresponding class name*/
public staticString nullSafeClassName(Object obj) {return (obj != null ?obj.getClass().getName() : NULL_STRING);
}/*** Return a String representation of the specified Object.
*
Builds a String representation of the contents in case of an array.
* Returns {@code"null"} if {@codeobj} is {@codenull}.
*@paramobj the object to build a String representation for
*@returna String representation of {@codeobj}*/
public staticString nullSafeToString(Object obj) {if (obj == null) {returnNULL_STRING;
}if (obj instanceofString) {return(String) obj;
}if (obj instanceofObject[]) {returnnullSafeToString((Object[]) obj);
}if (obj instanceof boolean[]) {return nullSafeToString((boolean[]) obj);
}if (obj instanceof byte[]) {return nullSafeToString((byte[]) obj);
}if (obj instanceof char[]) {return nullSafeToString((char[]) obj);
}if (obj instanceof double[]) {return nullSafeToString((double[]) obj);
}if (obj instanceof float[]) {return nullSafeToString((float[]) obj);
}if (obj instanceof int[]) {return nullSafeToString((int[]) obj);
}if (obj instanceof long[]) {return nullSafeToString((long[]) obj);
}if (obj instanceof short[]) {return nullSafeToString((short[]) obj);
}
String str=obj.toString();return (str != null ?str : EMPTY_STRING);
}/*** Return a String representation of the contents of the specified array.
*
The String representation consists of a list of the array's elements,
* enclosed in curly braces ({@code"{}"}). Adjacent elements are separated
* by the characters {@code", "} (a comma followed by a space). Returns
* {@code"null"} if {@codearray} is {@codenull}.
*@paramarray the array to build a String representation for
*@returna String representation of {@codearray}*/
public staticString nullSafeToString(Object[] array) {if (array == null) {returnNULL_STRING;
}int length =array.length;if (length == 0) {returnEMPTY_ARRAY;
}
StringBuilder sb= newStringBuilder();for (int i = 0; i < length; i++) {if (i == 0) {
sb.append(ARRAY_START);
}else{
sb.append(ARRAY_ELEMENT_SEPARATOR);
}
sb.append(String.valueOf(array[i]));
}
sb.append(ARRAY_END);returnsb.toString();
}/*** Return a String representation of the contents of the specified array.
*
The String representation consists of a list of the array's elements,
* enclosed in curly braces ({@code"{}"}). Adjacent elements are separated
* by the characters {@code", "} (a comma followed by a space). Returns
* {@code"null"} if {@codearray} is {@codenull}.
*@paramarray the array to build a String representation for
*@returna String representation of {@codearray}*/
public static String nullSafeToString(boolean[] array) {if (array == null) {returnNULL_STRING;
}int length =array.length;if (length == 0) {returnEMPTY_ARRAY;
}
StringBuilder sb= newStringBuilder();for (int i = 0; i < length; i++) {if (i == 0) {
sb.append(ARRAY_START);
}else{
sb.append(ARRAY_ELEMENT_SEPARATOR);
}
sb.append(array[i]);
}
sb.append(ARRAY_END);returnsb.toString();
}/*** Return a String representation of the contents of the specified array.
*
The String representation consists of a list of the array's elements,
* enclosed in curly braces ({@code"{}"}). Adjacent elements are separated
* by the characters {@code", "} (a comma followed by a space). Returns
* {@code"null"} if {@codearray} is {@codenull}.
*@paramarray the array to build a String representation for
*@returna String representation of {@codearray}*/
public static String nullSafeToString(byte[] array) {if (array == null) {returnNULL_STRING;
}int length =array.length;if (length == 0) {returnEMPTY_ARRAY;
}
StringBuilder sb= newStringBuilder();for (int i = 0; i < length; i++) {if (i == 0) {
sb.append(ARRAY_START);
}else{
sb.append(ARRAY_ELEMENT_SEPARATOR);
}
sb.append(array[i]);
}
sb.append(ARRAY_END);returnsb.toString();
}/*** Return a String representation of the contents of the specified array.
*
The String representation consists of a list of the array's elements,
* enclosed in curly braces ({@code"{}"}). Adjacent elements are separated
* by the characters {@code", "} (a comma followed by a space). Returns
* {@code"null"} if {@codearray} is {@codenull}.
*@paramarray the array to build a String representation for
*@returna String representation of {@codearray}*/
public static String nullSafeToString(char[] array) {if (array == null) {returnNULL_STRING;
}int length =array.length;if (length == 0) {returnEMPTY_ARRAY;
}
StringBuilder sb= newStringBuilder();for (int i = 0; i < length; i++) {if (i == 0) {
sb.append(ARRAY_START);
}else{
sb.append(ARRAY_ELEMENT_SEPARATOR);
}
sb.append("'").append(array[i]).append("'");
}
sb.append(ARRAY_END);returnsb.toString();
}/*** Return a String representation of the contents of the specified array.
*
The String representation consists of a list of the array's elements,
* enclosed in curly braces ({@code"{}"}). Adjacent elements are separated
* by the characters {@code", "} (a comma followed by a space). Returns
* {@code"null"} if {@codearray} is {@codenull}.
*@paramarray the array to build a String representation for
*@returna String representation of {@codearray}*/
public static String nullSafeToString(double[] array) {if (array == null) {returnNULL_STRING;
}int length =array.length;if (length == 0) {returnEMPTY_ARRAY;
}
StringBuilder sb= newStringBuilder();for (int i = 0; i < length; i++) {if (i == 0) {
sb.append(ARRAY_START);
}else{
sb.append(ARRAY_ELEMENT_SEPARATOR);
}
sb.append(array[i]);
}
sb.append(ARRAY_END);returnsb.toString();
}/*** Return a String representation of the contents of the specified array.
*
The String representation consists of a list of the array's elements,
* enclosed in curly braces ({@code"{}"}). Adjacent elements are separated
* by the characters {@code", "} (a comma followed by a space). Returns
* {@code"null"} if {@codearray} is {@codenull}.
*@paramarray the array to build a String representation for
*@returna String representation of {@codearray}*/
public static String nullSafeToString(float[] array) {if (array == null) {returnNULL_STRING;
}int length =array.length;if (length == 0) {returnEMPTY_ARRAY;
}
StringBuilder sb= newStringBuilder();for (int i = 0; i < length; i++) {if (i == 0) {
sb.append(ARRAY_START);
}else{
sb.append(ARRAY_ELEMENT_SEPARATOR);
}
sb.append(array[i]);
}
sb.append(ARRAY_END);returnsb.toString();
}/*** Return a String representation of the contents of the specified array.
*
The String representation consists of a list of the array's elements,
* enclosed in curly braces ({@code"{}"}). Adjacent elements are separated
* by the characters {@code", "} (a comma followed by a space). Returns
* {@code"null"} if {@codearray} is {@codenull}.
*@paramarray the array to build a String representation for
*@returna String representation of {@codearray}*/
public static String nullSafeToString(int[] array) {if (array == null) {returnNULL_STRING;
}int length =array.length;if (length == 0) {returnEMPTY_ARRAY;
}
StringBuilder sb= newStringBuilder();for (int i = 0; i < length; i++) {if (i == 0) {
sb.append(ARRAY_START);
}else{
sb.append(ARRAY_ELEMENT_SEPARATOR);
}
sb.append(array[i]);
}
sb.append(ARRAY_END);returnsb.toString();
}/*** Return a String representation of the contents of the specified array.
*
The String representation consists of a list of the array's elements,
* enclosed in curly braces ({@code"{}"}). Adjacent elements are separated
* by the characters {@code", "} (a comma followed by a space). Returns
* {@code"null"} if {@codearray} is {@codenull}.
*@paramarray the array to build a String representation for
*@returna String representation of {@codearray}*/
public static String nullSafeToString(long[] array) {if (array == null) {returnNULL_STRING;
}int length =array.length;if (length == 0) {returnEMPTY_ARRAY;
}
StringBuilder sb= newStringBuilder();for (int i = 0; i < length; i++) {if (i == 0) {
sb.append(ARRAY_START);
}else{
sb.append(ARRAY_ELEMENT_SEPARATOR);
}
sb.append(array[i]);
}
sb.append(ARRAY_END);returnsb.toString();
}/*** Return a String representation of the contents of the specified array.
*
The String representation consists of a list of the array's elements,
* enclosed in curly braces ({@code"{}"}). Adjacent elements are separated
* by the characters {@code", "} (a comma followed by a space). Returns
* {@code"null"} if {@codearray} is {@codenull}.
*@paramarray the array to build a String representation for
*@returna String representation of {@codearray}*/
public static String nullSafeToString(short[] array) {if (array == null) {returnNULL_STRING;
}int length =array.length;if (length == 0) {returnEMPTY_ARRAY;
}
StringBuilder sb= newStringBuilder();for (int i = 0; i < length; i++) {if (i == 0) {
sb.append(ARRAY_START);
}else{
sb.append(ARRAY_ELEMENT_SEPARATOR);
}
sb.append(array[i]);
}
sb.append(ARRAY_END);returnsb.toString();
}