|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.basedb.util.formatter.MultiFormatter
public class MultiFormatter
A generic formatter that can be used to format objects of mixed classes. To use it you register a formatter for each class you expect to use. A default formatter is used for objects with unregistered classes.
Null values return the empty string.
Field Summary | |
---|---|
private boolean |
checkSuperclass
|
private boolean |
decideOnFirst
|
private Formatter<Object> |
defaultFormatter
|
private Formatter |
formatter
|
private Map<Class<?>,Formatter<?>> |
formatters
|
Constructor Summary | |
---|---|
MultiFormatter(Formatter<Object> defaultFormatter,
boolean checkSuperclass)
Create a new multi formatter. |
|
MultiFormatter(Formatter<Object> defaultFormatter,
boolean checkSuperclass,
boolean decideOnFirst)
Create a new multi formatter. |
Method Summary | ||
---|---|---|
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. |
|
|
registerFormatter(Class<? extends T> clazz,
Formatter<T> formatter)
Register a formatter for the specified class. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final Formatter<Object> defaultFormatter
private final boolean checkSuperclass
private final Map<Class<?>,Formatter<?>> formatters
private final boolean decideOnFirst
private Formatter formatter
Constructor Detail |
---|
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.Method Detail |
---|
public String format(Object value)
Formatter
format
in interface Formatter<Object>
value
- The value to format
public Number parseString(String value)
Formatter
parseString
in interface Formatter<Object>
value
- The string to parse
public <T> void registerFormatter(Class<? extends T> clazz, Formatter<T> formatter)
clazz
- The class of objects to format with the formatterformatter
- The formatter
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |