public class MapAccessor extends java.lang.Object implements MapAdaptable
Constructor and Description |
---|
MapAccessor(java.util.Map map)
Creates a new attribute map accessor.
|
Modifier and Type | Method and Description |
---|---|
java.util.Map |
asMap()
Returns this object's contents as a
Map . |
void |
assertContainsKey(java.lang.Object key)
Asserts that the attribute is present in the attribute map.
|
java.lang.Object |
assertKeyValueInstanceOf(java.lang.Object key,
java.lang.Object value,
java.lang.Class requiredType)
Assert that the key value, if non null, is an instance of the required type.
|
java.lang.Object |
assertKeyValueOfType(java.lang.Object key,
java.lang.Class requiredType)
Assert that value of the map key, if non-null, is of the required type.
|
boolean |
containsKey(java.lang.Object key,
java.lang.Class requiredType)
Indicates if the attribute is present in the attribute map and of the required type.
|
java.lang.Object |
get(java.lang.Object key)
Returns a value in the map, returning null if the attribute is not present.
|
java.lang.Object |
get(java.lang.Object key,
java.lang.Class requiredType)
Returns a value in the map, asserting it is of the required type if present and returning
null if
not found. |
java.lang.Object |
get(java.lang.Object key,
java.lang.Class requiredType,
java.lang.Object defaultValue)
Returns a value in the map of the specified type, returning the defaultValue if no value is found.
|
java.lang.Object |
get(java.lang.Object key,
java.lang.Object defaultValue)
Returns a value in the map, returning the defaultValue if no value was found.
|
java.lang.Object[] |
getArray(java.lang.Object key,
java.lang.Class requiredType)
Returns a array value in the map, asserting it is of the required type if present and returning
null
if not found. |
java.lang.Boolean |
getBoolean(java.lang.Object key)
Returns a boolean value in the map, returning
null if no value was found. |
java.lang.Boolean |
getBoolean(java.lang.Object key,
java.lang.Boolean defaultValue)
Returns a boolean value in the map, returning the defaultValue if no value was found.
|
java.util.Collection |
getCollection(java.lang.Object key)
Returns a collection value in the map, returning
null if no value was found. |
java.util.Collection |
getCollection(java.lang.Object key,
java.lang.Class requiredType)
Returns a collection value in the map, asserting it is of the required type if present and returning
null if not found. |
java.lang.Integer |
getInteger(java.lang.Object key)
Returns an integer value in the map, returning
null if no value was found. |
java.lang.Integer |
getInteger(java.lang.Object key,
java.lang.Integer defaultValue)
Returns an integer value in the map, returning the defaultValue if no value was found.
|
java.lang.Long |
getLong(java.lang.Object key)
Returns a long value in the map, returning
null if no value was found. |
java.lang.Long |
getLong(java.lang.Object key,
java.lang.Long defaultValue)
Returns a long value in the map, returning the defaultValue if no value was found.
|
java.lang.Number |
getNumber(java.lang.Object key,
java.lang.Class requiredType)
Returns a number value in the map that is of the specified type, returning
null if no value was
found. |
java.lang.Number |
getNumber(java.lang.Object key,
java.lang.Class requiredType,
java.lang.Number defaultValue)
Returns a number attribute value in the map of the specified type, returning the defaultValue if no value was
found.
|
java.lang.Object |
getRequired(java.lang.Object key)
Returns a value in the map, throwing an exception if the attribute is not present and of the correct type.
|
java.lang.Object |
getRequired(java.lang.Object key,
java.lang.Class requiredType)
Returns an value in the map, asserting it is present and of the required type.
|
java.lang.Object[] |
getRequiredArray(java.lang.Object key,
java.lang.Class requiredType)
Returns an array value in the map, asserting it is of the required type if present and throwing an exception if
not found.
|
java.lang.Boolean |
getRequiredBoolean(java.lang.Object key)
Returns a boolean value in the map, throwing an exception if the value is not present and of the correct type.
|
java.util.Collection |
getRequiredCollection(java.lang.Object key)
Returns a collection value in the map, throwing an exception if not found.
|
java.util.Collection |
getRequiredCollection(java.lang.Object key,
java.lang.Class requiredType)
Returns a collection value in the map, asserting it is of the required type if present and throwing an exception
if not found.
|
java.lang.Integer |
getRequiredInteger(java.lang.Object key)
Returns an integer value in the map, throwing an exception if the value is not present and of the correct type.
|
java.lang.Long |
getRequiredLong(java.lang.Object key)
Returns a long value in the map, throwing an exception if the value is not present and of the correct type.
|
java.lang.Number |
getRequiredNumber(java.lang.Object key,
java.lang.Class requiredType)
Returns a number value in the map, throwing an exception if the attribute is not present and of the correct type.
|
java.lang.String |
getRequiredString(java.lang.Object key)
Returns a string value in the map, throwing an exception if the attribute is not present and of the correct type.
|
java.lang.String |
getString(java.lang.Object key)
Returns a string value in the map, returning
null if no value was found. |
java.lang.String |
getString(java.lang.Object key,
java.lang.String defaultValue)
Returns a string value in the map, returning the defaultValue if no value was found.
|
public MapAccessor(java.util.Map map)
map
- the mappublic java.util.Map asMap()
MapAdaptable
Map
. The returned map may or may not be modifiable depending on this
implementation.
Warning: this operation may be called frequently; if so care should be taken so that the map contents (if calculated) be cached as appropriate.
asMap
in interface MapAdaptable
public java.lang.Object get(java.lang.Object key)
key
- the keypublic java.lang.Object get(java.lang.Object key, java.lang.Object defaultValue)
key
- the keydefaultValue
- the defaultpublic java.lang.Object get(java.lang.Object key, java.lang.Class requiredType) throws java.lang.IllegalArgumentException
null
if
not found.key
- the keyrequiredType
- the required typejava.lang.IllegalArgumentException
- if the key is present but the value is not of the required typepublic java.lang.Object get(java.lang.Object key, java.lang.Class requiredType, java.lang.Object defaultValue)
key
- the keyrequiredType
- the required typedefaultValue
- the defaultjava.lang.IllegalArgumentException
- if the key is present but the value is not of the required typepublic java.lang.Object getRequired(java.lang.Object key) throws java.lang.IllegalArgumentException
key
- the keyjava.lang.IllegalArgumentException
public java.lang.Object getRequired(java.lang.Object key, java.lang.Class requiredType) throws java.lang.IllegalArgumentException
key
- the keyrequiredType
- the required typejava.lang.IllegalArgumentException
public java.lang.String getString(java.lang.Object key) throws java.lang.IllegalArgumentException
null
if no value was found.key
- the keyjava.lang.IllegalArgumentException
- if the key is present but the value is not a stringpublic java.lang.String getString(java.lang.Object key, java.lang.String defaultValue) throws java.lang.IllegalArgumentException
key
- the keydefaultValue
- the defaultjava.lang.IllegalArgumentException
- if the key is present but the value is not a stringpublic java.lang.String getRequiredString(java.lang.Object key) throws java.lang.IllegalArgumentException
key
- the keyjava.lang.IllegalArgumentException
- if the key is not present or present but the value is not a stringpublic java.util.Collection getCollection(java.lang.Object key) throws java.lang.IllegalArgumentException
null
if no value was found.key
- the keyjava.lang.IllegalArgumentException
- if the key is present but the value is not a collectionpublic java.util.Collection getCollection(java.lang.Object key, java.lang.Class requiredType) throws java.lang.IllegalArgumentException
null
if not found.key
- the keyjava.lang.IllegalArgumentException
- if the key is present but the value is not a collectionpublic java.util.Collection getRequiredCollection(java.lang.Object key) throws java.lang.IllegalArgumentException
key
- the keyjava.lang.IllegalArgumentException
- if the key is not present or present but the value is not a collectionpublic java.util.Collection getRequiredCollection(java.lang.Object key, java.lang.Class requiredType) throws java.lang.IllegalArgumentException
key
- the keyjava.lang.IllegalArgumentException
- if the key is not present or present but the value is not a collection of the
required typepublic java.lang.Object[] getArray(java.lang.Object key, java.lang.Class requiredType) throws java.lang.IllegalArgumentException
null
if not found.key
- the keyjava.lang.IllegalArgumentException
- if the key is present but the value is not an array of the required typepublic java.lang.Object[] getRequiredArray(java.lang.Object key, java.lang.Class requiredType) throws java.lang.IllegalArgumentException
key
- the keyjava.lang.IllegalArgumentException
- if the key is not present or present but the value is not a array of the
required typepublic java.lang.Number getNumber(java.lang.Object key, java.lang.Class requiredType) throws java.lang.IllegalArgumentException
null
if no value was
found.key
- the keyrequiredType
- the required number typejava.lang.IllegalArgumentException
- if the key is present but the value is not a number of the required typepublic java.lang.Number getNumber(java.lang.Object key, java.lang.Class requiredType, java.lang.Number defaultValue) throws java.lang.IllegalArgumentException
key
- the attribute namedefaultValue
- the defaultjava.lang.IllegalArgumentException
- if the key is present but the value is not a number of the required typepublic java.lang.Number getRequiredNumber(java.lang.Object key, java.lang.Class requiredType) throws java.lang.IllegalArgumentException
key
- the keyjava.lang.IllegalArgumentException
- if the key is not present or present but the value is not a number of the
required typepublic java.lang.Integer getInteger(java.lang.Object key) throws java.lang.IllegalArgumentException
null
if no value was found.key
- the keyjava.lang.IllegalArgumentException
- if the key is present but the value is not an integerpublic java.lang.Integer getInteger(java.lang.Object key, java.lang.Integer defaultValue) throws java.lang.IllegalArgumentException
key
- the keydefaultValue
- the defaultjava.lang.IllegalArgumentException
- if the key is present but the value is not an integerpublic java.lang.Integer getRequiredInteger(java.lang.Object key) throws java.lang.IllegalArgumentException
key
- the attribute namejava.lang.IllegalArgumentException
- if the key is not present or present but the value is not an integerpublic java.lang.Long getLong(java.lang.Object key) throws java.lang.IllegalArgumentException
null
if no value was found.key
- the keyjava.lang.IllegalArgumentException
- if the key is present but not a longpublic java.lang.Long getLong(java.lang.Object key, java.lang.Long defaultValue) throws java.lang.IllegalArgumentException
key
- the keydefaultValue
- the defaultjava.lang.IllegalArgumentException
- if the key is present but the value is not a longpublic java.lang.Long getRequiredLong(java.lang.Object key) throws java.lang.IllegalArgumentException
key
- the keyjava.lang.IllegalArgumentException
- if the key is not present or present but the value is not a longpublic java.lang.Boolean getBoolean(java.lang.Object key) throws java.lang.IllegalArgumentException
null
if no value was found.key
- the keyjava.lang.IllegalArgumentException
- if the key is present but the value is not a booleanpublic java.lang.Boolean getBoolean(java.lang.Object key, java.lang.Boolean defaultValue) throws java.lang.IllegalArgumentException
key
- the keydefaultValue
- the defaultjava.lang.IllegalArgumentException
- if the key is present but the value is not a booleanpublic java.lang.Boolean getRequiredBoolean(java.lang.Object key) throws java.lang.IllegalArgumentException
key
- the attributejava.lang.IllegalArgumentException
- if the key is not present or present but the value is not a booleanpublic void assertContainsKey(java.lang.Object key) throws java.lang.IllegalArgumentException
key
- the keyjava.lang.IllegalArgumentException
- if the key is not presentpublic boolean containsKey(java.lang.Object key, java.lang.Class requiredType) throws java.lang.IllegalArgumentException
key
- the attribute namejava.lang.IllegalArgumentException
public java.lang.Object assertKeyValueOfType(java.lang.Object key, java.lang.Class requiredType)
key
- the attribute namerequiredType
- the required attribute value typepublic java.lang.Object assertKeyValueInstanceOf(java.lang.Object key, java.lang.Object value, java.lang.Class requiredType)
key
- the keyvalue
- the valuerequiredType
- the required type