com.vaadin.data.util.converter
Class StringToNumberConverter

java.lang.Object
  extended by com.vaadin.data.util.converter.StringToNumberConverter
All Implemented Interfaces:
Converter<String,Number>, Serializable

public class StringToNumberConverter
extends Object
implements Converter<String,Number>

A converter that converts from Number to String and back. Uses the given locale and NumberFormat for formatting and parsing.

Override and overwrite getFormat(Locale) to use a different format.

Since:
7.0
Version:
7.0.0.alpha3
Author:
Vaadin Ltd
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.vaadin.data.util.converter.Converter
Converter.ConversionException
 
Constructor Summary
StringToNumberConverter()
           
 
Method Summary
 Number convertToModel(String value, Locale locale)
          Converts the given value from target type to source type.
 String convertToPresentation(Number value, Locale locale)
          Converts the given value from source type to target type.
protected  NumberFormat getFormat(Locale locale)
          Returns the format used by convertToPresentation(Number, Locale) and convertToModel(String, Locale).
 Class<Number> getModelType()
          The source type of the converter.
 Class<String> getPresentationType()
          The target type of the converter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringToNumberConverter

public StringToNumberConverter()
Method Detail

getFormat

protected NumberFormat getFormat(Locale locale)
Returns the format used by convertToPresentation(Number, Locale) and convertToModel(String, Locale).

Parameters:
locale - The locale to use
Returns:
A NumberFormat instance

convertToModel

public Number convertToModel(String value,
                             Locale locale)
                      throws Converter.ConversionException
Description copied from interface: Converter
Converts the given value from target type to source type.

A converter can optionally use locale to do the conversion.

A converter should in most cases be symmetric so chaining Converter.convertToPresentation(Object, Locale) and Converter.convertToModel(Object, Locale) should return the original value.

Specified by:
convertToModel in interface Converter<String,Number>
Parameters:
value - The value to convert, compatible with the target type. Can be null
locale - The locale to use for conversion. Can be null.
Returns:
The converted value compatible with the source type
Throws:
Converter.ConversionException - If the value could not be converted

convertToPresentation

public String convertToPresentation(Number value,
                                    Locale locale)
                             throws Converter.ConversionException
Description copied from interface: Converter
Converts the given value from source type to target type.

A converter can optionally use locale to do the conversion.

A converter should in most cases be symmetric so chaining Converter.convertToPresentation(Object, Locale) and Converter.convertToModel(Object, Locale) should return the original value.

Specified by:
convertToPresentation in interface Converter<String,Number>
Parameters:
value - The value to convert, compatible with the target type. Can be null
locale - The locale to use for conversion. Can be null.
Returns:
The converted value compatible with the source type
Throws:
Converter.ConversionException - If the value could not be converted

getModelType

public Class<Number> getModelType()
Description copied from interface: Converter
The source type of the converter. Values of this type can be passed to Converter.convertToPresentation(Object, Locale).

Specified by:
getModelType in interface Converter<String,Number>
Returns:
The source type

getPresentationType

public Class<String> getPresentationType()
Description copied from interface: Converter
The target type of the converter. Values of this type can be passed to Converter.convertToModel(Object, Locale).

Specified by:
getPresentationType in interface Converter<String,Number>
Returns:
The target type


Copyright © 2000-2011 Vaadin Ltd. All Rights Reserved.