com.mjh.util
Class BeanMap
java.lang.Object
|
+--com.mjh.util.BeanMap
- All Implemented Interfaces:
- java.util.Map
- public class BeanMap
- extends java.lang.Object
- implements java.util.Map
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.
- Author:
- Mike Henderson
|
Constructor Summary |
BeanMap(java.lang.Object object)
|
|
Method Summary |
void |
clear()
|
boolean |
containsKey(java.lang.Object key)
|
boolean |
containsValue(java.lang.Object o)
|
java.util.Set |
entrySet()
|
boolean |
equals(java.lang.Object o)
|
java.lang.Object |
get(java.lang.Object key)
|
java.util.Map |
getAll()
|
boolean |
isEmpty()
|
java.util.Set |
keySet()
|
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
|
void |
putAll(java.util.Map map)
|
java.lang.Object |
remove(java.lang.Object key)
|
int |
size()
|
java.util.Collection |
values()
|
| 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 |
BeanMap
public BeanMap(java.lang.Object object)
throws java.beans.IntrospectionException
put
public java.lang.Object put(java.lang.Object key,
java.lang.Object value)
- Specified by:
put in interface java.util.Map
get
public java.lang.Object get(java.lang.Object key)
- Specified by:
get in interface java.util.Map
containsKey
public boolean containsKey(java.lang.Object key)
- Specified by:
containsKey in interface java.util.Map
containsValue
public boolean containsValue(java.lang.Object o)
- Specified by:
containsValue in interface java.util.Map
clear
public void clear()
- Specified by:
clear in interface java.util.Map
remove
public java.lang.Object remove(java.lang.Object key)
- Specified by:
remove in interface java.util.Map
values
public java.util.Collection values()
- Specified by:
values in interface java.util.Map
keySet
public java.util.Set keySet()
- Specified by:
keySet in interface java.util.Map
entrySet
public java.util.Set entrySet()
- Specified by:
entrySet in interface java.util.Map
equals
public boolean equals(java.lang.Object o)
- Specified by:
equals in interface java.util.Map- Overrides:
equals in class java.lang.Object
size
public int size()
- Specified by:
size in interface java.util.Map
getAll
public java.util.Map getAll()
putAll
public void putAll(java.util.Map map)
- Specified by:
putAll in interface java.util.Map
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty in interface java.util.Map
Copyright © 2002-2002 Michael J. Henderson & Associates, LLC. All Rights Reserved.