Class CustomMapEditor
- All Implemented Interfaces:
PropertyEditor
- Since:
- 2.0.1
- Author:
- Juergen Hoeller
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCustomMapEditor(Class<? extends Map> mapType) Create a new CustomMapEditor for the given target type, keeping an incomingnullas-is.CustomMapEditor(Class<? extends Map> mapType, boolean nullAsEmptyMap) Create a new CustomMapEditor for the given target type. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanReturn whether to always create a new Map, even if the type of the passed-in Map already matches.protected ObjectconvertKey(Object key) Hook to convert each encountered Map key.protected ObjectconvertValue(Object value) Hook to convert each encountered Map value.Create a Map of the given type, with the given initial capacity (if supported by the Map type).This implementation returnsnullto indicate that there is no appropriate text representation.voidConvert the given text value to a Map with a single element.voidConvert the given value to a Map of the target type.Methods inherited from class PropertyEditorSupport
addPropertyChangeListener, firePropertyChange, getCustomEditor, getJavaInitializationString, getSource, getTags, getValue, isPaintable, paintValue, removePropertyChangeListener, setSource, supportsCustomEditor
-
Constructor Details
-
CustomMapEditor
-
CustomMapEditor
Create a new CustomMapEditor for the given target type.If the incoming value is of the given type, it will be used as-is. If it is a different Map type or an array, it will be converted to a default implementation of the given Map type. If the value is anything else, a target Map with that single value will be created.
The default Map implementations are: TreeMap for SortedMap, and LinkedHashMap for Map.
- Parameters:
mapType- the target type, which needs to be a sub-interface of Map or a concrete Map classnullAsEmptyMap- ap whether to convert an incomingnullvalue to an empty Map (of the appropriate type)- See Also:
-
-
Method Details
-
setAsText
Convert the given text value to a Map with a single element.- Specified by:
setAsTextin interfacePropertyEditor- Overrides:
setAsTextin classPropertyEditorSupport- Throws:
IllegalArgumentException
-
setValue
Convert the given value to a Map of the target type.- Specified by:
setValuein interfacePropertyEditor- Overrides:
setValuein classPropertyEditorSupport
-
createMap
-
alwaysCreateNewMap
protected boolean alwaysCreateNewMap()Return whether to always create a new Map, even if the type of the passed-in Map already matches.Default is "false"; can be overridden to enforce creation of a new Map, for example to convert elements in any case.
- See Also:
-
convertKey
Hook to convert each encountered Map key. The default implementation simply returns the passed-in key as-is.Can be overridden to perform conversion of certain keys, for example from String to Integer.
Only called if actually creating a new Map! This is by default not the case if the type of the passed-in Map already matches. Override
alwaysCreateNewMap()to enforce creating a new Map in every case.- Parameters:
key- the source key- Returns:
- the key to be used in the target Map
- See Also:
-
convertValue
Hook to convert each encountered Map value. The default implementation simply returns the passed-in value as-is.Can be overridden to perform conversion of certain values, for example from String to Integer.
Only called if actually creating a new Map! This is by default not the case if the type of the passed-in Map already matches. Override
alwaysCreateNewMap()to enforce creating a new Map in every case.- Parameters:
value- the source value- Returns:
- the value to be used in the target Map
- See Also:
-
getAsText
This implementation returnsnullto indicate that there is no appropriate text representation.- Specified by:
getAsTextin interfacePropertyEditor- Overrides:
getAsTextin classPropertyEditorSupport
-