public class BeanMap extends AbstractMap<String,Object> implements Cloneable
If an exception occurs during attempts to get or set a property then the property is considered non existent in the Map
Modifier and Type | Class and Description |
---|---|
protected static class |
BeanMap.MyMapEntry
Map entry used by
BeanMap . |
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Constructor and Description |
---|
BeanMap()
Constructs a new empty
BeanMap . |
BeanMap(Object bean)
Constructs a new
BeanMap that operates on the
specified bean. |
Modifier and Type | Method and Description |
---|---|
void |
clear()
This method reinitializes the bean map to have default values for the
bean's properties.
|
Object |
clone()
Clone this bean map using the following process:
|
boolean |
containsKey(String name)
Returns true if the bean defines a property with the given name.
|
protected Object |
convertType(Class<?> newType,
Object value)
Converts the given value to the given type.
|
protected Object[] |
createWriteMethodArguments(Method method,
Object value)
Creates an array of parameters to pass to the given mutator method.
|
Iterator<Map.Entry<String,Object>> |
entryIterator()
Convenience method for getting an iterator over the entries.
|
Set<Map.Entry<String,Object>> |
entrySet()
Gets a Set of MapEntry objects that are the mappings for this BeanMap.
|
protected void |
firePropertyChange(String key,
Object oldValue,
Object newValue)
Called during a successful
AbstractMap.put(Object,Object) operation. |
Object |
get(String name)
Returns the value of the bean's property with the given name.
|
Object |
getBean()
Returns the bean currently being operated on.
|
Method |
getReadMethod(String name)
Returns the accessor for the property with the given name.
|
Class<?> |
getType(String name)
Returns the type of the property with the given name.
|
protected com.google.common.base.Function<?,?> |
getTypeFunction(Class<?> aType)
Returns a transformer for the given primitive type.
|
Method |
getWriteMethod(String name)
Returns the mutator for the property with the given name.
|
Iterator<String> |
keyIterator()
Convenience method for getting an iterator over the keys.
|
Set<String> |
keySet()
Get the keys for this BeanMap.
|
Object |
put(String name,
Object value)
Sets the bean property with the given name to the given value.
|
void |
putAllWriteable(BeanMap map)
Puts all of the writable properties from the given BeanMap into this
BeanMap.
|
protected void |
reinitialise()
Reinitializes this bean.
|
void |
setBean(Object newBean)
Sets the bean to be operated on by this map.
|
int |
size()
Returns the number of properties defined by the bean.
|
String |
toString() |
Iterator<Object> |
valueIterator()
Convenience method for getting an iterator over the values.
|
Collection<Object> |
values()
Returns the values for the BeanMap.
|
containsKey, containsValue, equals, get, hashCode, isEmpty, putAll, remove
finalize, getClass, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
public BeanMap()
BeanMap
.public BeanMap(Object bean)
BeanMap
that operates on the
specified bean. If the given bean is null
, then
this map will be empty.bean
- the bean for this map to operate onpublic String toString()
toString
in class AbstractMap<String,Object>
public Object clone() throws CloneNotSupportedException
clone
in class AbstractMap<String,Object>
CloneNotSupportedException
public void putAllWriteable(BeanMap map)
map
- the BeanMap whose properties to putpublic void clear()
clear()
differs from the Map contract in that
the mappings are not actually removed from the map (the mappings for a
BeanMap are fixed).public boolean containsKey(String name)
The given name must be a String
; if not, this method
returns false. This method will also return false if the bean
does not define a property with that name.
Write-only properties will not be matched as the test operates against property read methods.
name
- the name of the property to checkString
;
false if the bean does not define a property with that name; or
true if the bean does define a property with that namepublic Object get(String name)
The given name must be a String
and must not be
null; otherwise, this method returns null
.
If the bean defines a property with the given name, the value of
that property is returned. Otherwise, null
is
returned.
Write-only properties will not be matched as the test operates against property read methods.
name
- the name of the property whose value to returnpublic Object put(String name, Object value)
public int size()
public Set<String> keySet()
Write-only properties are not included in the returned set of property names, although it is possible to set their value and to get their type.
public Set<Map.Entry<String,Object>> entrySet()
Each MapEntry can be set but not removed.
public Collection<Object> values()
public Class<?> getType(String name)
name
- the name of the propertynull
if no such
property existspublic Iterator<String> keyIterator()
Write-only properties will not be returned in the iterator.
public Iterator<Object> valueIterator()
public Iterator<Map.Entry<String,Object>> entryIterator()
public Object getBean()
public void setBean(Object newBean)
newBean
- the new bean to operate onpublic Method getReadMethod(String name)
name
- the name of the propertypublic Method getWriteMethod(String name)
name
- the name of the propertyprotected void reinitialise()
setBean(Object)
.
Does introspection to find properties.protected void firePropertyChange(String key, Object oldValue, Object newValue)
AbstractMap.put(Object,Object)
operation.
Default implementation does nothing. Override to be notified of
property changes in the bean caused by this map.key
- the name of the property that changedoldValue
- the old value for that propertynewValue
- the new value for that propertyprotected Object[] createWriteMethodArguments(Method method, Object value) throws IllegalAccessException
convertType(Class,Object)
.method
- the mutator methodvalue
- the value to pass to the mutator methodIllegalAccessException
- if convertType(Class,Object)
raises itIllegalArgumentException
- if any other exception is raised
by convertType(Class,Object)
protected Object convertType(Class<?> newType, Object value) throws InstantiationException, IllegalAccessException, InvocationTargetException
If no such constructor exists, and the given type is a primitive
type, then the given value is converted to a string using its
toString()
method, and that string is
parsed into the correct primitive type using, for instance,
Integer.valueOf(String)
to convert the string into an
int
.
If no special constructor exists and the given type is not a primitive type, this method returns the original value.
newType
- the type to convert the value tovalue
- the value to convertNumberFormatException
- if newType is a primitive type, and
the string representation of the given value cannot be converted
to that typeInstantiationException
- if the constructor found with
reflection raises itInvocationTargetException
- if the constructor found with
reflection raises itIllegalAccessException
- neverprotected com.google.common.base.Function<?,?> getTypeFunction(Class<?> aType)
aType
- the primitive type whose transformer to returnCopyright © 2007–2016 Querydsl. All rights reserved.