com.wm.data
Class IDataUtil

java.lang.Object
  extended by com.wm.data.IDataUtil

public class IDataUtil
extends java.lang.Object

This class provides various utility methods for populating, converting, copying, and merging the elements within an IData object.


Constructor Summary
IDataUtil()
           
 
Method Summary
static void append(IData src, IData dst)
          Appends the elements from one IData object to the end of another IData object.
static IData clone(IData src)
          Returns a copy (a shallow clone) of the specified IData object.
static boolean contains(IDataCursor cursor, java.lang.Object value)
          Returns true if the IDataCursor contains the specified Object.
static void copy(IData src, IData dst)
          Copies all elements from one IData object to another IData object.
static IData create(java.lang.Object[][] data)
          Deprecated. 03/2003; Use IDataFactory.create() instead. Creates an IData object and initializes its key/value pairs from the contents of a specified two-column array, where the first column of the array contains key names and the second column contains the values of those keys.

The first column of the array (the one that specifies key names) must contain only String values that represent key names. Anything other than a String in this column will cause a ClassCastException to occur at run time.

If any member of the second column (the one that specifies values) of the array is null, that element is included in the IData object. If you DO NOT want to include null values in the IData object, use the create method provided by com.wm.data.IDataFactory instead.

static IData deepClone(IData src)
          Returns an independent copy (a deep clone) of the specified IData and its children.
static boolean equals(IData d1, IData d2)
          Indicates whether two IData objects contain the same keys and values.
static java.lang.Object get(IDataCursor cursor, java.lang.String key)
          Returns the Object at the specified key.
static boolean getBoolean(IDataCursor idc)
          Returns the selected element (the one at the cursor's current position) as a boolean.
static IData getIData(IDataCursor idc)
          Returns the selected element (the one at the cursor's current position) as an IData object.
static IData getIData(IDataCursor idc, java.lang.String key)
          Returns an IData representation of the value at the specified key.
static IData[] getIDataArray(IDataCursor idc, java.lang.String key)
          Returns an IData[] representation of the value at the specified key.
static int getInt(IDataCursor idc)
          Returns the selected element (the one at the cursor's current position) as an int or returns -1 if the element cannot be converted to an int.
static int getInt(IDataCursor idc, int def)
          Returns the selected element (the one at the cursor's current position) as an int or returns a default value if the element cannot be converted to an int.
static int getInt(IDataCursor idc, java.lang.String key, int def)
          Returns an int representation of the value at the specified key or returns a default value if the element cannot be converted to an int.
static java.lang.Object[] getObjectArray(IDataCursor idc, java.lang.String key)
          Returns an Object[] representation of the value at the specified key.
static java.lang.String getString(IDataCursor idc)
          Returns the selected element (the one at the cursor's current position) as a String.
static java.lang.String getString(IDataCursor idc, java.lang.String key)
          Returns a String representation of the value at the specified key.
static java.lang.String[] getStringArray(IDataCursor idc)
          Returns the selected element (the one at the cursor's current position) as a String[].
static java.lang.String[] getStringArray(IDataCursor idc, java.lang.String key)
          Returns a String[] representation of the value at the specified key.
static java.lang.String[][] getStringTable(IDataCursor idc)
          Returns the selected element (the one at the cursor's current position) as a String[][].
static java.lang.String[][] getStringTable(IDataCursor idc, java.lang.String key)
          Returns a String[][] representation of the value at the specified key.
static void merge(IData src, IData dst)
          Merges one IData object with another IData object.
static void put(IDataCursor cursor, java.lang.String key, java.lang.Object value)
          Adds an Object at the specified key in an IData object.
static void putInt(IDataCursor cursor, java.lang.String key, int value)
          Adds an int at the specified key in an IData object.
static void remove(IDataCursor idc, java.lang.String key)
          Deletes an element from an IData given the element’s key.
static int size(IDataCursor cursor)
          Returns the number of top-level elements in the IDataCursor.
static IData[] sortIDataArrayByKey(IData[] dataArray, java.lang.String key, int compareType, java.lang.String pattern, boolean reverse)
          Sorts an IData[] on a given key according to the criteria specified in the compareType, pattern, and order parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IDataUtil

public IDataUtil()
Method Detail

create

public static IData create(java.lang.Object[][] data)
Deprecated. 03/2003; Use IDataFactory.create() instead. Creates an IData object and initializes its key/value pairs from the contents of a specified two-column array, where the first column of the array contains key names and the second column contains the values of those keys.

The first column of the array (the one that specifies key names) must contain only String values that represent key names. Anything other than a String in this column will cause a ClassCastException to occur at run time.

If any member of the second column (the one that specifies values) of the array is null, that element is included in the IData object. If you DO NOT want to include null values in the IData object, use the create method provided by com.wm.data.IDataFactory instead.

Returns:
An IData object containing the key/value pairs defined by the values[][] array.
See Also:
IDataFactory.create(Object[][])

get

public static java.lang.Object get(IDataCursor cursor,
                                   java.lang.String key)
Returns the Object at the specified key.

Parameters:
cursor - an IDataCursor that points to the IData from which you want to retrieve the Object.
key - a String specifying the key whose value you want to retrieve.
Returns:
The Object contained in the IDataCursor at the given the key. If no Object exists at the given key, null is returned. If more than one Object exists with the given key, the Object at the first occurrence of the key is returned.

getIData

public static IData getIData(IDataCursor idc)
Returns the selected element (the one at the cursor's current position) as an IData object. If the selected element is not an IData object, getIData returns null.

Parameters:
idc - the IDataCursor that points to the element that getIData is to return.
Returns:
An IData object containing the selected element or null if that element is not an IData object.

getIData

public static IData getIData(IDataCursor idc,
                             java.lang.String key)
Returns an IData representation of the value at the specified key.

Parameters:
idc - An IDataCursor that points to the IData containing the element that you want to retrieve.
key - A String specifying the key that you want to retrieve.
Returns:
An IData representation of the value at the specified key. If the specified key does not contain an IData, getIData returns null.

getString

public static java.lang.String getString(IDataCursor idc)
Returns the selected element (the one at the cursor's current position) as a String. If the selected element is null, getString returns null.

Parameters:
idc - the IDataCursor that points to the element that getString is to return.
Returns:
A String containing a string representation of the selected element or null if element is null.

getString

public static java.lang.String getString(IDataCursor idc,
                                         java.lang.String key)
Returns a String representation of the value at the specified key.

Parameters:
idc - an IDataCursor that points to the IData containing the element that you want to retrieve.
key - a String specifying the key that you want to retrieve.
Returns:
A String representation of the value at the specified key. If the specified key is null, getString returns null. If the specified key does not contain a String, getString returns a String containing the toString() value of the specified key.

getStringArray

public static java.lang.String[] getStringArray(IDataCursor idc)
Returns the selected element (the one at the cursor's current position) as a String[]. If the selected element is not a string array, getStringArray returns null.

Parameters:
idc - The IDataCursor that points to the element that getStringArray is to return.
Returns:
A String[] containing the selected element or null if that element is not a string array.

getStringArray

public static java.lang.String[] getStringArray(IDataCursor idc,
                                                java.lang.String key)
Returns a String[] representation of the value at the specified key.

Parameters:
idc - an IDataCursor that points to the IData containing the element that you want to retrieve.
key - a String specifying the key that you want to retrieve.
Returns:
A String[] representation of the value at the specified key. If the specified key does not contain a String[], getStringArray returns null.

getStringTable

public static java.lang.String[][] getStringTable(IDataCursor idc)
Returns the selected element (the one at the cursor's current position) as a String[][]. If the selected element is not a string table, getStringTable returns null.

Parameters:
idc - the IDataCursor that points to the element that getStringTable is to return.
Returns:
A String[][] containing the selected element or null if that element is not a two-dimensional string array.

getStringTable

public static java.lang.String[][] getStringTable(IDataCursor idc,
                                                  java.lang.String key)
Returns a String[][] representation of the value at the specified key. If the selected element is not a string table, getStringTable returns null.

Parameters:
idc - an IDataCursor that points to the IData containing the element that you want to retrieve.
key - a String specifying the key whose value you want to retrieve.
Returns:
The String[][] value of the element at the specified key. If the selected element is not a string table, getStringTable returns null.

getBoolean

public static boolean getBoolean(IDataCursor idc)
Returns the selected element (the one at the cursor's current position) as a boolean. If the selected element is not a boolean object, cannot be converted to a boolean object from a String, or is null, getBoolean returns false.

Parameters:
idc - the IDataCursor that points to the element that getBoolean is to return.
Returns:
A boolean containing the value of the selected element or false if the selected element is not a boolean object, cannot be converted to a boolean object from a String, or is null.

getInt

public static int getInt(IDataCursor idc)
Returns the selected element (the one at the cursor's current position) as an int or returns -1 if the element cannot be converted to an int.

Parameters:
idc - the IDataCursor that points to the element that getInt is to return.
Returns:
the int value of the element at the specified cursor, -1 (negative one) if the element is null or cannot be converted to an int from a String

getInt

public static int getInt(IDataCursor idc,
                         int def)
Returns the selected element (the one at the cursor's current position) as an int or returns a default value if the element cannot be converted to an int.

Parameters:
idc - the IDataCursor that points to the element that getInt is to return.
def - the int value that getInt will return if the selected element is null or cannot be converted to an int.
Returns:
An int containing the value of the selected element or the value specified by def if the selected element is null or cannot be converted to an int.

getInt

public static int getInt(IDataCursor idc,
                         java.lang.String key,
                         int def)
Returns an int representation of the value at the specified key or returns a default value if the element cannot be converted to an int.

Parameters:
idc - an IDataCursor that points to the IData containing the element that you want to retrieve.
key - a String specifying the key whose value you want to retrieve.
def - the default int to return if the specified key is null or not an int.
Returns:
An int representation of the value at the specified key. If the specified key does not contain an int or is null, getInt returns the value specified in def.

getIDataArray

public static IData[] getIDataArray(IDataCursor idc,
                                    java.lang.String key)
Returns an IData[] representation of the value at the specified key.

Parameters:
idc - an IDataCursor that points to the IData containing the element that you want to retrieve.
key - a String specifying the key whose value you want to retrieve.
Returns:
An IData[] representation of the value at the specified key. If the specified key does not contain an IData[], getIDataArray returns null.

getObjectArray

public static java.lang.Object[] getObjectArray(IDataCursor idc,
                                                java.lang.String key)
Returns an Object[] representation of the value at the specified key.

Parameters:
idc - an IDataCursor that points to IData containing the element that you want to retrieve.
key - a String specifying the key whose value you want to retrieve.
Returns:
The Object[] value of the element at the specified cursor. If the selected element is not an object array, getObjectArray returns null.

put

public static void put(IDataCursor cursor,
                       java.lang.String key,
                       java.lang.Object value)
Adds an Object at the specified key in an IData object. If the specified key does not exist in the IData, the Object is appended to the end of the IData object. If the key exists, the new Object replaces the one at that key.

Parameters:
cursor - an IDataCursor that points to the IData to which you want to add an Object.
key - a String specifying the key at which the Object is to be added.
value - the Object that is to be added at the specified key.

putInt

public static void putInt(IDataCursor cursor,
                          java.lang.String key,
                          int value)
Adds an int at the specified key in an IData object. If the specified key does not exist in the IData, the int is appended to the end of the IData object. If the key exists, the new int replaces the one at that key.

Parameters:
cursor - an IDataCursor that points to the IData to which you want to add an int.
key - a String specifying the key at which the int is to be added.
value - the int that is to be added at the specified key.

append

public static void append(IData src,
                          IData dst)
Appends the elements from one IData object to the end of another IData object. The order of the elements in the source object is preserved. Duplicate elements are preserved.

Parameters:
src - the IData object whose elements are to be copied.
dst - the IData object into which the elements from the source object will be appended.
See Also:
copy(com.wm.data.IData, com.wm.data.IData), merge(com.wm.data.IData, com.wm.data.IData)

merge

public static void merge(IData src,
                         IData dst)
Merges one IData object with another IData object. Only top-level elements are merged. If duplicate element names exist in the two objects, those elements are merged as follows:

This is the method that Java services should use to incorporate their output into the pipeline in a backward compatible manner. The merge rules described above provide standard behavior and support for duplicate outputs. This is required to make Developer pipeline predictions reflect the true output of Java services.

Parameters:
src - the IData object whose elements are to be copied.
dst - the IData object into which the elements from the source object will be merged.
See Also:
copy(com.wm.data.IData, com.wm.data.IData), merge(com.wm.data.IData, com.wm.data.IData)

copy

public static void copy(IData src,
                        IData dst)
Copies all elements from one IData object to another IData object. If the destination IData object has its own elements, copy inserts the elements from the source object after the first element in the destination object. The order of the elements in the source object is preserved, as are duplicate key names. This method is similar to append except for where the copied key/value pairs are inserted.

Parameters:
src - the IData object whose elements are to be copied.
dst - the IData object into which the elements from the source object will be copied.
See Also:
append(com.wm.data.IData, com.wm.data.IData), merge(com.wm.data.IData, com.wm.data.IData)

clone

public static IData clone(IData src)
Returns a copy (a shallow clone) of the specified IData object. Shallow clone means that the values are references to the same object instances as the source IData.

Parameters:
src - the IData object that is to be copied.
Returns:
An IData object containing the same key/value pairs as the one from which it was copied.
See Also:
deepClone(com.wm.data.IData)

deepClone

public static IData deepClone(IData src)
Returns an independent copy (a deep clone) of the specified IData and its children.

Important:Be aware that using this method is extremely expensive in terms of processing time and memory. Use it only when absolutely necessary.

Parameters:
src - the IData object that you want to copy.
Returns:
An IData that is an independent copy of the source IData and its children.
See Also:
clone(com.wm.data.IData)

sortIDataArrayByKey

public static IData[] sortIDataArrayByKey(IData[] dataArray,
                                          java.lang.String key,
                                          int compareType,
                                          java.lang.String pattern,
                                          boolean reverse)
Sorts an IData[] on a given key according to the criteria specified in the compareType, pattern, and order parameters.

Parameters:
dataArray - the IData[] object that is to be sorted.
key - a String specifying the key on which the IData[] is to be sorted.
compareType - an int specifying the comparison type. Valid choices are:
IDataUtil.COMPARE_TYPE_COLLATION
IDataUtil.COMPARE_TYPE_TIME
pattern - a String specifying the pattern to sort by. When used with IDataUtil.COMPARE_TYPE_TIME and set to null, a default pattern of MM/dd/yyyy hh:mm:ss a is used, where “a” indicates the a.m./p.m. marker. See the java.text SimpleDateFormat class for more information about date and time patterns.
reverse - a Boolean specifying whether the IData[] is to be sorted in descending order. Set to true for descending order.
Returns:
The IData[] object sorted by the specified criteria. Will return null if key is not in every entry of the IData[] object or if compareType is invalid.

equals

public static boolean equals(IData d1,
                             IData d2)
Indicates whether two IData objects contain the same keys and values. If the IData object contains nested IData, IData[], Vector, IDataCodable, IDataCodable [], or Object objects, the structure of the nested objects are compared, too. All other object types must be identical or satisfy object_one.equals(object_two).

Note: Null elements are evaluated in the same way as other keys and values. As long as two null elements have the same key name and both keys are in the same position within their respective IData objects, the two elements will be considered equal.

Parameters:
d1 - an IData object that will be compared to the IData object specified in d2.
d2 - an IData object that will be compared to the IData object specified in d1.
Returns:
true if the two IData objects contain the same elements; false otherwise.

remove

public static void remove(IDataCursor idc,
                          java.lang.String key)
Deletes an element from an IData given the element’s key. If multiple elements exist in the IData with the given key, the first occurrence of the key is deleted.

Parameters:
idc - an IDataCursor that points to the IData containing the element that you want to delete.
key - a String specifying the key whose value you want to remove.

size

public static int size(IDataCursor cursor)
Returns the number of top-level elements in the IDataCursor.

Parameters:
cursor - an IDataCursor that points to the IData whose elements you want to count.
Returns:
An containing the number of top level elements in the IData.

contains

public static boolean contains(IDataCursor cursor,
                               java.lang.Object value)
Returns true if the IDataCursor contains the specified Object.

Parameters:
cursor - an IDataCursor that points to the IData that you want to search. if the specified Object exists in it.
value - the Object that you want contains to look for.
Returns:
true if the IData contains the specified Object; false otherwise.