obj
is
* not null
; otherwise returns an empty String.
* Differs from {@link #nullSafeToString(Object)} in that it returns
* an empty String rather than "null" for a null
value.
* @param obj the object to build a display String for
* @return a display String representation of obj
* @see #nullSafeToString(Object)
*/
public static String getDisplayString(Object obj) {
if (obj == null) {
return EMPTY_STRING;
}
return nullSafeToString(obj);
}
/**
* Determine the class name for the given object.
*
Returns "null"
if obj
is null
.
* @param obj the object to introspect (may be null
)
* @return the corresponding class name
*/
public static String 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 "null"
if obj
is null
.
* @param obj the object to build a String representation for
* @return a String representation of obj
*/
public static String nullSafeToString(Object obj) {
if (obj == null) {
return NULL_STRING;
}
if (obj instanceof String) {
return (String) obj;
}
if (obj instanceof Object[]) {
return nullSafeToString((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 ("{}"
). Adjacent elements are separated
* by the characters ", "
(a comma followed by a space). Returns
* "null"
if array
is null
.
* @param array the array to build a String representation for
* @return a String representation of array
*/
public static String nullSafeToString(Object[] array) {
if (array == null) {
return NULL_STRING;
}
int length = array.length;
if (length == 0) {
return EMPTY_ARRAY;
}
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < length; i++) {
if (i == 0) {
buffer.append(ARRAY_START);
}
else {
buffer.append(ARRAY_ELEMENT_SEPARATOR);
}
buffer.append(String.valueOf(array[i]));
}
buffer.append(ARRAY_END);
return buffer.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 ("{}"
). Adjacent elements are separated
* by the characters ", "
(a comma followed by a space). Returns
* "null"
if array
is null
.
* @param array the array to build a String representation for
* @return a String representation of array
*/
public static String nullSafeToString(boolean[] array) {
if (array == null) {
return NULL_STRING;
}
int length = array.length;
if (length == 0) {
return EMPTY_ARRAY;
}
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < length; i++) {
if (i == 0) {
buffer.append(ARRAY_START);
}
else {
buffer.append(ARRAY_ELEMENT_SEPARATOR);
}
buffer.append(array[i]);
}
buffer.append(ARRAY_END);
return buffer.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 ("{}"
). Adjacent elements are separated
* by the characters ", "
(a comma followed by a space). Returns
* "null"
if array
is null
.
* @param array the array to build a String representation for
* @return a String representation of array
*/
public static String nullSafeToString(byte[] array) {
if (array == null) {
return NULL_STRING;
}
int length = array.length;
if (length == 0) {
return EMPTY_ARRAY;
}
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < length; i++) {
if (i == 0) {
buffer.append(ARRAY_START);
}
else {
buffer.append(ARRAY_ELEMENT_SEPARATOR);
}
buffer.append(array[i]);
}
buffer.append(ARRAY_END);
return buffer.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 ("{}"
). Adjacent elements are separated
* by the characters ", "
(a comma followed by a space). Returns
* "null"
if array
is null
.
* @param array the array to build a String representation for
* @return a String representation of array
*/
public static String nullSafeToString(char[] array) {
if (array == null) {
return NULL_STRING;
}
int length = array.length;
if (length == 0) {
return EMPTY_ARRAY;
}
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < length; i++) {
if (i == 0) {
buffer.append(ARRAY_START);
}
else {
buffer.append(ARRAY_ELEMENT_SEPARATOR);
}
buffer.append("'").append(array[i]).append("'");
}
buffer.append(ARRAY_END);
return buffer.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 ("{}"
). Adjacent elements are separated
* by the characters ", "
(a comma followed by a space). Returns
* "null"
if array
is null
.
* @param array the array to build a String representation for
* @return a String representation of array
*/
public static String nullSafeToString(double[] array) {
if (array == null) {
return NULL_STRING;
}
int length = array.length;
if (length == 0) {
return EMPTY_ARRAY;
}
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < length; i++) {
if (i == 0) {
buffer.append(ARRAY_START);
}
else {
buffer.append(ARRAY_ELEMENT_SEPARATOR);
}
buffer.append(array[i]);
}
buffer.append(ARRAY_END);
return buffer.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 ("{}"
). Adjacent elements are separated
* by the characters ", "
(a comma followed by a space). Returns
* "null"
if array
is null
.
* @param array the array to build a String representation for
* @return a String representation of array
*/
public static String nullSafeToString(float[] array) {
if (array == null) {
return NULL_STRING;
}
int length = array.length;
if (length == 0) {
return EMPTY_ARRAY;
}
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < length; i++) {
if (i == 0) {
buffer.append(ARRAY_START);
}
else {
buffer.append(ARRAY_ELEMENT_SEPARATOR);
}
buffer.append(array[i]);
}
buffer.append(ARRAY_END);
return buffer.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 ("{}"
). Adjacent elements are separated
* by the characters ", "
(a comma followed by a space). Returns
* "null"
if array
is null
.
* @param array the array to build a String representation for
* @return a String representation of array
*/
public static String nullSafeToString(int[] array) {
if (array == null) {
return NULL_STRING;
}
int length = array.length;
if (length == 0) {
return EMPTY_ARRAY;
}
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < length; i++) {
if (i == 0) {
buffer.append(ARRAY_START);
}
else {
buffer.append(ARRAY_ELEMENT_SEPARATOR);
}
buffer.append(array[i]);
}
buffer.append(ARRAY_END);
return buffer.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 ("{}"
). Adjacent elements are separated
* by the characters ", "
(a comma followed by a space). Returns
* "null"
if array
is null
.
* @param array the array to build a String representation for
* @return a String representation of array
*/
public static String nullSafeToString(long[] array) {
if (array == null) {
return NULL_STRING;
}
int length = array.length;
if (length == 0) {
return EMPTY_ARRAY;
}
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < length; i++) {
if (i == 0) {
buffer.append(ARRAY_START);
}
else {
buffer.append(ARRAY_ELEMENT_SEPARATOR);
}
buffer.append(array[i]);
}
buffer.append(ARRAY_END);
return buffer.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 ("{}"
). Adjacent elements are separated
* by the characters ", "
(a comma followed by a space). Returns
* "null"
if array
is null
.
* @param array the array to build a String representation for
* @return a String representation of array
*/
public static String nullSafeToString(short[] array) {
if (array == null) {
return NULL_STRING;
}
int length = array.length;
if (length == 0) {
return EMPTY_ARRAY;
}
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < length; i++) {
if (i == 0) {
buffer.append(ARRAY_START);
}
else {
buffer.append(ARRAY_ELEMENT_SEPARATOR);
}
buffer.append(array[i]);
}
buffer.append(ARRAY_END);
return buffer.toString();
}
}