com.isomorphic.util
Class DataTools

java.lang.Object
  |
  +--com.isomorphic.util.DataTools

public class DataTools
extends java.lang.Object

DataTools is a utility class with the following facilities:

See Also:
prettyPrint(Object), getProperties(Object), setProperties(Map, Object)

Method Summary
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.util.List buildList(java.lang.Object one)
          Creates a List of one elements.
static java.util.List buildList(java.lang.Object one, java.lang.Object two)
          Creates a List of two elements.
static java.util.List buildList(java.lang.Object one, java.lang.Object two, java.lang.Object three)
          Creates a List of three elements.
static java.util.List buildList(java.lang.Object one, java.lang.Object two, java.lang.Object three, java.lang.Object four)
          Creates a List of four elements.
static java.util.Map buildMap(java.lang.Object key, java.lang.Object value)
          Creates a Map of one key/value pair.
static java.util.Map buildMap(java.lang.Object key, java.lang.Object value, java.lang.Object key2, java.lang.Object value2)
          Creates a Map of two key/value pairs.
static java.util.Map buildMap(java.lang.Object key, java.lang.Object value, java.lang.Object key2, java.lang.Object value2, java.lang.Object key3, java.lang.Object value3)
          Creates a Map of three key/value pairs.
static java.util.Map buildMap(java.lang.Object key, java.lang.Object value, java.lang.Object key2, java.lang.Object value2, java.lang.Object key3, java.lang.Object value3, java.lang.Object key4, java.lang.Object value4)
          Creates a Map of four key/value pairs.
static java.util.Map buildMap(java.lang.Object key, java.lang.Object value, java.lang.Object key2, java.lang.Object value2, java.lang.Object key3, java.lang.Object value3, java.lang.Object key4, java.lang.Object value4, java.lang.Object key5, java.lang.Object value5)
          Creates a Map of five key/value pairs.
static java.util.Map buildMap(java.lang.Object key, java.lang.Object value, java.lang.Object key2, java.lang.Object value2, java.lang.Object key3, java.lang.Object value3, java.lang.Object key4, java.lang.Object value4, java.lang.Object key5, java.lang.Object value5, java.lang.Object key6, java.lang.Object value6)
          Creates a Map of six key/value pairs.
static java.util.Map buildMap(java.lang.Object key, java.lang.Object value, java.lang.Object key2, java.lang.Object value2, java.lang.Object key3, java.lang.Object value3, java.lang.Object key4, java.lang.Object value4, java.lang.Object key5, java.lang.Object value5, java.lang.Object key6, java.lang.Object value6, java.lang.Object key7, java.lang.Object value7)
          Creates a Map of six key/value pairs.
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 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.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.
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.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.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 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 one, java.util.Map two)
          Constructs a Map containing all the key/value pairs of the Maps supplied as arguments.
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.Map orderedMapUnion(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 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 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)
          Sets the properties for a JavaBean provided as key-value pairs in a Map.
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.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.
 

Method Detail

keysNotPresent

public 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.

Parameters:
map - the Map
keys - the List of keys
Returns:
the list of keys in the supplied List that are not present in the Map

subsetMap

public 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.

Parameters:
origMap - the original Map
keys - the keys denoting the key/value pairs that should be included in the result Map
Returns:
the subset of the original Map containing only the key/value pairs corresponding to the supplied List of keys

subsetByPrefix

public static java.util.List subsetByPrefix(java.util.List list,
                                            java.lang.String prefix)
Returns any strings within list which begin with prefix. Non-string members of list are ignored.

Parameters:
list - the list of strings
prefix - strings in the list with this prefix will be returned
Returns:
a list of the strings in the supplied list that begin with the specified prefix

removeNullValuedKeys

public static java.util.Map removeNullValuedKeys(java.util.Map map)
Removes all keys from the passed-in map where the values are null.

Parameters:
map - the Map on which to operate

removeEmptyStringValuedKeys

public static java.util.Map removeEmptyStringValuedKeys(java.util.Map map)
Removes all keys from the passed-in map where the values are empty strings.

Parameters:
map - the Map on which to operate

divideMap

public 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.

Parameters:
origMap - the original Map
retainKeys - the List of keys corresponding to the key/value pairs that should be retained
Returns:
a Map containing the key/value pairs that were not retained

mapUnion

public static java.util.Map mapUnion(java.util.Map one,
                                     java.util.Map two)
Constructs a Map containing all the key/value pairs of the Maps supplied as arguments.

Parameters:
one - the first Map
two - the second Map
Returns:
the union of the two Maps

orderedMapUnion

public static java.util.Map orderedMapUnion(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. If the same key is present in both Maps, the returned Map will contain the key/value pair of the first Map.

Parameters:
one - the first Map
two - the second Map
Returns:
the union of the two Maps

deepMerge

public static java.lang.Object deepMerge(java.lang.Object source,
                                         java.lang.Object target,
                                         boolean overwrite)
                                  throws java.lang.Exception
Merges one collections data structure into another. Any nodes/items not present in the target get created. Those that are present are merged. Note that the initial source and target must be of the same type and their data must not contain conflicting types.
Parameters:
source - the Object to be copied from
target - the Object to be copied into
overwrite - 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.
Returns:
the merged Object

deepRemoveKey

public static void deepRemoveKey(java.lang.Object keyToRemove,
                                 java.lang.Object data)
                          throws java.lang.Exception
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.
Parameters:
keyToRemove - the key to remove
data - the nested data structure to walk

deepRemoveNullValues

public static void deepRemoveNullValues(java.lang.Object data)
                                 throws java.lang.Exception
Walks a nested Collection-based datastructure and removes all entities that have a null value. For Maps this means the removal of keys with a value of null, for Collections this means the removel of null elements.
Parameters:
data - the nested data structure to walk

deepRemoveEmptyCollections

public static void deepRemoveEmptyCollections(java.lang.Object data)
                                       throws java.lang.Exception
Walks a nested Collection-based datastructure and removes all Collections entities that are zero-sized.
Parameters:
data - the nested data structure to walk

mapMerge

public 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.

Parameters:
source - the Map to be copied from
target - the Map to be copied into
Returns:
the merged Map

mapMergeNonNull

public 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.

Parameters:
source - the Map to be copied from
target - the Map to be copied into
Returns:
the merged Map

putAllNotPresent

public 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).

Parameters:
source - the Map to be copied from
target - the Map to be copied into
Returns:
the merged Map

mapIntersection

public 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.

Parameters:
primary - the primary Map
secondary - the secondary Map
Returns:
the intersection of the two Map

mapIntersectionKeys

public static java.util.List mapIntersectionKeys(java.util.Map one,
                                                 java.util.Map two)
Returns the list of keys that are present in both Maps.

Parameters:
one - the first Map
two - the second Map
Returns:
the list of keys that is the intersection of the Maps

substringKeyMap

public 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. The new Map's keys are the origin keys without the prefix.

Parameters:
prefix - the prefix to be matched with the keys
source - the source Map
Returns:
the new Map

identityMap

public static java.util.Map identityMap(java.util.List list)
Stores the elements of a 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.

Parameters:
list - the List to be stored
Returns:
the Map containing the uniques elements of the list

reverseMap

public static java.util.Map reverseMap(java.util.Map origMap)
Reverses a 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.

Parameters:
origMap - the original Map
Returns:
the reversed Map

putMultiple

public 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.

Parameters:
map - the Map to which the key/value pair should be added
key - the key in the key/value pair
value - the value in the key/value pair
Returns:
the Map, with the key/value pair added to it

putMultipleAsList

public 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.

Parameters:
map - the Map to which the key/value pair should be added
key - the key in the key/value pair
value - the value in the key/value pair
Returns:
the Map, with the key/value pair added to it

addAll

public static java.util.List addAll(java.util.List target,
                                    java.util.List source)
Adds the contents of one List to another.

Parameters:
target - the List to which the contents of the source List should be added
source - the List to be added to the target List
Returns:
the combined List

addAll

public static java.util.List addAll(java.util.List target,
                                    java.util.Iterator source)
Adds all the elements of an Iterator to a List.

Parameters:
target - the List to which the contents of the source List should be added
source - the List to be added to the target List
Returns:
the combined List

addAsList

public static java.util.List addAsList(java.util.List targetList,
                                       java.lang.Object sourceList)
Add either a single object or List to another List. If sourceList is a List, adds its items, if it's an Object, just adds the Object itself. Returns the modified targetList.

combineAsLists

public 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.

putCombinedList

public 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.

setUnion

public static java.util.List setUnion(java.util.List one,
                                      java.util.List two)
Creates a new List containing all the elements of two Lists.

Parameters:
one - the first List
two - the second List
Returns:
the combined List

addDisjunctionToSet

public static void addDisjunctionToSet(java.util.List one,
                                       java.util.List two)
Adds elements of the second List that are missing in the first. If the first or second List is null, the first will be unchanged.

Parameters:
one - the first List
two - the second List
Returns:
the combined List

arrayUnion

public static java.lang.Object[] arrayUnion(java.lang.Object[] one,
                                            java.lang.Object[] two)
Creates a new array containing all the elements of two arrays.

Parameters:
one - the first array
two - the second array
Returns:
the combined array

setIntersection

public static java.util.List setIntersection(java.util.Collection one,
                                             java.util.Collection two)
Creates a new List containing the common elements of two Collections.

Parameters:
one - the first Collection
two - the second Collection
Returns:
the common elements

mapDisjunction

public 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.

Parameters:
one - the first Map
two - the second Map
Returns:
the Map of the disjunction

setDisjunction

public 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.

Parameters:
one - the first Collection
two - the second Collection
Returns:
the List of elements present in the first List that are not in the second List

enumToList

public static java.util.List enumToList(java.util.Iterator i)
Converts an Iterator to a List.

Parameters:
i - the Iterator
Returns:
the List of Iterator elements

arrayToList

public static java.util.List arrayToList(java.lang.Object[] arr,
                                         int from,
                                         int length)
Creates a List containing a subset of an array.

Parameters:
arr - the source array
from - the array index of the first element of the subset
length - the number of elements in the subset
Returns:
the List of elements from the subset of the source array

arrayToList

public static java.util.List arrayToList(java.lang.Object[] arr)
Creates a List from an array.

Parameters:
arr - the source array
Returns:
the List of elements from the source array

listToArray

public static java.lang.Object[] listToArray(java.util.List list)
Creates an Object array from a List.

Parameters:
list - the source List
Returns:
the Object array containing the elements of the source list

listToStringArray

public static java.lang.String[] listToStringArray(java.util.Collection list)
Creates a String array from a List.

Parameters:
list - the source List
Returns:
the array of Strings from the source List

mapToProperties

public static java.util.Properties mapToProperties(java.util.Map map)
Creates a Properties object from a Map. The keys and values in the map must be strings.

Parameters:
map - the source Map
Returns:
the Properties object containing the keys/values of the source Map as properties

keysAsList

public static java.util.List keysAsList(java.util.Map map)
Creates a List of the keys from a Map.

Parameters:
map - the source Map
Returns:
the list of keys from the source Map

makeList

public static java.util.List makeList(java.lang.Object element)
Creates a List containing one element.

Parameters:
element - the element
Returns:
the List containing the element

makeListIfSingle

public static java.util.List makeListIfSingle(java.lang.Object obj)
Creates a List containing one element if the element is not a List.

Parameters:
obj - the element
Returns:
the List

contains

public static boolean contains(java.lang.String str,
                               java.lang.String substr)
Tests if the specified substring is present in the specified string.

Parameters:
str - the enclosing string
substr - the substring
Returns:
true if the substring is contained in the string, false otherwise

nestedGet

public static java.lang.Object nestedGet(java.lang.Object struct,
                                         java.lang.String fetch)
Retrieves a object from a series of nested 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.

Parameters:
struct - the enclosing List or Map
fetch - the string describing the location of the desired object
Returns:
the desired object
Throws:
java.lang.ClassCastException - if any of the enclosing data structures is neither a Map nor a List

buildList

public static java.util.List buildList(java.lang.Object one)
Creates a List of one elements. This method is useful because new ArrayList().add() does not return the List.

Parameters:
one - the first element
two - the second element
Returns:
the List containing the two elements

buildList

public static java.util.List buildList(java.lang.Object one,
                                       java.lang.Object two)
Creates a List of two elements.

Parameters:
one - the first element
two - the second element
Returns:
the List containing the two elements

buildList

public static java.util.List buildList(java.lang.Object one,
                                       java.lang.Object two,
                                       java.lang.Object three)
Creates a List of three elements.

Parameters:
one - the first element
two - the second element
three - the third element
Returns:
the List containing the three elements

buildList

public static java.util.List buildList(java.lang.Object one,
                                       java.lang.Object two,
                                       java.lang.Object three,
                                       java.lang.Object four)
Creates a List of four elements.

Parameters:
one - the first element
two - the second element
three - the third element
four - the fourth element
Returns:
the List containing the four elements

buildMap

public static java.util.Map buildMap(java.lang.Object key,
                                     java.lang.Object value)
Creates a Map of one key/value pair.

Parameters:
key - the key
value - the value
Returns:
the Map containing the key/value pair

buildMap

public static java.util.Map buildMap(java.lang.Object key,
                                     java.lang.Object value,
                                     java.lang.Object key2,
                                     java.lang.Object value2)
Creates a Map of two key/value pairs.

Parameters:
key - the first key
value - the first value
key2 - the second key
value2 - the second value
Returns:
the Map containing the two key/value pairs

buildMap

public static java.util.Map buildMap(java.lang.Object key,
                                     java.lang.Object value,
                                     java.lang.Object key2,
                                     java.lang.Object value2,
                                     java.lang.Object key3,
                                     java.lang.Object value3)
Creates a Map of three key/value pairs.

Parameters:
key - the first key
value - the first value
key2 - the second key
value2 - the second value
key3 - the third key
value3 - the third value
Returns:
the Map containing the three key/value pairs

buildMap

public static java.util.Map buildMap(java.lang.Object key,
                                     java.lang.Object value,
                                     java.lang.Object key2,
                                     java.lang.Object value2,
                                     java.lang.Object key3,
                                     java.lang.Object value3,
                                     java.lang.Object key4,
                                     java.lang.Object value4)
Creates a Map of four key/value pairs.

Parameters:
key - the first key
value - the first value
key2 - the second key
value2 - the second value
key3 - the third key
value3 - the third value
key4 - the fourth key
value4 - the fourth value
Returns:
the Map containing the four key/value pairs

buildMap

public static java.util.Map buildMap(java.lang.Object key,
                                     java.lang.Object value,
                                     java.lang.Object key2,
                                     java.lang.Object value2,
                                     java.lang.Object key3,
                                     java.lang.Object value3,
                                     java.lang.Object key4,
                                     java.lang.Object value4,
                                     java.lang.Object key5,
                                     java.lang.Object value5)
Creates a Map of five key/value pairs.

Parameters:
key - the first key
value - the first value
key2 - the second key
value2 - the second value
key3 - the third key
value3 - the third value
key4 - the fourth key
value4 - the fourth value
key5 - the fifth key
value5 - the fifth value
Returns:
the Map containing the five key/value pairs

buildMap

public static java.util.Map buildMap(java.lang.Object key,
                                     java.lang.Object value,
                                     java.lang.Object key2,
                                     java.lang.Object value2,
                                     java.lang.Object key3,
                                     java.lang.Object value3,
                                     java.lang.Object key4,
                                     java.lang.Object value4,
                                     java.lang.Object key5,
                                     java.lang.Object value5,
                                     java.lang.Object key6,
                                     java.lang.Object value6)
Creates a Map of six key/value pairs.

Parameters:
key - the first key
value - the first value
key2 - the second key
value2 - the second value
key3 - the third key
value3 - the third value
key4 - the fourth key
value4 - the fourth value
key5 - the fifth key
value5 - the fifth value
key6 - the sixth key
value6 - the sixth value
Returns:
the Map containing the six key/value pairs

buildMap

public static java.util.Map buildMap(java.lang.Object key,
                                     java.lang.Object value,
                                     java.lang.Object key2,
                                     java.lang.Object value2,
                                     java.lang.Object key3,
                                     java.lang.Object value3,
                                     java.lang.Object key4,
                                     java.lang.Object value4,
                                     java.lang.Object key5,
                                     java.lang.Object value5,
                                     java.lang.Object key6,
                                     java.lang.Object value6,
                                     java.lang.Object key7,
                                     java.lang.Object value7)
Creates a Map of six key/value pairs.

Parameters:
key - the first key
value - the first value
key2 - the second key
value2 - the second value
key3 - the third key
value3 - the third value
key4 - the fourth key
value4 - the fourth value
key5 - the fifth key
value5 - the fifth value
key6 - the sixth key
value6 - the sixth value
key7 - the seventh key
value7 - the seventh value
Returns:
the Map containing the six key/value pairs

getSingle

public 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. Returns null if the toFetchFrom argument is not a List or Map, or if toFetchFrom does not contain a single element.

Parameters:
toFetchFrom - the source List or Map
Returns:
the single element or key

checkSize

public static int checkSize(java.lang.Object obj)
Obtains the size of a Map, List or String.

Parameters:
obj - the Map, List or String
Returns:
the size of the Map, List or String, as an int or 0 if the object is of another class

fastDateFormat

public static java.lang.String fastDateFormat(java.util.Date date)
Returns a String representation of a Date object. This method is faster than using the SimpleDateFormat methods.

Parameters:
date - the date to be formatted
Returns:
the formatted date as a String

getStackTrace

public static java.lang.String getStackTrace(java.lang.Throwable t)
Returns the stack trace of a Throwable object as a String.

Parameters:
t - the Throwable object
Returns:
the stack trace for t as a String

remapRow

public 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. Given an existing Map and a mapping from old keys to new keys, create a new Map that uses the new keys.

Parameters:
row - the row, a Map
remap - the map of original to new column names
keepNonRemapped - boolean indicating whether to keep data under keys that are not remapped
Returns:
the row with remapped keys, or the original row, if remap is null

remapRow

public 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. 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.

Parameters:
row - the row, a Map
remap - the Map of original to new column names
Returns:
the row with remapped keys, or the original row, if remap is null

remapRows

public static java.util.List remapRows(java.util.List rows,
                                       java.util.Map remap,
                                       boolean keepNonRemapped)
Remap the keys in a List of Maps.

Parameters:
rows - the List of rows
remap - the Map of original to new column names
keepNonRemapped - boolean indicating whether to keep data under keys that are not remapped
Returns:
the result set with remapped columns, or the original List, if remap is null

remapRows

public static java.util.List remapRows(java.util.List rows,
                                       java.util.Map remap)
Remap the keys in a List of Maps. Columns from the original row that were not remapped will be retained.

Parameters:
rows - the List of rows
remap - the Map of original to new column names
Returns:
the result set with remapped columns, or the original List, if remap is null

getProperty

public 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.

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.

Parameters:
rows - the List of rows
column - the column name or key
Returns:
the List of values for column

toLowerCaseList

public static java.util.List toLowerCaseList(java.util.List list)
Given a List of strings, returns a new List of lower cased strings.

Parameters:
list - the List of strings
Returns:
the List of lower cased strings

prettyPrint

public static java.lang.String prettyPrint(java.lang.Object obj)
                                    throws java.lang.Exception
Formats information about an Object for viewing or printing as a String.

Parameters:
obj - the Object to be formatted for output
Returns:
the information String to be used for the Object in viewing or printing

addToIntInMap

public 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".

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.


incrementIntInMap

public 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".

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.


getIntInMap

public 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.

Returns 0 if no Integer is currently stored in the Map.


getProperties

public static java.util.Map getProperties(java.lang.Object bean)
                                   throws java.lang.Exception
Gets the properties for a JavaBean and returns them as a Map.

Parameters:
bean - the JavaBean object
Returns:
the JavaBean properties as a Map

getPropertyDescriptors

public static java.util.Map getPropertyDescriptors(java.lang.Object bean)
                                            throws java.lang.Exception
Gets the property descriptors for a JavaBean and returns them as a Map.

Parameters:
bean - the JavaBean object
Returns:
the JavaBean property descriptors as a Map

getPropertyDescriptors

public static java.util.Map getPropertyDescriptors(java.lang.Class beanClass)
                                            throws java.lang.Exception
Gets the properties for a JavaBean class through introspection and returns them as a Map.

Parameters:
beanClass - the JavaBean class
Returns:
the JavaBean class's property descriptors as a Map

setProperties

public static java.lang.Object setProperties(java.util.Map propertyMap,
                                             java.lang.Object bean)
                                      throws java.lang.Exception
Sets the properties for a JavaBean provided as key-value pairs in a 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.sqlTimestamp.

Also, 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.

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.

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.

Parameters:
propertyMap - a Map providing the key-value pairs
bean - the JavaBean object
Returns:
the JavaBean properties as a Map
Throws:
java.lang.IllegalArgumentException - if a value provided in the Map cannot be converted to an appropriate type

recursiveFileDelete

public static boolean recursiveFileDelete(java.io.File file)
Recursively deletes a directory.
Parameters:
file - file or directory to delete
Returns:
true if successful, false otherwise cannot be converted to an appropriate type