com.vaadin.data.util.converter
Class StringToBooleanConverter

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

public class StringToBooleanConverter
extends java.lang.Object
implements Converter<java.lang.String,java.lang.Boolean>

A converter that converts from String to Boolean and back. The String representation is given by Boolean.toString() or provided in constructor StringToBooleanConverter(String, String).

Leading and trailing white spaces are ignored when converting from a String.

For language-dependent representation, subclasses should overwrite getFalseString(Locale) and getTrueString(Locale)

Since:
7.0
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
StringToBooleanConverter()
          Creates converter with default string representations - "true" and "false"
StringToBooleanConverter(java.lang.String trueString, java.lang.String falseString)
          Creates converter with custom string representation.
 
Method Summary
 java.lang.Boolean convertToModel(java.lang.String value, java.lang.Class<? extends java.lang.Boolean> targetType, java.util.Locale locale)
          Converts the given value from target type to source type.
 java.lang.String convertToPresentation(java.lang.Boolean value, java.lang.Class<? extends java.lang.String> targetType, java.util.Locale locale)
          Converts the given value from source type to target type.
protected  java.lang.String getFalseString()
          Gets the string representation for false.
protected  java.lang.String getFalseString(java.util.Locale locale)
          Gets the locale-depended string representation for false.
 java.lang.Class<java.lang.Boolean> getModelType()
          The source type of the converter.
 java.lang.Class<java.lang.String> getPresentationType()
          The target type of the converter.
protected  java.lang.String getTrueString()
          Gets the string representation for true.
protected  java.lang.String getTrueString(java.util.Locale locale)
          Gets the locale-depended string representation for true.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringToBooleanConverter

public StringToBooleanConverter()
Creates converter with default string representations - "true" and "false"


StringToBooleanConverter

public StringToBooleanConverter(java.lang.String trueString,
                                java.lang.String falseString)
Creates converter with custom string representation.

Parameters:
falseString - string representation for false
trueString - string representation for true
Since:
7.5.4
Method Detail

convertToModel

public java.lang.Boolean convertToModel(java.lang.String value,
                                        java.lang.Class<? extends java.lang.Boolean> targetType,
                                        java.util.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, Class, Locale) and Converter.convertToModel(Object, Class, Locale) should return the original value.

Specified by:
convertToModel in interface Converter<java.lang.String,java.lang.Boolean>
Parameters:
value - The value to convert, compatible with the target type. Can be null
targetType - The requested type of the return value
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

getTrueString

protected java.lang.String getTrueString()
Gets the string representation for true. Default is "true", if not set in constructor.

Returns:
the string representation for true

getFalseString

protected java.lang.String getFalseString()
Gets the string representation for false. Default is "false", if not set in constructor.

Returns:
the string representation for false

convertToPresentation

public java.lang.String convertToPresentation(java.lang.Boolean value,
                                              java.lang.Class<? extends java.lang.String> targetType,
                                              java.util.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, Class, Locale) and Converter.convertToModel(Object, Class, Locale) should return the original value.

Specified by:
convertToPresentation in interface Converter<java.lang.String,java.lang.Boolean>
Parameters:
value - The value to convert, compatible with the target type. Can be null
targetType - The requested type of the return value
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

getFalseString

protected java.lang.String getFalseString(java.util.Locale locale)
Gets the locale-depended string representation for false. Default is locale-independent value provided by getFalseString()

Parameters:
locale - to be used
Returns:
the string representation for false
Since:
7.5.4

getTrueString

protected java.lang.String getTrueString(java.util.Locale locale)
Gets the locale-depended string representation for true. Default is locale-independent value provided by getTrueString()

Parameters:
locale - to be used
Returns:
the string representation for true
Since:
7.5.4

getModelType

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

Specified by:
getModelType in interface Converter<java.lang.String,java.lang.Boolean>
Returns:
The source type

getPresentationType

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

Specified by:
getPresentationType in interface Converter<java.lang.String,java.lang.Boolean>
Returns:
The target type


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