public class ObjectUtil
extends java.lang.Object
Constructor and Description |
---|
ObjectUtil() |
Modifier and Type | Method and Description |
---|---|
static <T extends CloneableSerializable> |
cloneSafe(T object)
Calls the Clone method on the given object of some type that extends
CloneableSerializable.
|
static <T> T |
cloneSmart(T object)
Attempts to clone a given object.
|
static <T> T[] |
cloneSmartArrayAndElements(T[] array)
Clones an array and its elements.
|
static <T> java.util.ArrayList<T> |
cloneSmartElementsAsArrayList(java.util.Collection<T> collection)
Creates a new
ArrayList and attempts to copy all of the elements
from the given collection into it by calling the cloneSmart method on
each of them. |
static <T> java.util.LinkedList<T> |
cloneSmartElementsAsLinkedList(java.lang.Iterable<T> collection)
Creates a new
LinkedList and attempts to copy all of the elements
from the given collection into it by calling the cloneSmart method on
each of them. |
static <T extends java.io.Serializable> |
deepCopy(T object)
Performs a deep copy of a given object.
|
static boolean |
equalsSafe(java.lang.Object first,
java.lang.Object second)
Determines if two objects are equals in a way that is safe for dealing
with null.
|
static java.util.LinkedList<java.lang.reflect.Field> |
getAllFields(java.lang.Class<?> c)
Returns a list of all of the fields on the given class and any
super-class.
|
static java.util.ArrayList<DefaultPair<java.lang.reflect.Field,java.lang.Object>> |
getAllFieldValues(java.lang.Object o)
Returns an ArrayList of field/value pairs
|
static byte[] |
getBytes(java.lang.Object o)
Attempts to convert the given Object into a byte array
|
static java.util.ArrayList<java.lang.Object> |
getFieldValues(java.lang.Object o,
java.util.Collection<java.lang.reflect.Field> fields)
Gets the values of the given fields for the object (can get public /
protected / private field values)
|
static java.util.LinkedList<java.lang.reflect.Method> |
getMethods(java.lang.Class<?> c)
Gets the Collection of all public/private/protected Methods in the
given Class (except those only given in the Object class).
|
static java.lang.String |
getShortClassName(java.lang.Class<?> c)
Gets a short version of the Class name, so that
gov.sandia.cognition.util.ObjectUtil$InternalClass will be returned as
"ObjectUtil$InternalClass", for example
|
static java.lang.String |
getShortClassName(java.lang.Object o)
Gets a short version of the Class name, so that
gov.sandia.cognition.util.ObjectUtil$InternalClass will be returned as
"ObjectUtil$InternalClass", for example
|
static int |
hashCodeSafe(java.lang.Object value)
Determines the hash code of the given value by calling the hashCode
method on the given object if it is not null.
|
static java.lang.String |
inspectAPI(java.lang.Class<?> c)
Creates a String representing the Constructors and Methods from the
given Class, inspects public constructors and all
public/private/protected methods (except those from the Object class).
|
static java.lang.String |
inspectFields(java.lang.Class<?> c)
Returns a String representing the values of all public/private/protected
fields in the given Class, e.g., "protected double myField"
|
static java.lang.String |
inspectFieldValues(java.lang.Object o)
Returns a String representing the values of all public/private/protected
fields in the given instantiated Object, e.g., "double myField = 3.14"
|
static java.lang.String |
inspector(java.lang.Object o)
Prints out the Methods and Fields associated with the argument.
|
static java.lang.String |
toString(java.lang.Object o)
Creates a String that contains the names and values of the members, or
the default Object toString if that fails.
|
public static boolean equalsSafe(java.lang.Object first, java.lang.Object second)
first
- The first object.second
- The second object.public static int hashCodeSafe(java.lang.Object value)
value
- The value to get the hash code for. May be null.public static <T extends CloneableSerializable> T cloneSafe(T object)
T
- The type of the object to clone.object
- The object to clone.public static <T> T cloneSmart(T object)
CloneableSerializable
interface. If it does, it calls the
cloneSafe
method with it. If not, it attempts to see if there is
a clone method on the given object, and if so it attempts to call the
method. If this fails, then it just returns the given object.
Note: It assumes that the given object's clone method will return the
same object of type T.T
- The type of the object to clone.object
- The object to clone.public static <T> java.util.ArrayList<T> cloneSmartElementsAsArrayList(java.util.Collection<T> collection)
ArrayList
and attempts to copy all of the elements
from the given collection into it by calling the cloneSmart method on
each of them.T
- The type of the elements in the list.collection
- The collection of elements to clone.ArrayList
with a clone of each element in it.public static <T> java.util.LinkedList<T> cloneSmartElementsAsLinkedList(java.lang.Iterable<T> collection)
LinkedList
and attempts to copy all of the elements
from the given collection into it by calling the cloneSmart method on
each of them.T
- The type of the elements in the list.collection
- The collection of elements to clone.LinkedList
with a clone of each element in it.public static <T> T[] cloneSmartArrayAndElements(T[] array)
T
- The type of object in the array.array
- The array to copy, along with its elements.public static <T extends java.io.Serializable> T deepCopy(T object)
T
- The type of the object to copy.object
- The object to copy.public static java.lang.String inspector(java.lang.Object o)
o
- Object/Class/String to inspect frompublic static java.lang.String inspectAPI(java.lang.Class<?> c)
c
- Class to determine the API ofpublic static java.util.LinkedList<java.lang.reflect.Method> getMethods(java.lang.Class<?> c)
c
- Class from which to pull the Methodspublic static java.lang.String toString(java.lang.Object o)
o
- Object to convert to a Stringpublic static java.lang.String inspectFieldValues(java.lang.Object o)
o
- Instantiated Object to inspectpublic static java.lang.String inspectFields(java.lang.Class<?> c)
c
- Class from which to inspect the fieldspublic static java.util.LinkedList<java.lang.reflect.Field> getAllFields(java.lang.Class<?> c)
c
- The class to get all the fields from.public static java.util.ArrayList<DefaultPair<java.lang.reflect.Field,java.lang.Object>> getAllFieldValues(java.lang.Object o)
o
- Object to get the field/value pairspublic static java.util.ArrayList<java.lang.Object> getFieldValues(java.lang.Object o, java.util.Collection<java.lang.reflect.Field> fields)
o
- Object to get the field values offields
- Fields to get the values ofpublic static java.lang.String getShortClassName(java.lang.Object o)
o
- Object from which to pull the short Class namepublic static java.lang.String getShortClassName(java.lang.Class<?> c)
c
- Object from which to pull the short Class namepublic static byte[] getBytes(java.lang.Object o)
o
- Object to convert