|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.univocity.parsers.conversions.NullConversion<String,T>
com.univocity.parsers.conversions.ObjectConversion<Boolean>
com.univocity.parsers.conversions.BooleanConversion
public class BooleanConversion
Converts Strings to Booleans and vice versa
This class supports multiple representations of boolean values. For example, you can define conversions from different Strings such as "Yes, Y, 1" to true, and "No, N, 0" to false.
The reverse conversion from a Boolean to String (in revert(Boolean)
will return the first String provided in this class constructor
Using the previous example, a call to revert(true)
will produce "Yes" and a call revert(false)
will produce "No".
Constructor Summary | |
---|---|
BooleanConversion(Boolean valueIfStringIsNull,
String valueIfObjectIsNull,
String[] valuesForTrue,
String[] valuesForFalse)
Creates a Conversion from String to Boolean with default values to return when the input is null. |
|
BooleanConversion(String[] valuesForTrue,
String[] valuesForFalse)
Creates conversions from String to Boolean. |
Method Summary | |
---|---|
protected Boolean |
fromString(String input)
Converts a String to a Boolean |
static Boolean |
getBoolean(String booleanString,
String[] trueValues,
String[] falseValues)
Returns the Boolean value represented by a String , as defined by sets of Strings that represent true and false values. |
String |
revert(Boolean input)
Converts a Boolean back to a String |
Methods inherited from class com.univocity.parsers.conversions.ObjectConversion |
---|
execute, fromInput, getValueIfObjectIsNull, getValueIfStringIsNull, setValueIfObjectIsNull, setValueIfStringIsNull, undo |
Methods inherited from class com.univocity.parsers.conversions.NullConversion |
---|
getValueOnNullInput, getValueOnNullOutput, setValueOnNullInput, setValueOnNullOutput |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BooleanConversion(String[] valuesForTrue, String[] valuesForFalse)
The list of Strings that identify "true" the list of Strings that identify "false" are mandatory.
valuesForTrue
- Strings that identify the boolean value true. The first element will be returned when executing revert(true)
valuesForFalse
- Strings that identify the boolean value false. The first element will be returned when executing #revert(false)
public BooleanConversion(Boolean valueIfStringIsNull, String valueIfObjectIsNull, String[] valuesForTrue, String[] valuesForFalse)
The list of Strings that identify "true" the list of Strings that identify "false" are mandatory.
valueIfStringIsNull
- default Boolean value to be returned when the input String is null. Used when ObjectConversion.execute(String)
is invoked.valueIfObjectIsNull
- default String value to be returned when a Boolean input is null. Used when revert(Boolean)
is invoked.valuesForTrue
- Strings that identify the boolean value true. The first element will be returned when executing revert(true)
valuesForFalse
- Strings that identify the boolean value false. The first element will be returned when executing #revert(false)
Method Detail |
---|
public String revert(Boolean input)
The return value depends on the list of values for true/false provided in the constructor of this class.
revert
in interface Conversion<String,Boolean>
revert
in class ObjectConversion<Boolean>
input
- the Boolean to be converted to a String
ObjectConversion.getValueIfObjectIsNull()
if the Boolean input is null.protected Boolean fromString(String input)
fromString
in class ObjectConversion<Boolean>
input
- a String to be converted into a Boolean value.
trueValues
, false if the input String is part of falseValues
, or ObjectConversion.getValueIfStringIsNull()
if the input String is null.public static Boolean getBoolean(String booleanString, String[] trueValues, String[] falseValues)
Boolean
value represented by a String
, as defined by sets of Strings that represent true
and false
values.
booleanString
- the value that represents either true
or false
trueValues
- a set of possible string values that represent true
. If empty, then "true" will be assumed as the only acceptable representation.falseValues
- a set of possible string values that represent false
. If empty, then "false" will be assumed as the only acceptable representation.
DataProcessingException
- if the input string does not match any value provided in neither set of possible values.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |