org.codehaus.waffle.bind.converters
Class StringNumberListMapValueConverter
java.lang.Object
org.codehaus.waffle.bind.converters.AbstractValueConverter
org.codehaus.waffle.bind.converters.StringListMapValueConverter
org.codehaus.waffle.bind.converters.StringNumberListMapValueConverter
- All Implemented Interfaces:
- ValueConverter
public class StringNumberListMapValueConverter
- extends StringListMapValueConverter
ValueConverter
that converts a text value to a Map of Number Lists indexed by Strings. It extends
StringListMapValueConverter
providing number parsing of the string values using the NumberFormat
instance provided (which defaults to NumberFormat.getInstance()
) and if not successful returns the
string values themselves.
A value of the form
a=1\n
b=1,2\n
c=1,2,3
would be converted to a map
Map<String, List<? extends Number>> map = new HashMap<String, List<? extends Number>>();
map.put("a", asList(1));
map.put("b", asList(1, 2));
map.put("c", asList(1, 2, 3));
As for StringListMapValueConverter
, the separators are also optionally injectable via Properties
in the constructor and take precedence over
the ones configured in the messages resources.
- Author:
- Mauro Talevi
Method Summary |
boolean |
accept(java.lang.reflect.Type type)
Accepts parameterized types of raw type Map and argument types String and Number |
protected java.lang.Object |
convertMissingValue(java.lang.String key,
java.lang.String defaultMessage,
java.lang.Object... parameters)
Handles the case of a missing value. |
java.lang.Object |
convertValue(java.lang.String propertyName,
java.lang.String value,
java.lang.reflect.Type toType)
Converts a String value to an Object of a given type |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
StringNumberListMapValueConverter
public StringNumberListMapValueConverter(MessageResources messageResources)
StringNumberListMapValueConverter
public StringNumberListMapValueConverter(MessageResources messageResources,
java.util.Properties patterns)
StringNumberListMapValueConverter
public StringNumberListMapValueConverter(MessageResources messageResources,
java.util.Properties patterns,
java.text.NumberFormat numberFormat)
accept
public boolean accept(java.lang.reflect.Type type)
- Accepts parameterized types of raw type Map and argument types String and Number
- Specified by:
accept
in interface ValueConverter
- Overrides:
accept
in class StringListMapValueConverter
- Parameters:
type
- the Type a value is to be bound to
- Returns:
- A boolean
true
is type is compatible
convertValue
public java.lang.Object convertValue(java.lang.String propertyName,
java.lang.String value,
java.lang.reflect.Type toType)
- Description copied from interface:
ValueConverter
- Converts a String value to an Object of a given type
- Specified by:
convertValue
in interface ValueConverter
- Overrides:
convertValue
in class StringListMapValueConverter
- Parameters:
propertyName
- the associated property name, which can be null
, also needed to present
customized error messages.value
- the String valuetoType
- the Object Type
- Returns:
- The converted Object
convertMissingValue
protected java.lang.Object convertMissingValue(java.lang.String key,
java.lang.String defaultMessage,
java.lang.Object... parameters)
- Description copied from class:
AbstractValueConverter
- Handles the case of a missing value. By default it return a
null
converted value, but can be
overridden to throw a BindException
- Overrides:
convertMissingValue
in class StringListMapValueConverter
- Parameters:
key
- the error message keydefaultMessage
- the default message if key is not foundparameters
- the message formatting parameters
- Returns:
- A converted object when value is missing,
null
by default.
Copyright © 2008. All Rights Reserved.