public final class ConverterFactory extends Object
Type converters should be used judiciously. To bind non-Strings
to a text UI component
you should favor to use a JFormattedTextField.
They provide a powerful means to convert Strings to objects
and handle many cases that arise around invalid input.
ValueModel,
Format,
JFormattedTextField| Modifier and Type | Class and Description |
|---|---|
static class |
ConverterFactory.BooleanNegator
Negates Booleans leaving null unchanged.
|
static class |
ConverterFactory.BooleanToStringConverter
Converts Booleans to Strings and vice-versa using given texts for
true, false, and null.
|
static class |
ConverterFactory.DoubleConverter
Converts Doubles using a given multiplier.
|
static class |
ConverterFactory.DoubleToIntegerConverter
Converts Doubles to Integers and vice-versa.
|
static class |
ConverterFactory.FloatConverter
Converts Floats using a given multiplier.
|
static class |
ConverterFactory.FloatToIntegerConverter
Converts Floats to Integers and vice-versa.
|
static class |
ConverterFactory.IntegerConverter
Converts Integers using a given multiplier.
|
static class |
ConverterFactory.LongConverter
Converts Longs using a given multiplier.
|
static class |
ConverterFactory.LongToIntegerConverter
Converts Longs to Integers and vice-versa.
|
static class |
ConverterFactory.StringConverter
Converts Values to Strings and vice-versa using a given Format.
|
| Modifier and Type | Method and Description |
|---|---|
static ValueModel |
createBooleanNegator(ValueModel booleanSource)
Creates and returns a ValueModel that negates Booleans and leaves
null unchanged. |
static ValueModel |
createBooleanToStringConverter(ValueModel booleanSubject,
String trueText,
String falseText)
Creates and returns a ValueModel that converts Booleans
to the associated of the two specified strings, and vice versa.
|
static ValueModel |
createBooleanToStringConverter(ValueModel booleanSource,
String trueText,
String falseText,
String nullText)
Creates and returns a ValueModel that converts Booleans
to the associated of the two specified strings, and vice versa.
|
static ValueModel |
createDoubleConverter(ValueModel doubleSource,
double multiplier)
Creates and returns a ValueModel that converts Doubles using the
specified multiplier.
|
static ValueModel |
createDoubleToIntegerConverter(ValueModel doubleSource)
Creates and returns a ValueModel that converts Doubles to Integer,
and vice versa.
|
static ValueModel |
createDoubleToIntegerConverter(ValueModel doubleSource,
int multiplier)
Creates and returns a ValueModel that converts Doubles to Integer,
and vice versa.
|
static ValueModel |
createFloatConverter(ValueModel floatSource,
float multiplier)
Creates and returns a ValueModel that converts Floats using the
specified multiplier.
|
static ValueModel |
createFloatToIntegerConverter(ValueModel floatSource)
Creates and returns a ValueModel that converts Floats to Integer,
and vice versa.
|
static ValueModel |
createFloatToIntegerConverter(ValueModel floatSource,
int multiplier)
Creates and returns a ValueModel that converts Floats to Integer,
and vice versa.
|
static ValueModel |
createIntegerConverter(ValueModel integerSource,
double multiplier)
Creates and returns a ValueModel that converts Integers using the
specified multiplier.
|
static ValueModel |
createLongConverter(ValueModel longSource,
double multiplier)
Creates and returns a ValueModel that converts Long using the
specified multiplier.
|
static ValueModel |
createLongToIntegerConverter(ValueModel longSubject)
Creates and returns a ValueModel that converts Longs to Integer
and vice versa.
|
static ValueModel |
createLongToIntegerConverter(ValueModel longSource,
int multiplier)
Creates and returns a ValueModel that converts Longs to Integer
and vice versa.
|
static ValueModel |
createStringConverter(ValueModel source,
Format format)
Creates and returns a ValueModel that converts objects to Strings
and vice versa.
|
public static ValueModel createBooleanNegator(ValueModel booleanSource)
null unchanged.booleanSource - a Boolean ValueModelNullPointerException - if the booleanSource is nullpublic static ValueModel createBooleanToStringConverter(ValueModel booleanSubject, String trueText, String falseText)
null is mapped to an empty string.
Ignores cases when setting a text.booleanSubject - a Boolean ValueModeltrueText - the text associated with Boolean.TRUEfalseText - the text associated with Boolean.FALSENullPointerException - if booleanSource,
trueText, falseText or nullText is nullIllegalArgumentException - if trueText equals falseTextpublic static ValueModel createBooleanToStringConverter(ValueModel booleanSource, String trueText, String falseText, String nullText)
null is mapped to the specified text.
Ignores cases when setting a text.booleanSource - a Boolean ValueModeltrueText - the text associated with Boolean.TRUEfalseText - the text associated with Boolean.FALSEnullText - the text associated with nullNullPointerException - if booleanSource,
trueText, falseText or nullText is nullIllegalArgumentException - if trueText equals falseTextpublic static ValueModel createDoubleConverter(ValueModel doubleSource, double multiplier)
Examples: multiplier=100, Double(1.23) -> Double(123), multiplier=1000, Double(1.23) -> Double(1230)
doubleSource - a Double ValueModelmultiplier - the multiplier used for the conversionNullPointerException - if doubleSource is nullpublic static ValueModel createDoubleToIntegerConverter(ValueModel doubleSource)
doubleSource - a Double ValueModelNullPointerException - if doubleSource is nullpublic static ValueModel createDoubleToIntegerConverter(ValueModel doubleSource, int multiplier)
Examples: multiplier=100, Double(1.23) -> Integer(123), multiplier=1000, Double(1.23) -> Integer(1230)
doubleSource - a Double ValueModelmultiplier - the multiplier used to convert the Double to IntegerNullPointerException - if doubleSource is nullpublic static ValueModel createFloatConverter(ValueModel floatSource, float multiplier)
Examples: multiplier=100, Float(1.23) -> Float(123), multiplier=1000, Float(1.23) -> Float(1230)
floatSource - a Float ValueModelmultiplier - the multiplier used for the conversionNullPointerException - if floatSource is nullpublic static ValueModel createFloatToIntegerConverter(ValueModel floatSource)
floatSource - a Float ValueModelNullPointerException - if floatSource is nullpublic static ValueModel createFloatToIntegerConverter(ValueModel floatSource, int multiplier)
floatSource - a Float ValueModelmultiplier - the multiplier used to convert the Float to IntegerNullPointerException - if floatSource is nullpublic static ValueModel createIntegerConverter(ValueModel integerSource, double multiplier)
Examples: multiplier=100, Integer(3) -> Integer(300), multiplier=1000, Integer(3) -> Integer(3000)
integerSource - a Integer ValueModelmultiplier - the multiplier used for the conversionNullPointerException - if integerSource is nullpublic static ValueModel createLongConverter(ValueModel longSource, double multiplier)
Examples: multiplier=100, Long(3) -> Long(300), multiplier=1000, Long(3) -> Long(3000)
longSource - a Long ValueModelmultiplier - the multiplier used for the conversionNullPointerException - if longSource is nullpublic static ValueModel createLongToIntegerConverter(ValueModel longSubject)
Constraints: The subject is of type Long,
values written to the converter are of type Integer.
longSubject - a Long ValueModelNullPointerException - if the subject is nullpublic static ValueModel createLongToIntegerConverter(ValueModel longSource, int multiplier)
Constraints: The subject is of type Long,
values written to the converter are of type Integer.
longSource - a Long ValueModelmultiplier - used to multiply the Long when converting to IntegerNullPointerException - if longSource is nullpublic static ValueModel createStringConverter(ValueModel source, Format format)
Format.
Constraints: The source is of type Object;
it must be formattable and parsable via the given Format.
source - the underlying ValueModel.format - the Format used to format and parseNullPointerException - if source or format
is nullCopyright © 2002-2015 JGoodies Software GmbH. All Rights Reserved.