net.sf.jsefa.common.converter
Class BooleanConverter

java.lang.Object
  extended by net.sf.jsefa.common.converter.BooleanConverter
All Implemented Interfaces:
SimpleTypeConverter

public class BooleanConverter
extends Object
implements SimpleTypeConverter

Converter for Boolean objects.
The format consists of two Strings. The first token is the literal for true and the second the literal for false.

It is thread-safe.

Author:
Norman Lahme-Huetig

Field Summary
protected static String[] FORMAT_BINARY
          Format String with "1" for true and "0" for false.
protected static String[] FORMAT_TRUE_FALSE
          Format String with "true" for true and "false" for false.
protected static String[] FORMAT_YES_NO
          Format String with "yes" for true and "no" for false.
 
Constructor Summary
protected BooleanConverter(SimpleTypeConverterConfiguration configuration)
          Constructs a new BooleanConverter.
 
Method Summary
static BooleanConverter create(SimpleTypeConverterConfiguration configuration)
          Creates a new BooleanConverter.
 Boolean fromString(String value)
          Converts the given String object into an object with the simple data type this converter is intended for.
protected  String[] getDefaultFormat()
          Returns the default format which is used when no format is given.
 String toString(Object value)
          Converts the given value to a String object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FORMAT_TRUE_FALSE

protected static final String[] FORMAT_TRUE_FALSE
Format String with "true" for true and "false" for false.


FORMAT_YES_NO

protected static final String[] FORMAT_YES_NO
Format String with "yes" for true and "no" for false.


FORMAT_BINARY

protected static final String[] FORMAT_BINARY
Format String with "1" for true and "0" for false.

Constructor Detail

BooleanConverter

protected BooleanConverter(SimpleTypeConverterConfiguration configuration)
Constructs a new BooleanConverter.
If no format is given, the default format (see getDefaultFormat()) is used.

Parameters:
configuration - the configuration.
Throws:
ConversionException - if the given format is not valid.
Method Detail

create

public static BooleanConverter create(SimpleTypeConverterConfiguration configuration)
Creates a new BooleanConverter.
If no format is given, the default format (see getDefaultFormat()) is used.

Parameters:
configuration - the configuration.
Returns:
a boolean converter
Throws:
ConversionException - if the given format is not valid.

fromString

public final Boolean fromString(String value)
Converts the given String object into an object with the simple data type this converter is intended for.

Specified by:
fromString in interface SimpleTypeConverter
Parameters:
value - the String object to convert
Returns:
the converted value

toString

public final String toString(Object value)
Converts the given value to a String object.

Specified by:
toString in interface SimpleTypeConverter
Parameters:
value - the value to convert
Returns:
the converted value

getDefaultFormat

protected String[] getDefaultFormat()
Returns the default format which is used when no format is given.

Returns:
the default format.


Copyright © 2014. All rights reserved.