public class IDataMap
extends java.util.AbstractMap<java.lang.String,java.lang.Object>
IDataMap combines the functionality of IData, IDataCursor, IDataUtil, and IDataFactory. IDataMap implements the java.util.Map interface from the Java Collections Framework, providing a familiar and simple interface. IDataMap expands the Map interface, adding getAs<Type> methods, which convert the returned value to a specific type.
For example:
IDataMap pl = new IDataMap(pipeline); String userName = pl.getAsString("userName"); Integer port = pl.getAsInteger("port", 5555); for (String key : pl.keys()) { System.out.println("pipeline[" + key + "]: " + pl.get(key)); } IData[] assets = pl.getAsIDataArray("assets"); // ... processing ... pl.put("status", "complete");
IDataMap, as a Map, assumes that the keys of the IData instance are unique, meaning that there are no duplicated elements with the same key.
IDataMap wraps an IData instance with a Map interface. It does not provide an alternative implementation of the underlying data structure for IData. IDataMap performs the same way as the legacy IData family.
You should use either IDataMap on an IData or the legacy IData family, but not both, since there are potential issues with concurrent modification via both the IDataMap and IData classes. For performance reasons, IDataMap caches values as it looks them up from IData. As with the IData family, IDataMap does not guarantee thread safety.
As a result of implementing the Map interface, an IDataMap can have its keys and values iterated over using the for-each construct, as in the example above.
Modifier and Type | Class and Description |
---|---|
class |
IDataMap.IDataMapEntry
A name/value pair of entries for an IData instance.
|
Constructor and Description |
---|
IDataMap()
Creates a map wrapping a newly-constructed IData.
|
IDataMap(IData data)
Creates a map wrapping the given IData.
|
IDataMap(java.util.Map<? extends java.lang.String,? extends java.lang.Object> other)
Creates a map wrapping a newly-constructed IData from the given map.
|
IDataMap(java.lang.Object[][] data)
Constructs an IData from data, an array of Object
arrays, and creates a map wrapping it.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all elements from the IData object.
|
java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> |
entrySet()
Returns a set of entries for this map.
|
java.lang.Object |
get(java.lang.Object key)
Returns the value for the given key, or null if there is none.
|
java.lang.Boolean |
getAsBoolean(java.lang.Object key)
Returns the value as a boolean, if the value exists and can be converted
to a boolean.
|
java.lang.Boolean |
getAsBoolean(java.lang.Object key,
java.lang.Boolean defVal)
Returns the value as a boolean, if the value exists and can be converted
to a boolean.
|
IData |
getAsIData(java.lang.Object key)
Returns the value as an IData object, or null if not found.
|
IData |
getAsIData(java.lang.Object key,
IData defVal)
Returns the value as an IData, or defVal if not found.
|
IData[] |
getAsIDataArray(java.lang.Object key)
Returns the value as an IData array, or null if not found.
|
IData[] |
getAsIDataArray(java.lang.Object key,
IData[] defVal)
Returns the value as an IData array, or defVal if not found.
|
IDataMap |
getAsIDataMap(java.lang.Object key)
Returns the element for the given key, wrapping it in an IDataMap, if the
element is an IData instance.
|
IDataMap |
getAsIDataMap(java.lang.Object key,
IDataMap devVal)
Returns the element for the given key, wrapping it in an IDataMap, if the
element is an IData instance.
|
java.lang.Integer |
getAsInteger(java.lang.Object key)
Returns the value as an integer, if the value exists and can be converted
to an integer.
|
java.lang.Integer |
getAsInteger(java.lang.Object key,
java.lang.Integer defVal)
Returns the value as an integer, if the value exists and can be converted
to an integer.
|
java.lang.Long |
getAsLong(java.lang.Object key)
Returns the value as a long, if the value exists and can be converted
to an integer.
|
java.lang.Long |
getAsLong(java.lang.Object key,
java.lang.Long defVal)
Returns the value as a long, if the value exists and can be converted
to a long.
|
java.lang.String |
getAsNonEmptyString(java.lang.Object key)
Returns the value as a String, converting via toString
unless the value is a String.
|
java.lang.String |
getAsNonEmptyString(java.lang.Object key,
java.lang.String defVal)
Returns the value as a String, converting via toString
unless the value is a String.
|
java.lang.String |
getAsString(java.lang.Object key)
Returns the value as a String, converting via toString
unless the value is a String.
|
java.lang.String |
getAsString(java.lang.Object key,
java.lang.String defVal)
Returns the value as a String, converting via toString
unless the value is a String.
|
java.lang.String[] |
getAsStringArray(java.lang.Object key)
Returns the value as a String array, or null if not found.
|
java.lang.String[] |
getAsStringArray(java.lang.Object key,
java.lang.String[] defVal)
Returns the value as a String array, or defVal if not found.
|
IData |
getIData()
Returns the IData that this object wraps.
|
java.lang.Object |
getNested(java.lang.Object... keys)
Returns a value within an arbitrarily deep nesting of IData objects.
|
java.lang.Object |
put(java.lang.String key,
java.lang.Object value)
Sets the value for the given key, and returns the previous value or null
if none.
|
java.lang.Object |
remove(java.lang.Object key)
Removes the IData entry for the given key.
|
public IDataMap(IData data)
data
- The IData instance to be wrapped by this IDataMap. If null, a
new IData will be created, and is accessible via the
getIData method.public IDataMap()
public IDataMap(java.lang.Object[][] data)
data
- The data from which to populate this IDataMap.public IDataMap(java.util.Map<? extends java.lang.String,? extends java.lang.Object> other)
other
- The map from which to populate this IDataMap.public IData getIData()
public java.lang.Object get(java.lang.Object key)
get
in interface java.util.Map<java.lang.String,java.lang.Object>
get
in class java.util.AbstractMap<java.lang.String,java.lang.Object>
key
- The key with which to find the associated value.public java.lang.Boolean getAsBoolean(java.lang.Object key)
key
- The key with which to find the associated value.public java.lang.Boolean getAsBoolean(java.lang.Object key, java.lang.Boolean defVal)
key
- The key with which to find the associated value.public IData getAsIData(java.lang.Object key)
key
- The key with which to find the associated value.public IData getAsIData(java.lang.Object key, IData defVal)
key
- The key with which to find the associated value.public IData[] getAsIDataArray(java.lang.Object key)
key
- The key with which to find the associated value.public IData[] getAsIDataArray(java.lang.Object key, IData[] defVal)
key
- The key with which to find the associated value.public java.lang.Integer getAsInteger(java.lang.Object key)
key
- The key with which to find the associated value.public java.lang.Integer getAsInteger(java.lang.Object key, java.lang.Integer defVal)
key
- The key with which to find the associated value.public java.lang.Long getAsLong(java.lang.Object key, java.lang.Long defVal)
key
- The key with which to find the associated value.public java.lang.Long getAsLong(java.lang.Object key)
key
- The key with which to find the associated value.public java.lang.String getAsString(java.lang.Object key)
key
- The key with which to find the associated value.public java.lang.String getAsString(java.lang.Object key, java.lang.String defVal)
key
- The key with which to find the associated value.public java.lang.String getAsNonEmptyString(java.lang.Object key)
key
- The key with which to find the associated value.public java.lang.String getAsNonEmptyString(java.lang.Object key, java.lang.String defVal)
key
- The key with which to find the associated value.public java.lang.String[] getAsStringArray(java.lang.Object key)
key
- The key with which to find the associated value.public java.lang.String[] getAsStringArray(java.lang.Object key, java.lang.String[] defVal)
key
- The key with which to find the associated value.public IDataMap getAsIDataMap(java.lang.Object key)
key
- The key with which to find the associated value.public IDataMap getAsIDataMap(java.lang.Object key, IDataMap devVal)
key
- The key with which to find the associated value.public java.lang.Object getNested(java.lang.Object... keys)
keys
- The keys with which to find the associated value.public java.lang.Object put(java.lang.String key, java.lang.Object value)
put
in interface java.util.Map<java.lang.String,java.lang.Object>
put
in class java.util.AbstractMap<java.lang.String,java.lang.Object>
key
- The key for which the value will be associated.public java.lang.Object remove(java.lang.Object key)
remove
in interface java.util.Map<java.lang.String,java.lang.Object>
remove
in class java.util.AbstractMap<java.lang.String,java.lang.Object>
key
- The key for which the entry will be removed.public void clear()
clear
in interface java.util.Map<java.lang.String,java.lang.Object>
clear
in class java.util.AbstractMap<java.lang.String,java.lang.Object>
public java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> entrySet()
entrySet
in interface java.util.Map<java.lang.String,java.lang.Object>
entrySet
in class java.util.AbstractMap<java.lang.String,java.lang.Object>