public class DataTools
extends java.lang.Object
DataTools
is a utility class with the following facilities: getProperties()
and setProperties()
: getProperties()
allow the properties of any Java object to be extracted as a Map, and setProperties
allows any Map to be applied to a Java object, calling setter methods named after the keys of the Map. These methods are very useful for going from Java beans to a JavaScript representation and back. Modifier and Type | Method and Description |
---|---|
static java.util.List | addAll(java.util.List target, java.util.Iterator source) Adds all the elements of an Iterator to a List . |
static java.util.List | addAll(java.util.List target, java.util.List source) Adds the contents of one List to another. |
static java.util.List | addAsList(java.util.List targetList, java.lang.Object sourceList) Add either a single object or List to another List. |
static void | addDisjunctionToSet(java.util.List one, java.util.List two) Adds elements of the second List that are missing in the first. |
static void | addToIntInMap(java.util.Map map, java.lang.Object key, int addition) Add to the value of an Integer instance stored in the map "map" under key "key". |
static java.util.List | arrayToList(java.lang.Object[] arr) Creates a List from an array. |
static java.util.List | arrayToList(java.lang.Object[] arr, int from, int length) Creates a List containing a subset of an array. |
static java.lang.Object[] | arrayUnion(java.lang.Object[] one, java.lang.Object[] two) Creates a new array containing all the elements of two arrays. |
static java.lang.String | bcrypt(java.lang.String plaintext) Returns the hash of the passed-in string, encrypted using the bcrypt algorithm |
static java.util.List | buildList(java.lang.Object[] args) Creates a List containing the passed in objects |
static DataTypeMap | buildMap(java.lang.Object[] args) Creates a Map of key/value pairs. |
static java.lang.Object | castValue(java.lang.Object value, java.lang.Class targetType, DataSource ds) Converts specified value to targetType . |
static int | checkSize(java.lang.Object obj) Obtains the size of a Map , List or String . |
static java.lang.Object | combineAsLists(java.lang.Object one, java.lang.Object two) Combine two single objects or Lists into one new List, or return a single Object if one argument is single and the other argument is null. |
static boolean | contains(java.lang.String str, java.lang.String substr) Tests if the specified substring is present in the specified string. |
static java.lang.Object | deepMerge(java.lang.Object source, java.lang.Object target, boolean overwrite) Merges one collections data structure into another. |
static void | deepRemoveEmptyCollections(java.lang.Object data) Walks a nested Collection-based datastructure and removes all Collections entities that are zero-sized. |
static void | deepRemoveKey(java.lang.Object keyToRemove, java.lang.Object data) Walks a nested Collection-based datastructure and removes all instances of keyToRemove (and its associated value) from any Map objects found in the data structure. |
static void | deepRemoveNullValues(java.lang.Object data) Walks a nested Collection-based datastructure and removes all entities that have a null value. |
static java.util.Map | divideMap(java.util.Map origMap, java.util.List retainKeys) Alters a Map so that it retains only the specified keys, returning a Map with any keys not retained. |
static java.util.List | enumToList(java.util.Iterator i) Converts an Iterator to a List . |
static java.lang.String | fastDateFormat(java.util.Date date) Returns a String representation of a Date object. |
static java.util.List | findAll(java.util.List rows, java.util.Map properties) Given a List of Maps, return all Maps that have common key/value pairs with another Map. |
static java.util.List | findAll(java.util.List rows, java.lang.Object propertyName, java.lang.Object value) Given a List of Maps, return all Maps that have a certain value for a key. |
static java.lang.String | formatDate(java.lang.String format, java.util.Date date) Returns the parameter date formatted according to the parameter format string. |
static java.lang.Class | getCachedClass(java.lang.String className) Returns loaded Class object for specified name. |
static java.lang.reflect.Field[] | getClassFields(java.lang.Class c) Returns array of all fields declared in specified class and it's supper classes. |
static java.lang.reflect.Method[] | getClassMethods(java.lang.Class c) Returns array of all methods declared in specified class and it's supper classes. |
static int | getIntInMap(java.util.Map map, java.lang.Object key) Get value of an Integer instance stored in the map "map" under key "key", as the primitive type int . |
static java.lang.Object | getLoggerRepository() Returns log4j LoggerRepository instance that was configured from log4j.isc.config.xml . |
static java.util.Map | getProperties(java.lang.Object bean) Gets the properties for a JavaBean and returns them as a Map . |
static java.util.List | getProperty(java.util.List rows, java.lang.Object column) Given a result set, as a List of rows, and a column name, returns the List of values for that column. |
static java.util.Map | getPropertyDescriptors(java.lang.Class beanClass) Gets the properties for a JavaBean class through introspection and returns them as a Map . Removes properties added by byte-code instrumentation: interceptFieldCallback property is removed if class implements net.sf.cglib.transform.impl.InterceptFieldEnabled interface; fieldHandler property is removed if class implements org.hibernate.bytecode.javassist.FieldHandled interface; |
static java.util.Map | getPropertyDescriptors(java.lang.Object bean) Gets the property descriptors for a JavaBean and returns them as a Map . |
static java.lang.Class | getPropertyType(java.lang.Class c, java.lang.String propertyName) Returns type of specified property in provided class. |
static java.lang.Class | getRealClass(java.lang.Object bean) Checks if provided bean is a proxy and extracts real class. |
static java.lang.Object | getSingle(java.lang.Object toFetchFrom) Retrieves the element of a single element List , or the key of a single key/value pair Map . |
static java.lang.String | getStackTrace(java.lang.Throwable t) Returns the stack trace of a Throwable object as a String . |
static java.lang.String | getStackTrace(java.lang.Throwable t, int lineCount) Returns the stack trace of a Throwable object as a String shortened to requested number of lines. |
static java.lang.String | getterName(java.lang.reflect.Method method) Tests if method is getter and returns property name. |
static java.lang.String | hashValue(java.lang.String plaintext) Returns the hash of the passed-in string, encrypted using the MD5 algorithm |
static java.lang.String | hashValue(java.lang.String plaintext, java.lang.String algorithm) Returns the hash of the passed-in string, encrypted using the specified algorithm |
static java.util.Map | identityMap(java.util.List list) Stores the elements of a List as the keys and values of a Map . |
static void | incrementIntInMap(java.util.Map map, java.lang.Object key) Add to the value of an Integer instance stored in the map "map" under key "key". |
static boolean | isNumberType(java.lang.Class clazz) Returns true if provided class is either assignable to Number or represents one of primitive number types byte, short, int, long, float, double . |
static boolean | isTextType(java.lang.Class clazz) Returns true if provided class is either assignable to Character or assignable to String or represents primitive char type. |
static org.apache.commons.jxpath.JXPathContext | jxPathContext(java.lang.Object obj) Returns JXPathContext in lenient mode |
static java.util.List | keysAsList(java.util.Map map) Creates a List of the keys from a Map . |
static java.util.List | keysNotPresent(java.util.Map map, java.util.List keys) Given a Map and a List of keys, returns the list of keys in the List that are not present in the Map . |
static java.lang.Object[] | listToArray(java.util.List list) Creates an Object array from a List . |
static java.lang.String[] | listToStringArray(java.util.Collection list) Creates a String array from a List . |
static java.util.List | makeList(java.lang.Object element) Creates a List containing one element. |
static java.util.List | makeListIfSingle(java.lang.Object obj) Creates a List containing one element if the element is not a List . |
static java.util.Map | mapDisjunction(java.util.Map one, java.util.Map two) Creates a new Map containing the key/value pairs whose keys are not present in both Maps supplied. |
static java.util.Map | mapIntersection(java.util.Map primary, java.util.Map secondary) Constructs a Map containing the key/value pairs of the primary Map whose keys are present in the secondary Map . |
static java.util.List | mapIntersectionKeys(java.util.Map one, java.util.Map two) Returns the list of keys that are present in both Maps . |
static java.util.Map | mapMerge(java.util.Map source, java.util.Map target) Copies the key/value pairs of a Map into another Map , replacing the key/value pair of the target Map . |
static java.util.Map | mapMergeNonNull(java.util.Map source, java.util.Map target) Copies the key/value pairs of a Map into another Map , replacing the key/value pair of the target Map if the source value is non-null. |
static java.util.Properties | mapToProperties(java.util.Map map) Creates a Properties object from a Map . |
static java.util.Map | mapUnion(java.util.Map primary, java.util.Map secondary) Constructs a Map containing all the key/value pairs of the Maps supplied as arguments, with the first Map taking precedence. |
static java.lang.String | md5(java.lang.String plaintext) Returns the hash of the passed-in string, encrypted using the MD5 algorithm |
static java.lang.Object | nestedGet(java.lang.Object struct, java.lang.String fetch) Retrieves a object from a series of nested Lists or Map . |
static java.util.LinkedHashMap | orderedMapUnion(java.util.Map primary, java.util.Map secondary) Does the same as mapUnion , but keeps order of key/value pairs. |
static java.lang.String | prettyPrint(java.lang.Object obj) Formats information about an Object for viewing or printing as a String . |
static java.util.Map | putAllNotPresent(java.util.Map target, java.util.Map source) Copies the key/value pairs of a Map into another Map , adding only key/value pairs for which the target Map does not already have a mapping (as determined by the containsKey method). |
static java.util.Map | putCombinedList(java.util.Map map, java.lang.Object key, java.lang.Object value) Put a value into a Map, combining with any existing value as though combineAsLists() had been called on the existing value and new value. |
static java.util.Map | putMultiple(java.util.Map map, java.lang.Object key, java.lang.Object value) Puts a key/value pair into a Map , if there is already a value under that key, create a List to hold the values. |
static java.util.Map | putMultipleAsList(java.util.Map map, java.lang.Object key, java.lang.Object value) Works like the putMultiple method, but in this case values are always encapsualted in a List . |
static boolean | recursiveFileDelete(java.io.File file) Recursively deletes a directory. |
static void | registerTransformer(java.lang.Class targetType, DataTools.Transformer transformer) Register a Transformer. |
static java.util.Map | remapRow(java.util.Map row, java.util.Map remap) Change the keys used in a Map to a new set of keys. |
static java.util.Map | remapRow(java.util.Map row, java.util.Map remap, boolean keepNonRemapped) Change the keys used in a Map to a new set of keys. |
static java.util.List | remapRows(java.util.List rows, java.util.Map remap) Remap the keys in a List of Maps . |
static java.util.List | remapRows(java.util.List rows, java.util.Map remap, boolean keepNonRemapped) Remap the keys in a List of Maps . |
static java.util.Map | removeEmptyStringValuedKeys(java.util.Map map) Removes all keys from the passed-in map where the values are empty strings. |
static java.util.Map | removeNullValuedKeys(java.util.Map map) Removes all keys from the passed-in map where the values are null . |
static java.util.Map | reverseMap(java.util.Map origMap) Reverses a Map so that values point at keys. |
static java.util.List | setDisjunction(java.util.Collection one, java.util.Collection two) Creates a new List containing all elements from the first Collection that are not in the second Collection . |
static java.util.List | setIntersection(java.util.Collection one, java.util.Collection two) Creates a new List containing the common elements of two Collections . |
static java.lang.Object | setProperties(java.util.Map propertyMap, java.lang.Object bean) As the three-argument version of this method, but passes a null dataSource |
static java.lang.Object | setProperties(java.util.Map propertyMap, java.lang.Object bean, DataSource dataSource) Sets the properties for a JavaBean provided as key-value pairs in a Map . |
static java.lang.Object | setProperties(java.util.Map propertyMap, java.lang.Object bean, DataSource dataSource, DSRequest dsRequest) This version of setProperties accepts a DSRequest for use as context by the conversion process. |
static java.util.List | setUnion(java.util.List one, java.util.List two) Creates a new List containing all the elements of two Lists . |
static java.lang.String | sha(java.lang.String plaintext) Returns the hash of the passed-in string, encrypted using the SHA-1 algorithm |
static java.util.List | subsetByPrefix(java.util.List list, java.lang.String prefix) Returns any strings within list which begin with prefix . |
static java.util.Map | subsetMap(java.util.Map origMap, java.util.List keys) Given a Map and a List of keys, returns a subset of the Map containing the key/value pairs as specified by the List of keys. |
static java.util.Map | substringKeyMap(java.lang.String prefix, java.util.Map source) Constructs a Map of key/value pairs from the source Map whose keys start with a specific prefix. |
static java.util.List | toLowerCaseList(java.util.List list) Given a List of strings, returns a new List of lower cased strings. |
public static java.util.List keysNotPresent(java.util.Map map, java.util.List keys)
Map
and a List
of keys, returns the list of keys in the List
that are not present in the Map
. map
- the Map
keys
- the List
of keysList
that are not present in the Map
public static java.util.Map subsetMap(java.util.Map origMap, java.util.List keys)
Map
and a List
of keys, returns a subset of the Map
containing the key/value pairs as specified by the List
of keys. origMap
- the original Map
keys
- the keys denoting the key/value pairs that should be included in the result Map
Map
containing only the key/value pairs corresponding to the supplied List
of keyspublic static java.util.List subsetByPrefix(java.util.List list, java.lang.String prefix)
list
which begin with prefix
. Non-string members of list
are ignored. list
- the list of stringsprefix
- strings in the list with this prefix will be returnedpublic static java.util.Map removeNullValuedKeys(java.util.Map map)
map
where the values are null
. map
- the Map
on which to operatepublic static java.util.Map removeEmptyStringValuedKeys(java.util.Map map)
map
where the values are empty strings. map
- the Map
on which to operatepublic static java.util.Map divideMap(java.util.Map origMap, java.util.List retainKeys)
Map
so that it retains only the specified keys, returning a Map
with any keys not retained. origMap
- the original Map
retainKeys
- the List
of keys corresponding to the key/value pairs that should be retainedMap
containing the key/value pairs that were not retainedpublic static java.util.Map mapUnion(java.util.Map primary, java.util.Map secondary)
Map
containing all the key/value pairs of the Maps
supplied as arguments, with the first Map
taking precedence. If the same key is present in both Maps
, the returned Map
will contain the key/value pair of the first Map
. primary
- the first Map
secondary
- the second Map
Maps
public static java.util.LinkedHashMap orderedMapUnion(java.util.Map primary, java.util.Map secondary)
mapUnion
, but keeps order of key/value pairs. Key/value pairs of primary Map
will go first, then key/value pairs from secondary Map
ignoring dublicates. Consider using LinkedHashMap
for primary and secondary maps to get full value from this method. primary
- the first Map
secondary
- the second Map
Maps
public static java.lang.Object deepMerge(java.lang.Object source, java.lang.Object target, boolean overwrite) throws java.lang.Exception
source
- the Object
to be copied fromtarget
- the Object
to be copied intooverwrite
- controls how non-collection/non-map collisions are resolved. If true, target values are overwritten with source values. If false, target values are not overwritten.Object
java.lang.Exception
public static void deepRemoveKey(java.lang.Object keyToRemove, java.lang.Object data) throws java.lang.Exception
keyToRemove
- the key to removedata
- the nested data structure to walkjava.lang.Exception
public static void deepRemoveNullValues(java.lang.Object data) throws java.lang.Exception
data
- the nested data structure to walkjava.lang.Exception
public static void deepRemoveEmptyCollections(java.lang.Object data) throws java.lang.Exception
data
- the nested data structure to walkjava.lang.Exception
public static java.util.Map mapMerge(java.util.Map source, java.util.Map target)
Map
into another Map
, replacing the key/value pair of the target Map
. source
- the Map
to be copied fromtarget
- the Map
to be copied intoMap
public static java.util.Map mapMergeNonNull(java.util.Map source, java.util.Map target)
Map
into another Map
, replacing the key/value pair of the target Map
if the source value is non-null. source
- the Map
to be copied fromtarget
- the Map
to be copied intoMap
public static java.util.Map putAllNotPresent(java.util.Map target, java.util.Map source)
Map
into another Map
, adding only key/value pairs for which the target Map
does not already have a mapping (as determined by the containsKey
method). source
- the Map
to be copied fromtarget
- the Map
to be copied intoMap
public static java.util.Map mapIntersection(java.util.Map primary, java.util.Map secondary)
Map
containing the key/value pairs of the primary Map
whose keys are present in the secondary Map
. primary
- the primary Map
secondary
- the secondary Map
Map
public static java.util.List mapIntersectionKeys(java.util.Map one, java.util.Map two)
Maps
. one
- the first Map
two
- the second Map
Maps
public static java.util.Map substringKeyMap(java.lang.String prefix, java.util.Map source)
Map
of key/value pairs from the source Map
whose keys start with a specific prefix. The new Map
's keys are the origin keys without the prefix. prefix
- the prefix to be matched with the keyssource
- the source Map
Map
public static java.util.Map identityMap(java.util.List list)
List
as the keys and values of a Map
. This can serve as a HashSet
which disallows duplicates and can quickly determine whether a set has a given member. list
- the List
to be storedMap
containing the uniques elements of the listpublic static java.util.Map reverseMap(java.util.Map origMap)
Map
so that values point at keys. If more than one value in the original Map
has the same key (where "same" is determined by hashcode
), the multiple keys are placed into a List
in the reversed Map
. Note: If in the original Map
, Lists
are mapped to values, and more than one List
maps to the same value, this method will work incorrectly since it won't be able to tell Lists
it created for multiple values from Lists
that were keys in the original Map
.
origMap
- the original Map
Map
public static java.util.Map putMultiple(java.util.Map map, java.lang.Object key, java.lang.Object value)
Map
, if there is already a value under that key, create a List
to hold the values. map
- the Map
to which the key/value pair should be addedkey
- the key in the key/value pairvalue
- the value in the key/value pairMap
, with the key/value pair added to itpublic static java.util.Map putMultipleAsList(java.util.Map map, java.lang.Object key, java.lang.Object value)
putMultiple
method, but in this case values are always encapsualted in a List
. map
- the Map
to which the key/value pair should be addedkey
- the key in the key/value pairvalue
- the value in the key/value pairMap
, with the key/value pair added to itpublic static java.util.List addAll(java.util.List target, java.util.List source)
List
to another. target
- the List
to which the contents of the source List
should be addedsource
- the List
to be added to the target List
List
public static java.util.List addAll(java.util.List target, java.util.Iterator source)
Iterator
to a List
. target
- the List
to which the contents of the source List
should be addedsource
- the List
to be added to the target List
List
public static java.util.List addAsList(java.util.List targetList, java.lang.Object sourceList)
sourceList
is a List, adds its items, if it's an Object, just adds the Object itself. Returns the modified targetList
.public static java.lang.Object combineAsLists(java.lang.Object one, java.lang.Object two)
public static java.util.Map putCombinedList(java.util.Map map, java.lang.Object key, java.lang.Object value)
public static java.util.List setUnion(java.util.List one, java.util.List two)
List
containing all the elements of two Lists
. one
- the first List
two
- the second List
List
public static void addDisjunctionToSet(java.util.List one, java.util.List two)
List
that are missing in the first. If the first or second List
is null
, the first will be unchanged. one
- the first List
two
- the second List
public static java.lang.Object[] arrayUnion(java.lang.Object[] one, java.lang.Object[] two)
one
- the first arraytwo
- the second arraypublic static java.util.List setIntersection(java.util.Collection one, java.util.Collection two)
List
containing the common elements of two Collections
. one
- the first Collection
two
- the second Collection
public static java.util.Map mapDisjunction(java.util.Map one, java.util.Map two)
Map
containing the key/value pairs whose keys are not present in both Maps
supplied. one
- the first Map
two
- the second Map
Map
of the disjunctionpublic static java.util.List setDisjunction(java.util.Collection one, java.util.Collection two)
List
containing all elements from the first Collection
that are not in the second Collection
. one
- the first Collection
two
- the second Collection
List
of elements present in the first List
that are not in the second List
public static java.util.List enumToList(java.util.Iterator i)
Iterator
to a List
. i
- the Iterator
List
of Iterator
elementspublic static java.util.List arrayToList(java.lang.Object[] arr, int from, int length)
List
containing a subset of an array. arr
- the source arrayfrom
- the array index of the first element of the subsetlength
- the number of elements in the subsetList
of elements from the subset of the source arraypublic static java.util.List arrayToList(java.lang.Object[] arr)
List
from an array. arr
- the source arrayList
of elements from the source arraypublic static java.lang.Object[] listToArray(java.util.List list)
Object
array from a List
. list
- the source List
Object
array containing the elements of the source listpublic static java.lang.String[] listToStringArray(java.util.Collection list)
String
array from a List
. list
- the source List
Strings
from the source List
public static java.util.Properties mapToProperties(java.util.Map map)
Properties
object from a Map
. The keys and values in the map must be strings. map
- the source Map
Properties
object containing the keys/values of the source Map
as propertiespublic static java.util.List keysAsList(java.util.Map map)
List
of the keys from a Map
. map
- the source Map
Map
public static java.util.List makeList(java.lang.Object element)
List
containing one element. element
- the elementList
containing the elementpublic static java.util.List makeListIfSingle(java.lang.Object obj)
List
containing one element if the element is not a List
. obj
- the elementList
public static boolean contains(java.lang.String str, java.lang.String substr)
str
- the enclosing stringsubstr
- the substringtrue
if the substring is contained in the string, false
otherwisepublic static org.apache.commons.jxpath.JXPathContext jxPathContext(java.lang.Object obj)
obj
- the context beanpublic static java.lang.Object nestedGet(java.lang.Object struct, java.lang.String fetch)
Lists
or Map
. The location of the structure is described by a string of Map
keys or List
indexes, separated by periods. For example, specifying the string "dog.2"
would retrieve the object with key "dog"
from the supplied Map
; this object should be a List
- the second element of this List
would be retrieved and returned.
struct
- the enclosing List
or Map
fetch
- the string describing the location of the desired objectjava.lang.ClassCastException
- if any of the enclosing data structures is neither a Map
nor a List
public static java.util.List buildList(java.lang.Object[] args)
List
containing the passed in objectsargs
- any number of arguments of Objects to add to the returned listList
containing the passed in argspublic static DataTypeMap buildMap(java.lang.Object[] args)
Map
of key/value pairs.args
- any (even) number of arguments - key then value then key then value etc.Map
containing the five key/value pairspublic static java.lang.Object getSingle(java.lang.Object toFetchFrom)
List
, or the key of a single key/value pair Map
. Returns null
if the toFetchFrom
argument is not a List
or Map
, or if toFetchFrom
does not contain a single element. toFetchFrom
- the source List
or Map
public static int checkSize(java.lang.Object obj)
Map
, List
or String
. obj
- the Map
, List
or String
Map
, List
or String
, as an int
or 0
if the object is of another classpublic static java.lang.String fastDateFormat(java.util.Date date)
String
representation of a Date
object. This method is faster than using the SimpleDateFormat
methods. date
- the date to be formattedString
public static java.lang.String getStackTrace(java.lang.Throwable t, int lineCount)
Throwable
object as a String
shortened to requested number of lines. t
- the Throwable
objectlineCount
- number of lines to keep in stack trace String
t
as a String
public static java.lang.String getStackTrace(java.lang.Throwable t)
Throwable
object as a String
. t
- the Throwable
objectt
as a String
public static java.util.Map remapRow(java.util.Map row, java.util.Map remap, boolean keepNonRemapped)
Map
to a new set of keys. Given an existing Map
and a mapping from old keys to new keys, create a new Map
that uses the new keys. row
- the row, a Map
remap
- the map of original to new column nameskeepNonRemapped
- boolean
indicating whether to keep data under keys that are not remappedremap
is null
public static java.util.Map remapRow(java.util.Map row, java.util.Map remap)
Map
to a new set of keys. Given an existing Map
and a mapping from old keys to new keys, create a new Map
that uses the new keys. Columns from the original row that were not remapped will be retained. row
- the row, a Map
remap
- the Map
of original to new column namesremap
is null
public static java.util.List remapRows(java.util.List rows, java.util.Map remap, boolean keepNonRemapped)
List
of Maps
. rows
- the List
of rowsremap
- the Map
of original to new column nameskeepNonRemapped
- boolean
indicating whether to keep data under keys that are not remappedList
, if remap
is null
public static java.util.List remapRows(java.util.List rows, java.util.Map remap)
List
of Maps
. Columns from the original row that were not remapped will be retained. rows
- the List
of rowsremap
- the Map
of original to new column namesList
, if remap
is null
public static java.util.List getProperty(java.util.List rows, java.lang.Object column)
List
of rows, and a column name, returns the List
of values for that column. The result set is represented as a List
of Map
objects, with each Map
representing a row of data. The keys and values in each row correspond to the column names and data, respectively.
For rows that do not have a value for the specified column, no value will be present in the return list, in other words, an empty object will not be added for that row.
rows
- the List
of rowscolumn
- the column name or keyList
of values for column
public static java.util.List findAll(java.util.List rows, java.lang.Object propertyName, java.lang.Object value)
rows
- the List of MapspropertyName
- the propertyName (key in the Map)value
- expected value of the propertyName (may be null)public static java.util.List findAll(java.util.List rows, java.util.Map properties)
rows
- the List of Mapsproperties
- Map of key/value pairs to match. May not have null values.public static java.util.List toLowerCaseList(java.util.List list)
List
of strings, returns a new List
of lower cased strings. list
- the List
of stringsList
of lower cased stringspublic static java.lang.String prettyPrint(java.lang.Object obj)
Object
for viewing or printing as a String
. obj
- the Object
to be formatted for outputString
to be used for the Object
in viewing or printingpublic static void addToIntInMap(java.util.Map map, java.lang.Object key, int addition)
If no Integer is currently stored under "key", creates a new Integer with value 0 before adding to it.
This method exists because of the horrific chain of typecasts otherwise necessary to achieve this effect.
public static void incrementIntInMap(java.util.Map map, java.lang.Object key)
If no Integer is currently stored under "key", creates a new Integer with value 0 before adding to it.
This method exists because of the horrific chain of typecasts otherwise necessary to achieve this effect.
public static int getIntInMap(java.util.Map map, java.lang.Object key)
int
. Returns 0 if no Integer is currently stored in the Map.
public static java.lang.String getterName(java.lang.reflect.Method method)
null
if provided method is not getter.method
- Method
Getter to extract property name.String
Getter property name or null
if provided method is not getter.public static java.lang.reflect.Field[] getClassFields(java.lang.Class c)
null
.c
- Class
to be inspected.Field[]
Array of class fields.public static java.lang.reflect.Method[] getClassMethods(java.lang.Class c)
null
.c
- Class
to be inspected.Method[]
Array of class methods.public static java.lang.Class getPropertyType(java.lang.Class c, java.lang.String propertyName) throws java.beans.IntrospectionException
NullPointerException
if either of parameters is null.c
- Class
to be inspected.propertyName
- String
Name of property.Class
Type of property.java.beans.IntrospectionException
- when specified class has no such property.public static java.lang.Class getCachedClass(java.lang.String className)
Class
object for specified name. Cached class is returned if exists otherwise class object is loaded and cached. Returns null
if class can not be loaded (not in class path).className
- String
qualified class name to load.Class
object of null
if class can not be loaded (not in class path).public static java.lang.Class getRealClass(java.lang.Object bean)
realClass = (Class) ((HibernateProxy) bean).getHibernateLazyInitializer().getPersistentClass();
bean
- Object
Class
public static java.util.Map getProperties(java.lang.Object bean) throws java.lang.Exception
Map
.bean
- the JavaBean objectMap
java.lang.Exception
public static java.util.Map getPropertyDescriptors(java.lang.Object bean) throws java.lang.Exception
Map
.bean
- the JavaBean objectMap
java.lang.Exception
public static java.util.Map getPropertyDescriptors(java.lang.Class beanClass) throws java.lang.Exception
Map
. Removes properties added by byte-code instrumentation:interceptFieldCallback
property is removed if class implements net.sf.cglib.transform.impl.InterceptFieldEnabled
interface;fieldHandler
property is removed if class implements org.hibernate.bytecode.javassist.FieldHandled
interface;beanClass
- the JavaBean classMap
java.lang.Exception
public static java.lang.Object setProperties(java.util.Map propertyMap, java.lang.Object bean) throws java.lang.Exception
propertyMap
- a Map
providing the key-value pairsbean
- the JavaBean objectMap
java.lang.IllegalArgumentException
- if a value provided in the Map
cannot be converted to an appropriate typejava.lang.Exception
public static java.lang.Object setProperties(java.util.Map propertyMap, java.lang.Object bean, DataSource dataSource) throws java.lang.Exception
Map
. This method performs automatic type detection and conversion where possible. Conversion is done via standard bean semantics. Additionally, some standard conversions are performed automatically - for example inbound java.util.Date object will be auto-converted to java.sql.Date or java.sql.Timestamp. Keys for which conversion fails or for which there are no corresponding Bean properties are ignored.
For properties that have primitive value on the target bean (eg properties of int
type), generally, the static "valueOf(String)" method for the primitive type (eg Boolean.valueOf(String)) will be invoked on the result of "toString()" for the Object being assigned to the primitive property.
As special cases the null string ("") and the null
value will become 0 when assigned to numeric primitive types (which cannot be null).
If the null string is assigned to a non-primitive numeric type (eg Long), the property will be assigned null
.
If the target bean property is an enum, this method attempts to set an appropriate value by use of the enum translate strategy set by calling setEnumTranslateStrategy() on the dataSource, if one is provided. See DataSource.setEnumTranslateStrategy(String)
. If there is no DataSource, or it cannot set a value by cleanly using the enumTranslateStrategy, it will attempt to infer a value by considering the incoming value first as a String to match against the enumerated type's value names, and failing that as an integer to match against the enumerated type's values as an ordinal value. If that fails, it sets the target bean property to null.
If the target bean property is of Joda-Time type (org.joda.time.DateTime, DateMidnight, LocalDateTime, LocalDate, LocalTime
), then value is passed to the target type constructor taking Object
parameter. See Joda documentation for supported inputs.
If the target bean property is of Java 8 Date/Time API type (java.time.LocalDate, LocalDateTime, LocalTime
), it is created with ZoneId.systemDefault()
for Date
input or attempting <target-type>.parse(input.toString())
for everything else.
Otherwise, if the type accepted by a setter method on the target bean cannot accept the type of the value in the propertyMap, this method will attempt type conversion by looking for a constructor on the setter method type that accepts instances of the value's type.
Also, if a Map value is found in the values of the passed in propertyMap, and the recipient field on the bean is not a Map, this method will treat the target field as a bean, attempting to create the bean via newInstance() and populating it via a recursive call to this method. In other words, this method will auto-create and populate inner beans.
Similarly if a Collection is found in the propertyMap, it will be applied to a target field of Collection type. If the target field is of an abstract Collection type, the default types used are:
A DataSource can be optionally passed as the third argument and can modify some of the above behaviors, including choice of concrete type when populating bean properties that declare only an abstract type or base type - See DataSource.setProperties(Map, Object)
for details.
propertyMap
- a Map
providing the key-value pairsbean
- the JavaBean objectdataSource
- a context DataSource, if applicable. Can be nulljava.lang.IllegalArgumentException
- if a value provided in the Map
cannot be converted to an appropriate typejava.lang.Exception
public static java.lang.Object setProperties(java.util.Map propertyMap, java.lang.Object bean, DataSource dataSource, DSRequest dsRequest) throws java.lang.Exception
DynamicDSGenerator
.propertyMap
- a Map
providing the key-value pairsbean
- the JavaBean objectdataSource
- a context DataSource, if applicabledsRequest
- a context DSRequest, if applicablejava.lang.IllegalArgumentException
- if a value provided in the Map
cannot be converted to an appropriate typejava.lang.Exception
public static void registerTransformer(java.lang.Class targetType, DataTools.Transformer transformer)
targetType
- the Class that this Transformer is capable of transforming totransformer
- the Transformer object itselfpublic static java.lang.Object castValue(java.lang.Object value, java.lang.Class targetType, DataSource ds)
value
to targetType
. null
if passed value is null
targetType
then same value returnedtargetType
is Long.TYPE
method returns Long
targetType
is Boolean
and passed value is instance of Number
then 0 converted to false
; any other number converted to true
targetType
is Boolean
and passed value is instance of Character
then 'T', 't', 'Y' and 'y' converted to true
; any other character converted to false
targetType
is Boolean
and passed value is instance of String
then "true", "t", "yes" and "y" (ignoring case) converted to true
; any other string converted to false
targetType
is Byte
and passed value is instance of Boolean
then false
converted to 0; true
converted to 1targetType
is Byte
and passed value is instance of Number
then value may be rounded and/or truncatedtargetType
is Byte
and passed value is instance of String
then value is parsed with Byte.valueOf()
targetType
is Short
and passed value is instance of Boolean
then false
converted to 0; true
converted to 1targetType
is Short
and passed value is instance of Number
then value may be rounded and/or truncatedtargetType
is Short
and passed value is instance of String
then value is parsed with Short.valueOf()
targetType
is Integer
and passed value is instance of Boolean
then false
converted to 0; true
converted to 1targetType
is Integer
and passed value is instance of Number
then value may be rounded and/or truncatedtargetType
is Integer
and passed value is instance of Character
then caracter value is returnedtargetType
is Integer
and passed value is instance of String
then value is parsed with Integer.valueOf()
targetType
is Long
and passed value is instance of Boolean
then false
converted to 0; true
converted to 1targetType
is Long
and passed value is instance of Number
then value may be rounded and/or truncatedtargetType
is Long
and passed value is instance of Character
then caracter value is returnedtargetType
is Long
and passed value is instance of String
then value is parsed with Long.valueOf()
targetType
is Long
and passed value is instance of Date
then Date.getTime()
returnedtargetType
is Float
and passed value is instance of Boolean
then false
converted to 0; true
converted to 1targetType
is Float
and passed value is instance of Number
then value may be rounded and/or truncatedtargetType
is Float
and passed value is instance of Character
then caracter value is returnedtargetType
is Float
and passed value is instance of String
then value is parsed with Float.valueOf()
targetType
is Float
and passed value is instance of Date
then Date.getTime()
returnedtargetType
is Double
and passed value is instance of Boolean
then false
converted to 0; true
converted to 1targetType
is Double
and passed value is instance of Number
then value may be roundedtargetType
is Double
and passed value is instance of Character
then caracter value is returnedtargetType
is Double
and passed value is instance of String
then value is parsed with Double.valueOf()
targetType
is Double
and passed value is instance of Date
then Date.getTime()
returnedtargetType
is Character
and passed value is instance of Boolean
then false
converted to 'f'; true
converted to 't'targetType
is Character
and passed value is instance of Number
then character for value code returned (value may be rounded and/or truncated)targetType
is Character
and passed value is instance of String
then returns first string charater; (char) 0
returned for empty stringtargetType
is String
then value.toString()
returnedtargetType
is BigInteger
and passed value is instance of Boolean
then false
converted to BigInteger.ZERO
; true
converted to BigInteger.ONE
targetType
is BigInteger
and passed value is instance of Number
then value may be roundedtargetType
is BigInteger
and passed value is instance of Character
then caracter value is returnedtargetType
is BigInteger
and passed value is instance of String
then value is parsedtargetType
is BigInteger
and passed value is instance of Date
then Date.getTime()
returnedtargetType
is BigDecimal
and passed value is instance of Boolean
then false
converted to BigDecimal.ZERO
; true
converted to BigDecimal.ONE
targetType
is BigDecimal
and passed value is instance of Number
then value converted to BigDecimal
targetType
is BigDecimal
and passed value is instance of Character
then caracter value is returnedtargetType
is BigDecimal
and passed value is instance of String
then value is parsedtargetType
is BigDecimal
and passed value is instance of Date
then Date.getTime()
returnedtargetType
is java.util.Date
and passed value is instance of Number
then java.util.Date
created with value as miliseconds (value may be rounded and/or truncated)targetType
is java.util.Date
and passed value is instance of String
then value is parsed with DateFormat.getDateTimeInstance()
targetType
is java.sql.Date
and passed value is instance of Number
then java.sql.Date
created with value as miliseconds (value may be rounded and/or truncated)targetType
is java.sql.Date
and passed value is instance of String
then value is parsed with DateFormat.getDateInstance()
targetType
is java.sql.Date
and passed value is instance of java.util.Date
then value is convertedtargetType
is java.sql.Date
and passed value is instance of java.sql.Time
then value is convertedtargetType
is java.sql.Date
and passed value is instance of java.sql.Timestamp
then value is convertedtargetType
is java.sql.Time
and passed value is instance of Number
then java.sql.Time
created with value as miliseconds (value may be rounded and/or truncated)targetType
is java.sql.Time
and passed value is instance of String
then value is parsed with DateFormat.getTimeInstance()
targetType
is java.sql.Time
and passed value is instance of java.util.Date
then value is convertedtargetType
is java.sql.Time
and passed value is instance of java.sql.Date
then value is convertedtargetType
is java.sql.Time
and passed value is instance of java.sql.Timestamp
then value is convertedtargetType
is java.sql.Timestamp
and passed value is instance of Number
then java.sql.Timestamp
created with value as miliseconds (value may be rounded and/or truncated)targetType
is java.sql.Timestamp
and passed value is instance of String
then value is parsed with DateFormat.getDateTimeInstance()
targetType
is java.sql.Timestamp
and passed value is instance of java.util.Date
then value is convertedtargetType
is java.sql.Timestamp
and passed value is instance of java.sql.Date
then value is convertedtargetType
is java.sql.Timestamp
and passed value is instance of java.sql.Time
then value is convertedvalue
- Object
value to be converted.targetType
- Class
conversion target type.ds
- DataSource
initiating conversion.Object
converted value.java.lang.ClassCastException
- if value can not be converted or parsing exception occurs.public static boolean isTextType(java.lang.Class clazz)
true
if provided class is either assignable to Character
or assignable to String
or represents primitive char
type.clazz
- Class
for testing.boolean
true
if specified class represents class for text; false
- for all other classes.public static boolean isNumberType(java.lang.Class clazz)
true
if provided class is either assignable to Number
or represents one of primitive number types byte, short, int, long, float, double
.clazz
- Class
for testing.boolean
true
if specified class represents class for numbers; false
- for all other classes.public static boolean recursiveFileDelete(java.io.File file)
file
- file or directory to deletepublic static java.lang.String md5(java.lang.String plaintext) throws java.lang.Exception
plaintext
- the text to encryptjava.lang.Exception
public static java.lang.String sha(java.lang.String plaintext) throws java.lang.Exception
plaintext
- the text to encryptjava.lang.Exception
public static java.lang.String bcrypt(java.lang.String plaintext) throws java.lang.Exception
plaintext
- the text to encryptjava.lang.Exception
public static java.lang.String hashValue(java.lang.String plaintext) throws java.lang.Exception
plaintext
- the text to encryptjava.lang.Exception
public static java.lang.String hashValue(java.lang.String plaintext, java.lang.String algorithm) throws java.lang.Exception
plaintext
- the text to encryptalgorithm
- the encryption algorithm to use. Search the client-side documentation for "HashAlgorithm" for details.java.lang.Exception
public static java.lang.String formatDate(java.lang.String format, java.util.Date date)
format
- A valid SimpleDateFormat format stringdate
- The date to formatpublic static java.lang.Object getLoggerRepository()
LoggerRepository
instance that was configured from log4j.isc.config.xml
. Use this method to access log4j loggers for custom categories defined in this file. Note: use this method only if log4j logging is used.
LoggerRepository
instance if configured, otherwise null
. Note: Object
return type is used to avoid unnecessary log4j dependency if alternative logging system is used.