public class MultiFormatter extends Object implements Formatter<Object>
Null values return the empty string.
Modifier and Type | Field and Description |
---|---|
private boolean |
checkSuperclass |
private boolean |
decideOnFirst |
private Formatter<Object> |
defaultFormatter |
private Formatter |
formatter |
private Map<Class<?>,Formatter<?>> |
formatters |
Constructor and Description |
---|
MultiFormatter(Formatter<Object> defaultFormatter,
boolean checkSuperclass)
Create a new multi formatter.
|
MultiFormatter(Formatter<Object> defaultFormatter,
boolean checkSuperclass,
boolean decideOnFirst)
Create a new multi formatter.
|
Modifier and Type | Method and Description |
---|---|
String |
format(Object value)
Format a value by converting it to a string.
|
Number |
parseString(String value)
Parse a string and return a value of the correct type.
|
<T> void |
registerFormatter(Class<? extends T> clazz,
Formatter<T> formatter)
Register a formatter for the specified class.
|
private final boolean checkSuperclass
private final boolean decideOnFirst
private Formatter formatter
public MultiFormatter(Formatter<Object> defaultFormatter, boolean checkSuperclass)
defaultFormatter
- The formatter to use if the object's class
isn't found among the registered formatterscheckSuperclass
- If the superclass and interfaces of the object should be
checked in case there is no exact matchpublic MultiFormatter(Formatter<Object> defaultFormatter, boolean checkSuperclass, boolean decideOnFirst)
defaultFormatter
- The formatter to use if the object's class
isn't found among the registered formatterscheckSuperclass
- If the superclass and interfaces of the object should be
checked in case there is no exact matchdecideOnFirst
- If TRUE, the first non-null value decides which parent
formatter to use. All subsequent calls to format(Object)
uses
the same formatetter. This is useful when you know that the formatter will
only use the same class of objects, but not which class.public String format(Object value)
Formatter
public Number parseString(String value)
Formatter
parseString
in interface Formatter<Object>
value
- The string to parse