|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.binding.collection.MapAccessor
public class MapAccessor
A simple, generic decorator for getting attributes out of a map. May be instantiated directly or used as a base class as a convenience.
Constructor Summary | |
---|---|
MapAccessor(Map map)
Creates a new attribute map accessor. |
Method Summary | |
---|---|
Map |
asMap()
Returns this object's contents as a Map . |
void |
assertContainsKey(Object key)
Asserts that the attribute is present in the attribute map. |
Object |
assertKeyValueInstanceOf(Object key,
Object value,
Class requiredType)
Assert that the key value, if non null, is an instance of the required type. |
Object |
assertKeyValueOfType(Object key,
Class requiredType)
Assert that value of the map key, if non-null, is of the required type. |
boolean |
containsKey(Object key,
Class requiredType)
Indicates if the attribute is present in the attribute map and of the required type. |
Object |
get(Object key)
Returns a value in the map, returning null if the attribute is not present. |
Object |
get(Object key,
Class requiredType)
Returns a value in the map, asserting it is of the required type if present and returning null if
not found. |
Object |
get(Object key,
Class requiredType,
Object defaultValue)
Returns a value in the map of the specified type, returning the defaultValue if no value is found. |
Object |
get(Object key,
Object defaultValue)
Returns a value in the map, returning the defaultValue if no value was found. |
Object[] |
getArray(Object key,
Class requiredType)
Returns a array value in the map, asserting it is of the required type if present and returning null
if not found. |
Boolean |
getBoolean(Object key)
Returns a boolean value in the map, returning null if no value was found. |
Boolean |
getBoolean(Object key,
Boolean defaultValue)
Returns a boolean value in the map, returning the defaultValue if no value was found. |
Collection |
getCollection(Object key)
Returns a collection value in the map, returning null if no value was found. |
Collection |
getCollection(Object key,
Class requiredType)
Returns a collection value in the map, asserting it is of the required type if present and returning null if not found. |
Integer |
getInteger(Object key)
Returns an integer value in the map, returning null if no value was found. |
Integer |
getInteger(Object key,
Integer defaultValue)
Returns an integer value in the map, returning the defaultValue if no value was found. |
Long |
getLong(Object key)
Returns a long value in the map, returning null if no value was found. |
Long |
getLong(Object key,
Long defaultValue)
Returns a long value in the map, returning the defaultValue if no value was found. |
Number |
getNumber(Object key,
Class requiredType)
Returns a number value in the map that is of the specified type, returning null if no value was
found. |
Number |
getNumber(Object key,
Class requiredType,
Number defaultValue)
Returns a number attribute value in the map of the specified type, returning the defaultValue if no value was found. |
Object |
getRequired(Object key)
Returns a value in the map, throwing an exception if the attribute is not present and of the correct type. |
Object |
getRequired(Object key,
Class requiredType)
Returns an value in the map, asserting it is present and of the required type. |
Object[] |
getRequiredArray(Object key,
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. |
Boolean |
getRequiredBoolean(Object key)
Returns a boolean value in the map, throwing an exception if the value is not present and of the correct type. |
Collection |
getRequiredCollection(Object key)
Returns a collection value in the map, throwing an exception if not found. |
Collection |
getRequiredCollection(Object key,
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. |
Integer |
getRequiredInteger(Object key)
Returns an integer value in the map, throwing an exception if the value is not present and of the correct type. |
Long |
getRequiredLong(Object key)
Returns a long value in the map, throwing an exception if the value is not present and of the correct type. |
Number |
getRequiredNumber(Object key,
Class requiredType)
Returns a number value in the map, throwing an exception if the attribute is not present and of the correct type. |
String |
getRequiredString(Object key)
Returns a string value in the map, throwing an exception if the attribute is not present and of the correct type. |
String |
getString(Object key)
Returns a string value in the map, returning null if no value was found. |
String |
getString(Object key,
String defaultValue)
Returns a string value in the map, returning the defaultValue if no value was found. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MapAccessor(Map map)
map
- the mapMethod Detail |
---|
public 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 Object get(Object key)
key
- the key
public Object get(Object key, Object defaultValue)
key
- the keydefaultValue
- the default
public Object get(Object key, Class requiredType) throws IllegalArgumentException
null
if
not found.
key
- the keyrequiredType
- the required type
IllegalArgumentException
- if the key is present but the value is not of the required typepublic Object get(Object key, Class requiredType, Object defaultValue)
key
- the keyrequiredType
- the required typedefaultValue
- the default
IllegalArgumentException
- if the key is present but the value is not of the required typepublic Object getRequired(Object key) throws IllegalArgumentException
key
- the key
IllegalArgumentException
public Object getRequired(Object key, Class requiredType) throws IllegalArgumentException
key
- the keyrequiredType
- the required type
IllegalArgumentException
public String getString(Object key) throws IllegalArgumentException
null
if no value was found.
key
- the key
IllegalArgumentException
- if the key is present but the value is not a stringpublic String getString(Object key, String defaultValue) throws IllegalArgumentException
key
- the keydefaultValue
- the default
IllegalArgumentException
- if the key is present but the value is not a stringpublic String getRequiredString(Object key) throws IllegalArgumentException
key
- the key
IllegalArgumentException
- if the key is not present or present but the value is not a stringpublic Collection getCollection(Object key) throws IllegalArgumentException
null
if no value was found.
key
- the key
IllegalArgumentException
- if the key is present but the value is not a collectionpublic Collection getCollection(Object key, Class requiredType) throws IllegalArgumentException
null
if not found.
key
- the key
IllegalArgumentException
- if the key is present but the value is not a collectionpublic Collection getRequiredCollection(Object key) throws IllegalArgumentException
key
- the key
IllegalArgumentException
- if the key is not present or present but the value is not a collectionpublic Collection getRequiredCollection(Object key, Class requiredType) throws IllegalArgumentException
key
- the key
IllegalArgumentException
- if the key is not present or present but the value is not a collection of the
required typepublic Object[] getArray(Object key, Class requiredType) throws IllegalArgumentException
null
if not found.
key
- the key
IllegalArgumentException
- if the key is present but the value is not an array of the required typepublic Object[] getRequiredArray(Object key, Class requiredType) throws IllegalArgumentException
key
- the key
IllegalArgumentException
- if the key is not present or present but the value is not a array of the
required typepublic Number getNumber(Object key, Class requiredType) throws IllegalArgumentException
null
if no value was
found.
key
- the keyrequiredType
- the required number type
IllegalArgumentException
- if the key is present but the value is not a number of the required typepublic Number getNumber(Object key, Class requiredType, Number defaultValue) throws IllegalArgumentException
key
- the attribute namedefaultValue
- the default
IllegalArgumentException
- if the key is present but the value is not a number of the required typepublic Number getRequiredNumber(Object key, Class requiredType) throws IllegalArgumentException
key
- the key
IllegalArgumentException
- if the key is not present or present but the value is not a number of the
required typepublic Integer getInteger(Object key) throws IllegalArgumentException
null
if no value was found.
key
- the key
IllegalArgumentException
- if the key is present but the value is not an integerpublic Integer getInteger(Object key, Integer defaultValue) throws IllegalArgumentException
key
- the keydefaultValue
- the default
IllegalArgumentException
- if the key is present but the value is not an integerpublic Integer getRequiredInteger(Object key) throws IllegalArgumentException
key
- the attribute name
IllegalArgumentException
- if the key is not present or present but the value is not an integerpublic Long getLong(Object key) throws IllegalArgumentException
null
if no value was found.
key
- the key
IllegalArgumentException
- if the key is present but not a longpublic Long getLong(Object key, Long defaultValue) throws IllegalArgumentException
key
- the keydefaultValue
- the default
IllegalArgumentException
- if the key is present but the value is not a longpublic Long getRequiredLong(Object key) throws IllegalArgumentException
key
- the key
IllegalArgumentException
- if the key is not present or present but the value is not a longpublic Boolean getBoolean(Object key) throws IllegalArgumentException
null
if no value was found.
key
- the key
IllegalArgumentException
- if the key is present but the value is not a booleanpublic Boolean getBoolean(Object key, Boolean defaultValue) throws IllegalArgumentException
key
- the keydefaultValue
- the default
IllegalArgumentException
- if the key is present but the value is not a booleanpublic Boolean getRequiredBoolean(Object key) throws IllegalArgumentException
key
- the attribute
IllegalArgumentException
- if the key is not present or present but the value is not a booleanpublic void assertContainsKey(Object key) throws IllegalArgumentException
key
- the key
IllegalArgumentException
- if the key is not presentpublic boolean containsKey(Object key, Class requiredType) throws IllegalArgumentException
key
- the attribute name
IllegalArgumentException
public Object assertKeyValueOfType(Object key, Class requiredType)
key
- the attribute namerequiredType
- the required attribute value type
public Object assertKeyValueInstanceOf(Object key, Object value, Class requiredType)
key
- the keyvalue
- the valuerequiredType
- the required type
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |