Package net.sf.basedb.util.formatter
Class PrefixSuffixFormatter<T>
- java.lang.Object
-
- net.sf.basedb.util.formatter.PrefixSuffixFormatter<T>
-
- All Implemented Interfaces:
Formatter<T>
public class PrefixSuffixFormatter<T> extends Object implements Formatter<T>
Formats a value with optional prefix and suffix. This formatter uses a parent formatter to format the actual value and then adds prefix and suffix as needed to the start and end of the formatted value.The
parseString(String)
method will first check if the string start or ends with the given prefix/suffix. If it does, the prefix/suffix is removed before parsing is delegated to the parent.- Version:
- 2.9
- Author:
- nicklas
- Last modified
- $Date: 2013-04-11 08:51:47 +0200 (to, 11 apr 2013) $
-
-
Field Summary
Fields Modifier and Type Field Description static char
NBSP
The character representing a non-breaking space.private Formatter<T>
parent
private String
prefix
private String
suffix
private boolean
usePrefixForNull
private boolean
useSuffixForNull
-
Constructor Summary
Constructors Constructor Description PrefixSuffixFormatter(String prefix, boolean usePrefixForNull, Formatter<T> parent, String suffix, boolean useSuffixForNull)
Create a new formatter.PrefixSuffixFormatter(String prefix, Formatter<T> parent, String suffix)
Create a new formatter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
format(T value)
Format a value by converting it to a string.T
parseString(String value)
Parse a string and return a value of the correct type.
-
-
-
Field Detail
-
NBSP
public static final char NBSP
The character representing a non-breaking space. Usefule to avoid line wrapping between prefix/suffix and value.- See Also:
- Constant Field Values
-
prefix
private final String prefix
-
suffix
private final String suffix
-
usePrefixForNull
private final boolean usePrefixForNull
-
useSuffixForNull
private final boolean useSuffixForNull
-
-
Constructor Detail
-
PrefixSuffixFormatter
public PrefixSuffixFormatter(String prefix, Formatter<T> parent, String suffix)
Create a new formatter. Prefix and suffix are included for null values.- Parameters:
prefix
- The prefix, or null to not use any prefixparent
- The parent formatter, if null aToStringFormatter
is automatically createdsuffix
- The suffix, or null to not use any suffix
-
PrefixSuffixFormatter
public PrefixSuffixFormatter(String prefix, boolean usePrefixForNull, Formatter<T> parent, String suffix, boolean useSuffixForNull)
Create a new formatter.- Parameters:
prefix
- The prefix, or null to not use any prefixusePrefixForNull
- If set, the prefix is always included, otherwise only for non-null valuesparent
- The parent formatter, if null aToStringFormatter
is automatically createdsuffix
- The suffix, or null to not use any suffixuseSuffixForNull
- If set, the suffix is always included, otherwise only for non-null values
-
-
Method Detail
-
format
public String format(T value)
Description copied from interface:Formatter
Format a value by converting it to a string.
-
parseString
public T parseString(String value)
Description copied from interface:Formatter
Parse a string and return a value of the correct type. A null input string should (unless otherwise documented by a specific formatter implementation) be allowed and may return null or any other "default" value.- Specified by:
parseString
in interfaceFormatter<T>
- Parameters:
value
- The string to parse- Returns:
- An object
-
-