Package net.sf.cglib.beans
Class BeanMap
- java.lang.Object
-
- net.sf.cglib.beans.BeanMap
-
- All Implemented Interfaces:
Map
public abstract class BeanMap extends Object implements Map
AMap
-based view of a JavaBean. The default set of keys is the union of all property names (getters or setters). An attempt to set a read-only property will be ignored, and write-only properties will be returned asnull
. Removal of objects is not a supported (the key set is fixed).- Author:
- Chris Nokleberg
-
-
Field Summary
Fields Modifier and Type Field Description protected Object
bean
static int
REQUIRE_GETTER
Limit the properties reflected in the key set of the map to readable properties.static int
REQUIRE_SETTER
Limit the properties reflected in the key set of the map to writable properties.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
clear()
boolean
containsKey(Object key)
boolean
containsValue(Object value)
static BeanMap
create(Object bean)
Helper method to create a newBeanMap
.Set
entrySet()
boolean
equals(Object o)
Object
get(Object key)
abstract Object
get(Object bean, Object key)
Get the property of a bean.Object
getBean()
Return the bean currently in use by this map.abstract Class
getPropertyType(String name)
Get the type of a property.int
hashCode()
boolean
isEmpty()
abstract BeanMap
newInstance(Object bean)
Create a newBeanMap
instance using the specified bean.Object
put(Object key, Object value)
abstract Object
put(Object bean, Object key, Object value)
Set the property of a bean.void
putAll(Map t)
Object
remove(Object key)
void
setBean(Object bean)
Change the underlying bean this map should use.int
size()
String
toString()
Collection
values()
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, keySet, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Field Detail
-
REQUIRE_GETTER
public static final int REQUIRE_GETTER
Limit the properties reflected in the key set of the map to readable properties.
-
REQUIRE_SETTER
public static final int REQUIRE_SETTER
Limit the properties reflected in the key set of the map to writable properties.
-
bean
protected Object bean
-
-
Constructor Detail
-
BeanMap
protected BeanMap()
-
BeanMap
protected BeanMap(Object bean)
-
-
Method Detail
-
create
public static BeanMap create(Object bean)
Helper method to create a newBeanMap
. For finer control over the generated instance, use a new instance ofBeanMap.Generator
instead of this static method.- Parameters:
bean
- the JavaBean underlying the map- Returns:
- a new
BeanMap
instance
-
newInstance
public abstract BeanMap newInstance(Object bean)
Create a newBeanMap
instance using the specified bean. This is faster than using thecreate(java.lang.Object)
static method.- Parameters:
bean
- the JavaBean underlying the map- Returns:
- a new
BeanMap
instance
-
getPropertyType
public abstract Class getPropertyType(String name)
Get the type of a property.- Parameters:
name
- the name of the JavaBean property- Returns:
- the type of the property, or null if the property does not exist
-
get
public abstract Object get(Object bean, Object key)
Get the property of a bean. This allows aBeanMap
to be used statically for multiple beans--the bean instance tied to the map is ignored and the bean passed to this method is used instead.- Parameters:
bean
- the bean to query; must be compatible with the type of thisBeanMap
key
- must be a String- Returns:
- the current value, or null if there is no matching property
-
put
public abstract Object put(Object bean, Object key, Object value)
Set the property of a bean. This allows aBeanMap
to be used statically for multiple beans--the bean instance tied to the map is ignored and the bean passed to this method is used instead.- Parameters:
key
- must be a String- Returns:
- the old value, if there was one, or null
-
setBean
public void setBean(Object bean)
Change the underlying bean this map should use.- Parameters:
bean
- the new JavaBean- See Also:
getBean()
-
getBean
public Object getBean()
Return the bean currently in use by this map.- Returns:
- the current JavaBean
- See Also:
setBean(java.lang.Object)
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKey
in interfaceMap
-
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValue
in interfaceMap
-
equals
public boolean equals(Object o)
-
hashCode
public int hashCode()
-
values
public Collection values()
-
-