T - The type of the property key (most often String).public class TypedPropertyMap<T> extends Object implements Map<T,Object>, Cloneable
A TypedPropertyMap is proxy for a source list of key/value pairs, that allows getting and setting of properties in a strongly typed fashion. Usually the source is a simple map with both String key and value.
For this to be possible, the properties must be defined. Meaning that every property key must have an associated strong typed to map to.
Additionally a ConversionService must be present that can perform the type conversion for every property.
Note: the standard implementation does not cache the fetched values and will always read from
the backing source directly. See also CachingTypedPropertyMap.
This class also implements the Map interface to facilitate use in JSP/JSTL. Note that the semantics for the general Map interface might be somewhat dodgy and slower than a regular map.
CachingTypedPropertyMap,
PropertyTypeRegistry,
PropertiesSource,
ConversionService| Modifier and Type | Field and Description |
|---|---|
protected PropertyTypeRegistry<T> |
propertyTypeRegistry |
protected PropertiesSource |
source |
protected Class |
sourceValueClass |
| Constructor and Description |
|---|
TypedPropertyMap(PropertyTypeRegistry<T> propertyTypeRegistry,
Map<T,?> source,
Class sourceValueClass)
Construct a new TypedPropertyMap.
|
TypedPropertyMap(PropertyTypeRegistry<T> propertyTypeRegistry,
PropertiesSource source,
Class sourceValueClass)
Construct a new TypedPropertyMap.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear() |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
TypedPropertyMap<T> |
detach()
Creates a duplicate of the TypedPropertyMap with its own property source, but the
same registry and conversionService.
|
Set<Map.Entry<T,Object>> |
entrySet() |
Object |
get(Object key) |
PropertiesSource |
getSource() |
<O> O |
getValue(T property)
Allows a strong typed property to be fetched from the source map.
|
<O> O |
getValue(T property,
Class<O> expectedType)
Fetches a property from the source map and converts it to the type expected.
|
<O> O |
getValue(T property,
org.springframework.core.convert.TypeDescriptor expectedType)
Fetches a property from the source map and converts it to the type expected.
|
boolean |
isEmpty() |
Set<T> |
keySet() |
Object |
put(T key,
Object value) |
void |
putAll(Map<? extends T,?> m) |
Object |
remove(Object key) |
Object |
set(T property,
Object value)
Stores the property value in the source map by converting it to the sourceValueClass first.
|
int |
size() |
Collection<Object> |
values() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcompute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAllprotected final PropertyTypeRegistry<T> propertyTypeRegistry
protected final Class sourceValueClass
protected final PropertiesSource source
public TypedPropertyMap(PropertyTypeRegistry<T> propertyTypeRegistry, Map<T,?> source, Class sourceValueClass)
propertyTypeRegistry - Registry that contains the property keys with their corresponding type
and conversion information.source - Backing source map containing the stored values.sourceValueClass - Class to use when setting values on the source map.public TypedPropertyMap(PropertyTypeRegistry<T> propertyTypeRegistry, PropertiesSource source, Class sourceValueClass)
propertyTypeRegistry - Registry that contains the property keys with their corresponding type.source - Backing source proxy containing the stored values.sourceValueClass - Class to use when setting values on the source map.PropertiesSourcepublic PropertiesSource getSource()
public <O> O getValue(T property)
O - Strong type value to return, the must registered type for the property must be able to cast to this type!property - Key of the property.public <O> O getValue(T property, Class<O> expectedType)
O - Strong type value to return.property - Key of the property.expectedType - Type the value should be converted to and will be returned.public <O> O getValue(T property, org.springframework.core.convert.TypeDescriptor expectedType)
O - Strong type value to return, converted value will be cast to the return type.property - Key of the property.expectedType - Type the value should be converted to and will be returned.public Object set(T property, Object value)
property - Key of the property.value - Strong type value to set the property to.public boolean containsKey(Object key)
containsKey in interface Map<T,Object>public boolean containsValue(Object value)
containsValue in interface Map<T,Object>public TypedPropertyMap<T> detach()
Copyright © 2017. All rights reserved.