|
|||||||||
| Home >> All >> com >> mjh >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
com.mjh.util
Class BeanMap

java.lang.Objectcom.mjh.util.BeanMap
- All Implemented Interfaces:
- java.util.Map
- public class BeanMap
- extends java.lang.Object
- implements java.util.Map
- extends java.lang.Object
BeanMap provides an adaptor for Java Beans to allow them to be treated as a java.util.Map.
BeanMap is pretty good at coercing string values into the appropriate primitive type for a bean setter method argument.
For example:
MyBean myBean = new MyBean();
BeanMap myMap = new BeamMap(myBean);
myMap.put("totalCount", "100");
Number value = (Number)myMap.get("totalCount");
The above code will call the setTotalCount() method on myBean with the string value of "100"
coerced to the required integer argument. Then call the getTotalCount() method on myBean and convert
the int return value to the Java primitive wrapper class.
The coercion makes BeanMap particularly useful to initialize beans from values stored in text files.
| Nested Class Summary | |
class |
BeanMap.BeanMapEntry
|
| Nested classes inherited from class java.util.Map |
java.util.Map.Entry |
| Field Summary | |
private java.lang.Object |
bean
|
private java.beans.BeanInfo |
info
|
private static org.apache.log4j.Logger |
log
|
private java.util.Map |
pdMap
|
| Constructor Summary | |
BeanMap(java.lang.Object object)
|
|
| Method Summary | |
void |
clear()
Remove all entries from this Map (optional operation). |
private java.lang.Object |
coerceValue(java.lang.Object value,
java.lang.Class targetClazz)
|
boolean |
containsKey(java.lang.Object key)
Returns true if this contains a mapping for the given key. |
boolean |
containsValue(java.lang.Object o)
Returns true if this contains at least one mapping with the given value. |
java.util.Set |
entrySet()
Returns a set view of the mappings in this Map. |
boolean |
equals(java.lang.Object o)
Compares the specified object with this map for equality. |
java.lang.Object |
get(java.lang.Object key)
Returns the value mapped by the given key. |
java.util.Map |
getAll()
|
private java.beans.PropertyDescriptor |
getPropertyDescriptor(java.lang.String key)
|
boolean |
isEmpty()
Returns true if the map contains no mappings. |
java.util.Set |
keySet()
Returns a set view of the keys in this Map. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Associates the given key to the given value (optional operation). |
void |
putAll(java.util.Map map)
Copies all entries of the given map to this one (optional operation). |
java.lang.Object |
remove(java.lang.Object key)
Removes the mapping for this key if present (optional operation). |
int |
size()
Returns the number of key-value mappings in the map. |
java.util.Collection |
values()
Returns a collection (or bag) view of the values in this Map. |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface java.util.Map |
hashCode |
| Field Detail |
log
private static final org.apache.log4j.Logger log
bean
private java.lang.Object bean
info
private java.beans.BeanInfo info
pdMap
private java.util.Map pdMap
| Constructor Detail |
BeanMap
public BeanMap(java.lang.Object object) throws java.beans.IntrospectionException
| Method Detail |
getPropertyDescriptor
private java.beans.PropertyDescriptor getPropertyDescriptor(java.lang.String key)
put
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
- Description copied from interface:
java.util.Map - Associates the given key to the given value (optional operation). If the
map already contains the key, its value is replaced. Be aware that in
a map that permits
nullvalues, a null return does not always imply that the mapping was created.- Specified by:
putin interfacejava.util.Map
get
public java.lang.Object get(java.lang.Object key)
- Description copied from interface:
java.util.Map - Returns the value mapped by the given key. Returns
nullif there is no mapping. However, in Maps that accept null values, you must rely oncontainsKeyto determine if a mapping exists.- Specified by:
getin interfacejava.util.Map
containsKey
public boolean containsKey(java.lang.Object key)
- Description copied from interface:
java.util.Map - Returns true if this contains a mapping for the given key.
- Specified by:
containsKeyin interfacejava.util.Map
containsValue
public boolean containsValue(java.lang.Object o)
- Description copied from interface:
java.util.Map - Returns true if this contains at least one mapping with the given value.
In other words, returns true if a value v exists where
(value == null ? v == null : value.equals(v)). This usually requires linear time.- Specified by:
containsValuein interfacejava.util.Map
clear
public void clear()
- Description copied from interface:
java.util.Map - Remove all entries from this Map (optional operation).
- Specified by:
clearin interfacejava.util.Map
remove
public java.lang.Object remove(java.lang.Object key)
- Description copied from interface:
java.util.Map - Removes the mapping for this key if present (optional operation). If
the key is not present, this returns null. Note that maps which permit
null values may also return null if the key was removed.
- Specified by:
removein interfacejava.util.Map
values
public java.util.Collection values()
- Description copied from interface:
java.util.Map - Returns a collection (or bag) view of the values in this Map. The
collection is backed by the map, so that changes in one show up in
the other. Modifications made while an iterator is in progress cause
undefined behavior. If the collection supports removal, these methods
remove the underlying mapping from the map:
Iterator.remove,Collection.remove,removeAll,retainAll, andclear. Element addition, viaaddoraddAll, is not supported via this collection.- Specified by:
valuesin interfacejava.util.Map
keySet
public java.util.Set keySet()
- Description copied from interface:
java.util.Map - Returns a set view of the keys in this Map. The set is backed by the
map, so that changes in one show up in the other. Modifications made
while an iterator is in progress cause undefined behavior. If the set
supports removal, these methods remove the underlying mapping from
the map:
Iterator.remove,Set.remove,removeAll,retainAll, andclear. Element addition, viaaddoraddAll, is not supported via this set.- Specified by:
keySetin interfacejava.util.Map
entrySet
public java.util.Set entrySet()
- Description copied from interface:
java.util.Map - Returns a set view of the mappings in this Map. Each element in the
set is a Map.Entry. The set is backed by the map, so that changes in
one show up in the other. Modifications made while an iterator is
in progress cause undefined behavior. If the set supports removal,
these methods remove the underlying mapping from the map:
Iterator.remove,Set.remove,removeAll,retainAll, andclear. Element addition, viaaddoraddAll, is not supported via this set.- Specified by:
entrySetin interfacejava.util.Map
equals
public boolean equals(java.lang.Object o)
- Description copied from interface:
java.util.Map - Compares the specified object with this map for equality. Returns
trueif the other object is a Map with the same mappings, that is,
o instanceof Map && entrySet().equals(((Map) o).entrySet();This allows comparison of maps, regardless of implementation.- Specified by:
equalsin interfacejava.util.Map
size
public int size()
- Description copied from interface:
java.util.Map - Returns the number of key-value mappings in the map. If there are more
than Integer.MAX_VALUE mappings, return Integer.MAX_VALUE.
- Specified by:
sizein interfacejava.util.Map
getAll
public java.util.Map getAll()
putAll
public void putAll(java.util.Map map)
- Description copied from interface:
java.util.Map - Copies all entries of the given map to this one (optional operation). If
the map already contains a key, its value is replaced.
- Specified by:
putAllin interfacejava.util.Map
isEmpty
public boolean isEmpty()
- Description copied from interface:
java.util.Map - Returns true if the map contains no mappings.
- Specified by:
isEmptyin interfacejava.util.Map
coerceValue
private java.lang.Object coerceValue(java.lang.Object value, java.lang.Class targetClazz)
|
|||||||||
| Home >> All >> com >> mjh >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
com.mjh.util.BeanMap