Class BeanMap
If an exception occurs during attempts to get or set a property then the property is considered non existent in the Map
- 
Nested Class SummaryNested ClassesNested classes/interfaces inherited from class java.util.AbstractMapAbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> 
- 
Field SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidclear()This method reinitializes the bean map to have default values for the bean's properties.clone()Clone this bean map using the following process: If there is no underlying bean, return a cloned BeanMap without a bean.booleancontainsKey(Object name) Returns true if the bean defines a property with the given name.protected <R> ObjectconvertType(Class<R> 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.Convenience method for getting an iterator over the entries.entrySet()Gets a Set of MapEntry objects that are the mappings for this BeanMap.protected voidfirePropertyChange(Object key, Object oldValue, Object newValue) Called during a successfulput(String,Object)operation.Gets the value of the bean's property with the given name.getBean()Gets the bean currently being operated on.protected MethodgetReadMethod(Object name) Gets the accessor for the property with the given name.getReadMethod(String name) Gets the accessor for the property with the given name.Class<?> Gets the type of the property with the given name.getTypeTransformer(Class<R> type) Gets a transformer for the given primitive type.protected MethodgetWriteMethod(Object name) Gets the mutator for the property with the given name.getWriteMethod(String name) Gets the mutator for the property with the given name.Convenience method for getting an iterator over the keys.keySet()Gets the keys for this BeanMap.protected voidLogs the given exception toSystem.out.protected voidLogs the given exception toSystem.err.Sets the bean property with the given name to the given value.voidputAllWriteable(BeanMap map) Puts all of the writable properties from the given BeanMap into this BeanMap.protected voidReinitializes this bean.voidSets the bean to be operated on by this map.intsize()Returns the number of properties defined by the bean.toString()Renders a string representation of this object.Convenience method for getting an iterator over the values.values()Gets the values for the BeanMap.Methods inherited from class java.util.AbstractMapcontainsValue, equals, hashCode, isEmpty, putAll, removeMethods inherited from class java.lang.Objectfinalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Mapcompute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
- 
Field Details- 
NULL_ARGUMENTSAn empty array. Used to invoke accessors via reflection.
 
- 
- 
Constructor Details- 
BeanMappublic BeanMap()Constructs a new emptyBeanMap.
- 
BeanMapConstructs a newBeanMapthat operates on the specified bean. If the given bean isnull, then this map will be empty.- Parameters:
- bean- the bean for this map to operate on
 
 
- 
- 
Method Details- 
clearThis method reinitializes the bean map to have default values for the bean's properties. This is accomplished by constructing a new instance of the bean which the map uses as its underlying data source. This behavior forclear()differs from the Map contract in that the mappings are not actually removed from the map (the mappings for a BeanMap are fixed).
- 
cloneClone this bean map using the following process:- If there is no underlying bean, return a cloned BeanMap without a bean.
- Since there is an underlying bean, try to instantiate a new bean of the same type using Class.newInstance().
- If the instantiation fails, throw a CloneNotSupportedException
- Clone the bean map and set the newly instantiated bean as the underlying bean for the bean map.
- Copy each property that is both readable and writable from the existing object to a cloned bean map.
- If anything fails along the way, throw a CloneNotSupportedException.
 - Overrides:
- clonein class- AbstractMap<String,- Object> 
- Returns:
- a cloned instance of this bean map
- Throws:
- CloneNotSupportedException- if the underlying bean cannot be cloned
 
- 
containsKeyReturns true if the bean defines a property with the given 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. - Specified by:
- containsKeyin interface- Map<String,- Object> 
- Overrides:
- containsKeyin class- AbstractMap<String,- Object> 
- Parameters:
- name- the name of the property to check
- Returns:
- false if the given name is null or is not a String; false if the bean does not define a property with that name; or true if the bean does define a property with that name
 
- 
convertTypeprotected <R> Object convertType(Class<R> newType, Object value) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException Converts the given value to the given type. First, reflection is used to find a public constructor declared by the given class that takes one argument, which must be the precise type of the given value. If such a constructor is found, a new object is created by passing the given value to that constructor, and the newly constructed object is returned.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 anint.If no special constructor exists and the given type is not a primitive type, this method returns the original value. - Type Parameters:
- R- The return type.
- Parameters:
- newType- the type to convert the value to
- value- the value to convert
- Returns:
- the converted value
- Throws:
- NumberFormatException- if newType is a primitive type, and the string representation of the given value cannot be converted to that type
- InstantiationException- if the constructor found with reflection raises it
- InvocationTargetException- if the constructor found with reflection raises it
- IllegalAccessException- never
- IllegalArgumentException- never
 
- 
createWriteMethodArgumentsprotected Object[] createWriteMethodArguments(Method method, Object value) throws IllegalAccessException, ClassCastException Creates an array of parameters to pass to the given mutator method. If the given object is not the right type to pass to the method directly, it will be converted usingconvertType(Class,Object).- Parameters:
- method- the mutator method
- value- the value to pass to the mutator method
- Returns:
- an array containing one object that is either the given value or a transformed value
- Throws:
- IllegalAccessException- if- convertType(Class,Object)raises it
- IllegalArgumentException- if any other exception is raised by- convertType(Class,Object)
- ClassCastException- if an error occurs creating the method args
 
- 
entryIteratorConvenience method for getting an iterator over the entries.- Returns:
- an iterator over the entries
 
- 
entrySetGets a Set of MapEntry objects that are the mappings for this BeanMap.Each MapEntry can be set but not removed. 
- 
firePropertyChangeCalled during a successfulput(String,Object)operation. Default implementation does nothing. Override to be notified of property changes in the bean caused by this map.- Parameters:
- key- the name of the property that changed
- oldValue- the old value for that property
- newValue- the new value for that property
 
- 
getGets the value of the bean's property with the given name.The given name must be a Stringand must not be null; otherwise, this method returnsnull. If the bean defines a property with the given name, the value of that property is returned. Otherwise,nullis returned.Write-only properties will not be matched as the test operates against property read methods. 
- 
getBeanGets the bean currently being operated on. The return value may be null if this map is empty.- Returns:
- the bean being operated on by this map
 
- 
getReadMethodGets the accessor for the property with the given name.- Parameters:
- name- the name of the property
- Returns:
- null if the name is null; null if the name is not a String; null if no such property exists; or the accessor method for that property
 
- 
getReadMethodGets the accessor for the property with the given name.- Parameters:
- name- the name of the property
- Returns:
- the accessor method for the property, or null
 
- 
getTypeGets the type of the property with the given name.- Parameters:
- name- the name of the property
- Returns:
- the type of the property, or nullif no such property exists
 
- 
getTypeTransformerGets a transformer for the given primitive type.- Type Parameters:
- R- The transformer result type.
- Parameters:
- type- the primitive type whose transformer to return
- Returns:
- a transformer that will convert strings into that type, or null if the given type is not a primitive type
 
- 
getWriteMethodGets the mutator for the property with the given name.- Parameters:
- name- the name of the
- Returns:
- null if the name is null; null if the name is not a String; null if no such property exists; null if the property is read-only; or the mutator method for that property
 
- 
getWriteMethodGets the mutator for the property with the given name.- Parameters:
- name- the name of the property
- Returns:
- the mutator method for the property, or null
 
- 
keyIteratorConvenience method for getting an iterator over the keys.Write-only properties will not be returned in the iterator. - Returns:
- an iterator over the keys
 
- 
keySetGets the keys for this BeanMap.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. 
- 
logInfoLogs the given exception toSystem.out. Used to display warnings while accessing/mutating the bean.- Parameters:
- ex- the exception to log
 
- 
logWarnLogs the given exception toSystem.err. Used to display errors while accessing/mutating the bean.- Parameters:
- ex- the exception to log
 
- 
putSets the bean property with the given name to the given value.- Specified by:
- putin interface- Map<String,- Object> 
- Overrides:
- putin class- AbstractMap<String,- Object> 
- Parameters:
- name- the name of the property to set
- value- the value to set that property to
- Returns:
- the previous value of that property
- Throws:
- IllegalArgumentException- if the given name is null; if the given name is not a- String; if the bean doesn't define a property with that name; or if the bean property with that name is read-only
- ClassCastException- if an error occurs creating the method args
 
- 
putAllWriteablePuts all of the writable properties from the given BeanMap into this BeanMap. Read-only and Write-only properties will be ignored.- Parameters:
- map- the BeanMap whose properties to put
 
- 
reinitialiseReinitializes this bean. Called duringsetBean(Object). Does introspection to find properties.
- 
setBeanSets the bean to be operated on by this map. The given value may be null, in which case this map will be empty.- Parameters:
- newBean- the new bean to operate on
 
- 
sizeReturns the number of properties defined by the bean.
- 
toStringRenders a string representation of this object.- Overrides:
- toStringin class- AbstractMap<String,- Object> 
- Returns:
- a Stringrepresentation of this object
 
- 
valueIteratorConvenience method for getting an iterator over the values.- Returns:
- an iterator over the values
 
- 
valuesGets the values for the BeanMap.
 
-