public class ObjectUtils extends Object
| Constructor and Description |
|---|
ObjectUtils() |
| Modifier and Type | Method and Description |
|---|---|
static Object |
byteArrayToObject(byte[] data)
De-serialize an object from byte array.
|
static Object |
clone(Object source)
Clone an object by invoking it's
clone() method, even if it
is not overridden. |
static Object |
cloneViaSerialization(Serializable obj)
Create object copy using serialization mechanism.
|
static boolean |
containsElement(Object obj,
Object element)
Returns true if first argument contains provided element.
|
static boolean |
equals(Object obj1,
Object obj2)
Safely compares two objects just like
equals() would, except
it allows any of the 2 objects to be null. |
static boolean |
equalsEx(Object obj1,
Object obj2)
Compares two objects or two object arrays.
|
static boolean |
equalsType(Object object,
Object thiz)
Non-symmetric utility for comparing the types of two objects.
|
static boolean |
isInstanceOf(Object object,
Class<?> klass)
Checks if an Object is an instance of the given class.
|
static boolean |
isNotInstanceOf(Object object,
Class<?> klass)
Checks if an Object is not an instance of the given class.
|
static boolean |
isNotNull(Object object)
Checks if an Object is not null.
|
static boolean |
isNull(Object object)
Checks if an Object is null.
|
static int |
length(Object obj)
Returns length of the object.
|
static byte[] |
objectToByteArray(Object obj)
Serialize an object to byte array.
|
static Object |
readObject(File source)
Reads serialized object from the file.
|
static Object |
readObject(String source)
Read object.
|
static Object |
readObjectAsXml(File source)
Reads serialized object from the XML file.
|
static Object |
readObjectAsXml(String source)
Read object as xml.
|
static void |
writeObject(File dest,
Object object)
Writes serializable object to a file.
|
static void |
writeObject(String dest,
Object object)
Write object.
|
static void |
writeObjectAsXml(File dest,
Object object)
Writes serializable object to a XML file.
|
static void |
writeObjectAsXml(String dest,
Object object)
Write object as xml.
|
public static boolean equals(Object obj1, Object obj2)
equals() would, except
it allows any of the 2 objects to be null.obj1 - the obj1obj2 - the obj2true if arguments are equal, otherwise
falsepublic static boolean equalsEx(Object obj1, Object obj2)
Object.equals(Object).obj1 - the obj1obj2 - the obj2equals(Object, Object)public static boolean equalsType(Object object, Object thiz)
Object.equals(Object) if instanceOf is
not used.object - equals() argumentthiz - current class that overrides equals()public static Object clone(Object source) throws CloneNotSupportedException
clone() method, even if it
is not overridden.source - the sourceCloneNotSupportedException - the clone not supported exceptionpublic static Object cloneViaSerialization(Serializable obj) throws IOException, ClassNotFoundException
obj - the objIOException - Signals that an I/O exception has occurred.ClassNotFoundException - the class not found exceptionpublic static void writeObject(String dest, Object object) throws IOException
dest - the destobject - the objectIOException - Signals that an I/O exception has occurred.writeObject(java.io.File, Object)public static void writeObject(File dest, Object object) throws IOException
dest - the destobject - the objectIOException - Signals that an I/O exception has occurred.public static void writeObjectAsXml(File dest, Object object) throws IOException
dest - the destobject - the objectIOException - Signals that an I/O exception has occurred.public static void writeObjectAsXml(String dest, Object object) throws IOException
dest - the destobject - the objectIOException - Signals that an I/O exception has occurred.writeObjectAsXml(java.io.File, Object)public static Object readObject(String source) throws IOException, ClassNotFoundException
source - the sourceIOException - Signals that an I/O exception has occurred.ClassNotFoundException - the class not found exceptionreadObject(java.io.File)public static Object readObject(File source) throws IOException, ClassNotFoundException
source - the sourceIOException - Signals that an I/O exception has occurred.ClassNotFoundException - the class not found exceptionpublic static Object readObjectAsXml(File source) throws IOException
source - the sourceIOException - Signals that an I/O exception has occurred.public static Object readObjectAsXml(String source) throws IOException
source - the sourceIOException - Signals that an I/O exception has occurred.readObjectAsXml(java.io.File)public static byte[] objectToByteArray(Object obj) throws IOException
obj - the objIOException - Signals that an I/O exception has occurred.public static Object byteArrayToObject(byte[] data) throws IOException, ClassNotFoundException
data - the dataIOException - Signals that an I/O exception has occurred.ClassNotFoundException - the class not found exceptionpublic static int length(Object obj)
obj - the objpublic static boolean containsElement(Object obj, Object element)
obj - the objelement - the elementpublic static boolean isNull(Object object)
Checks if an Object is null.
ObjectUtils.isNull(null) = true
object - the Object to check, may be nulltrue if the object is nullpublic static boolean isNotNull(Object object)
Checks if an Object is not null.
ObjectUtils.isNotNull(null) = false
object - the Object to check, may be nulltrue if the object is not null.public static boolean isInstanceOf(Object object, Class<?> klass)
Checks if an Object is an instance of the given class.
ObjectUtils.isInstanceOf(object, class) = false
object - the Object to check, may be instance of classklass - the classtrue if the object is an instance of the given
class.public static boolean isNotInstanceOf(Object object, Class<?> klass)
Checks if an Object is not an instance of the given class.
ObjectUtils.isNotInstanceOf(object, class) = false
object - the Object to check, may be not an instance of classklass - the classtrue if the object is an instance of the given
class.Copyright © 2016 utils4j. All Rights Reserved.