Class GosuObjectUtil
- java.lang.Object
-
- gw.util.GosuObjectUtil
-
public class GosuObjectUtil extends java.lang.ObjectThis class is directly derived from org.apache.commons.lang.ObjectUtils and is intended to avoid dependencies on that project.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGosuObjectUtil.NullClass used as a null placeholder wherenullhas another meaning.
-
Field Summary
Fields Modifier and Type Field Description static GosuObjectUtil.NullNULLSingleton used as anullplaceholder wherenullhas another meaning.
-
Constructor Summary
Constructors Constructor Description GosuObjectUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.lang.StringBufferappendIdentityToString(java.lang.StringBuffer buffer, java.lang.Object object)Deprecated.The design of this method is bad - see LANG-360.static intarrayHashCode(java.lang.Object array)Return the hash code for an arraystatic java.lang.ObjectdefaultIfNull(java.lang.Object object, java.lang.Object defaultValue)Returns a default value if the object passed isnull.static booleanequals(java.lang.Object object1, java.lang.Object object2)Compares two objects for equality, where either one or both objects may benull.static inthashCode(java.lang.Object obj)Gets the hash code of an object returning zero when the object isnull.static java.lang.StringidentityToString(java.lang.Object object)Gets the toString that would be produced byObjectif a class did not override toString itself.static voididentityToString(java.lang.StringBuffer buffer, java.lang.Object object)Appends the toString that would be produced byObjectif a class did not override toString itself.static booleanisJavaReferenceArray(java.lang.Object o)static java.lang.Objectmax(java.lang.Comparable c1, java.lang.Comparable c2)Null safe comparison of Comparables.static java.lang.Objectmin(java.lang.Comparable c1, java.lang.Comparable c2)Null safe comparison of Comparables.static java.lang.StringtoString(java.lang.Object obj)Gets thetoStringof anObjectreturning an empty string ("") ifnullinput.static java.lang.StringtoString(java.lang.Object obj, java.lang.String nullStr)Gets thetoStringof anObjectreturning a specified text ifnullinput.
-
-
-
Field Detail
-
NULL
public static final GosuObjectUtil.Null NULL
Singleton used as a
nullplaceholder wherenullhas another meaning.For example, in a
HashMaptheHashMap.get(java.lang.Object)method returnsnullif theMapcontainsnullor if there is no matching key. TheNullplaceholder can be used to distinguish between these two cases.Another example is
Hashtable, wherenullcannot be stored.This instance is Serializable.
-
-
Method Detail
-
defaultIfNull
public static java.lang.Object defaultIfNull(java.lang.Object object, java.lang.Object defaultValue)Returns a default value if the object passed is
null.ObjectUtils.defaultIfNull(null, null) = null ObjectUtils.defaultIfNull(null, "") = "" ObjectUtils.defaultIfNull(null, "zz") = "zz" ObjectUtils.defaultIfNull("abc", *) = "abc" ObjectUtils.defaultIfNull(Boolean.TRUE, *) = Boolean.TRUE- Parameters:
object- theObjectto test, may benulldefaultValue- the default value to return, may benull- Returns:
objectif it is notnull, defaultValue otherwise
-
equals
public static boolean equals(java.lang.Object object1, java.lang.Object object2)Compares two objects for equality, where either one or both objects may be
null.ObjectUtils.equals(null, null) = true ObjectUtils.equals(null, "") = false ObjectUtils.equals("", null) = false ObjectUtils.equals("", "") = true ObjectUtils.equals(Boolean.TRUE, null) = false ObjectUtils.equals(Boolean.TRUE, "true") = false ObjectUtils.equals(Boolean.TRUE, Boolean.TRUE) = true ObjectUtils.equals(Boolean.TRUE, Boolean.FALSE) = false- Parameters:
object1- the first object, may benullobject2- the second object, may benull- Returns:
trueif the values of both objects are the same
-
hashCode
public static int hashCode(java.lang.Object obj)
Gets the hash code of an object returning zero when the object is
null.ObjectUtils.hashCode(null) = 0 ObjectUtils.hashCode(obj) = obj.hashCode()
- Parameters:
obj- the object to obtain the hash code of, may benull- Returns:
- the hash code of the object, or zero if null
- Since:
- 2.1
-
identityToString
public static java.lang.String identityToString(java.lang.Object object)
Gets the toString that would be produced by
Objectif a class did not override toString itself.nullwill returnnull.ObjectUtils.identityToString(null) = null ObjectUtils.identityToString("") = "java.lang.String@1e23" ObjectUtils.identityToString(Boolean.TRUE) = "java.lang.Boolean@7fa"- Parameters:
object- the object to create a toString for, may benull- Returns:
- the default toString text, or
nullifnullpassed in
-
isJavaReferenceArray
public static boolean isJavaReferenceArray(java.lang.Object o)
- Returns:
- true if the given object is a pure java object array, false otherwise
-
identityToString
public static void identityToString(java.lang.StringBuffer buffer, java.lang.Object object)Appends the toString that would be produced by
Objectif a class did not override toString itself.nullwill throw a NullPointerException for either of the two parameters.ObjectUtils.identityToString(buf, "") = buf.append("java.lang.String@1e23" ObjectUtils.identityToString(buf, Boolean.TRUE) = buf.append("java.lang.Boolean@7fa" ObjectUtils.identityToString(buf, Boolean.TRUE) = buf.append("java.lang.Boolean@7fa")- Parameters:
buffer- the buffer to append toobject- the object to create a toString for- Since:
- 2.4
-
appendIdentityToString
public static java.lang.StringBuffer appendIdentityToString(java.lang.StringBuffer buffer, java.lang.Object object)Deprecated.The design of this method is bad - see LANG-360. Instead, use identityToString(StringBuffer, Object).Appends the toString that would be produced by
Objectif a class did not override toString itself.nullwill returnnull.ObjectUtils.appendIdentityToString(*, null) = null ObjectUtils.appendIdentityToString(null, "") = "java.lang.String@1e23" ObjectUtils.appendIdentityToString(null, Boolean.TRUE) = "java.lang.Boolean@7fa" ObjectUtils.appendIdentityToString(buf, Boolean.TRUE) = buf.append("java.lang.Boolean@7fa")- Parameters:
buffer- the buffer to append to, may benullobject- the object to create a toString for, may benull- Returns:
- the default toString text, or
nullifnullpassed in - Since:
- 2.0
-
toString
public static java.lang.String toString(java.lang.Object obj)
Gets the
toStringof anObjectreturning an empty string ("") ifnullinput.ObjectUtils.toString(null) = "" ObjectUtils.toString("") = "" ObjectUtils.toString("bat") = "bat" ObjectUtils.toString(Boolean.TRUE) = "true"- Parameters:
obj- the Object totoString, may be null- Returns:
- the passed in Object's toString, or nullStr if
nullinput - Since:
- 2.0
- See Also:
String.valueOf(Object)
-
toString
public static java.lang.String toString(java.lang.Object obj, java.lang.String nullStr)Gets the
toStringof anObjectreturning a specified text ifnullinput.ObjectUtils.toString(null, null) = null ObjectUtils.toString(null, "null") = "null" ObjectUtils.toString("", "null") = "" ObjectUtils.toString("bat", "null") = "bat" ObjectUtils.toString(Boolean.TRUE, "null") = "true"- Parameters:
obj- the Object totoString, may be nullnullStr- the String to return ifnullinput, may be null- Returns:
- the passed in Object's toString, or nullStr if
nullinput - Since:
- 2.0
- See Also:
String.valueOf(Object)
-
min
public static java.lang.Object min(java.lang.Comparable c1, java.lang.Comparable c2)Null safe comparison of Comparables.- Parameters:
c1- the first comparable, may be nullc2- the second comparable, may be null- Returns:
- If both objects are non-null and unequal, the lesser object.
- If both objects are non-null and equal, c1.
- If one of the comparables is null, the non-null object.
- If both the comparables are null, null is returned.
-
max
public static java.lang.Object max(java.lang.Comparable c1, java.lang.Comparable c2)Null safe comparison of Comparables.- Parameters:
c1- the first comparable, may be nullc2- the second comparable, may be null- Returns:
- If both objects are non-null and unequal, the greater object.
- If both objects are non-null and equal, c1.
- If one of the comparables is null, the non-null object.
- If both the comparables are null, null is returned.
-
arrayHashCode
public static int arrayHashCode(java.lang.Object array)
Return the hash code for an array- Parameters:
array- the array to compute the hash code.
-
-