- Revision
- 645
- Author
- mauro
- Date
- 2008-04-21 11:05:33 -0500 (Mon, 21 Apr 2008)
Log Message
Made NumberFormat instance injectable (with default) in list value converter.
Modified Paths
Diff
Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/converters/ListValueConverter.java (644 => 645)
--- trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/converters/ListValueConverter.java 2008-04-21 15:46:46 UTC (rev 644) +++ trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/converters/ListValueConverter.java 2008-04-21 16:05:33 UTC (rev 645) @@ -27,8 +27,8 @@ * <li>"bind.error.list" ([EMAIL PROTECTED] #BIND_ERROR_LIST_KEY}): list is <code>null</code> or empty (message defaults to * [EMAIL PROTECTED] #DEFAULT_LIST_MESSAGE})</li> * </ul> - * The converter first attempts to parse the values as numbers (using the default <code>NumberFormat</code> instance) - * and if not successful returns the string values. + * The converter first attempts to parse the values as numbers (using the <code>NumberFormat</code> instance provided, + * which defaults to <code>NumberFormat.getInstance()</code>) and if not successful returns the string values. * * @author Mauro Talevi */ @@ -37,9 +37,15 @@ static final String BIND_ERROR_LIST_KEY = "bind.error.list"; static final String DEFAULT_LIST_MESSAGE = "Invalid list value for field {0}"; private static final String COMMA = ","; + private NumberFormat numberFormat; public ListValueConverter(MessageResources messageResources) { + this(messageResources, NumberFormat.getInstance()); + } + + public ListValueConverter(MessageResources messageResources, NumberFormat numberFormat) { super(messageResources); + this.numberFormat = numberFormat; } public boolean accept(Class<?> type) { @@ -66,10 +72,9 @@ } private List<Number> toNumbers(List<String> values) throws ParseException { - NumberFormat format = NumberFormat.getInstance(); List<Number> list = new ArrayList<Number>(); for (String value : values) { - list.add(format.parse(value)); + list.add(numberFormat.parse(value)); } return list; }
To unsubscribe from this list please visit:
