public final class ObjectTransformer extends Object
Modifier and Type | Class and Description |
---|---|
static class |
ObjectTransformer.InputStreamReaderRunnable
Helper class that extends
Runnable to read data from an input stream in a separate thread |
Modifier and Type | Field and Description |
---|---|
protected static org.apache.log4j.Logger |
logger
the logger
|
Modifier and Type | Method and Description |
---|---|
static int |
compareObjects(Comparable first,
Comparable second,
boolean nullfirst)
Compare objects, care also for null objects
|
static byte[] |
decodeBinary(String encoded)
Decode the encoded binary data (hexcode, leading zeros, all uppercase
letters)
|
static String |
encodeBinary(byte[] binaryData)
Encode the given binary data into hexcode (leading zeros, all uppercase
letters)
|
static boolean |
equals(Object o1,
Object o2)
Compare objects using Object.equals, but also process null references
|
static byte[] |
getBinary(Object o,
byte[] defaultValue)
Get the object as binary value (byte array)
|
static boolean |
getBoolean(Object o,
boolean defaultValue)
Get the boolean value of the given object.
true, 1, yes and on will be interpreted as TRUE. false, 0, no and off will be interpreted as FALSE. Everything else cannot be interpreted as boolean and will return the defaultValue. |
static Boolean |
getBoolean(Object o,
Boolean defaultValue)
Get the Boolean value of the given object.
true, 1, yes and on will be interpreted as TRUE. false, 0, no and off will be interpreted as FALSE. Everything else cannot be interpreted as boolean and will return the defaultValue. |
static Collection |
getCollection(Object o,
Collection defaultValue)
Get the given object as a collection.
|
static Date |
getDate(Object o,
Date defaultValue)
Get the Date representation of the given object
|
static double |
getDouble(Object o,
double defaultValue)
Get a double value of the given object
|
static Double |
getDouble(Object o,
Double defaultValue)
Get the Double representation of the object
|
static int |
getInt(Object o,
int defaultValue)
Get an integer representation of the given object
|
static Integer |
getInteger(Object o,
Integer defaultValue)
Get the Integer representation of the given object
|
static long |
getLong(Object o,
long defaultValue)
Get a long representation of the given object
|
static Long |
getLong(Object o,
Long defaultValue)
Get a Long representation of the given object
|
static long |
getLongTimestamp(Object object,
long defaultValue)
Get the timestamp in milliseconds of the object (if it is a Date) or the
defaultValue for non-Date objects
|
static Number |
getNumber(Object object,
Number defaultValue)
Get the number represented by the given object
|
static String |
getString(Object o,
String defaultValue)
Transform the given object into a string (its string representation)
|
static String[] |
getStringArray(Object o,
String[] defaultValue)
Transform the given object into a string array
|
static int |
getTimestamp(Object object,
int defaultValue)
Get the timestamp value of the object (if it is a Date) or the
defaultValue for non-Date objects
|
static String |
getToken(Object o,
String defaultValue)
Transform the given object into a token.
|
static boolean |
isEmpty(Object value)
Check whether the given value somehow is empty.
|
static String |
readInputStreamIntoString(InputStream inputStream)
Read data coming from the given input stream, using the default charset.
|
static String |
readInputStreamIntoString(InputStream inputStream,
String charset)
Read data coming from the given input stream, using the given charset.
|
static Object |
transformObject(Object baseObject,
Class targetClass)
Tries to transforms a given object to the specified class.
|
public static Collection getCollection(Object o, Collection defaultValue)
o
- object to get as collectiondefaultValue
- default valuepublic static int getInt(Object o, int defaultValue)
o
- object to transformdefaultValue
- default value (when the object does not have an
integer representation)public static Integer getInteger(Object o, Integer defaultValue)
o
- object to transformdefaultValue
- default value (when the object does not have an
Integer representation)public static long getLong(Object o, long defaultValue)
o
- object to transformdefaultValue
- default value (when the object does not have a long
representation)public static Long getLong(Object o, Long defaultValue)
o
- object to transformdefaultValue
- default value (when the object does not have a Long
representation)public static double getDouble(Object o, double defaultValue)
o
- object to transformdefaultValue
- default value (when the object does not have a double
representation)public static Double getDouble(Object o, Double defaultValue)
o
- object to transformdefaultValue
- default valuepublic static boolean getBoolean(Object o, boolean defaultValue)
o
- object to transformdefaultValue
- default value (when the object cannot be interpreted
as boolean)public static Boolean getBoolean(Object o, Boolean defaultValue)
o
- object to transformdefaultValue
- default value (when the object cannot be interpreted
as boolean)public static byte[] getBinary(Object o, byte[] defaultValue)
o
- object to transformdefaultValue
- default valuepublic static String getString(Object o, String defaultValue)
o
- object to transformdefaultValue
- default value (when the object is null)public static String[] getStringArray(Object o, String[] defaultValue)
o
- object to transformdefaultValue
- default value, when the object cannot be interpreted as string arraypublic static Date getDate(Object o, Date defaultValue)
o
- object to transformdefaultValue
- default valuepublic static String getToken(Object o, String defaultValue)
o
- object to transformdefaultValue
- default value (when the object is null)public static boolean isEmpty(Object value)
value
- value to check for emptynesspublic static String encodeBinary(byte[] binaryData)
binaryData
- binary data to encodepublic static byte[] decodeBinary(String encoded)
encoded
- encoded binary dataIllegalArgumentException
- if the encoded data cannot be decodedpublic static int getTimestamp(Object object, int defaultValue)
object
- Date objectdefaultValue
- default valuepublic static long getLongTimestamp(Object object, long defaultValue)
object
- Date objectdefaultValue
- default valuepublic static Number getNumber(Object object, Number defaultValue)
object
- object to transform into a numberdefaultValue
- defaultvalue when object is null, or does not represent a numberpublic static Object transformObject(Object baseObject, Class targetClass)
baseObject
- The base object which to transformtargetClass
- The target class to which the baseObect shall be transformed.public static String readInputStreamIntoString(InputStream inputStream) throws IOException
inputStream
- input stream containing dataIOException
- when reading failspublic static String readInputStreamIntoString(InputStream inputStream, String charset) throws IOException
inputStream
- input stream containing datacharset
- charset to be usedIOException
- when reading failspublic static int compareObjects(Comparable first, Comparable second, boolean nullfirst)
first
- first objectsecond
- second objectnullfirst
- true when nulls shall be smaller than nonnulls, false if
nulls are biggerCopyright © 2017 Gentics Software. All Rights Reserved.