Package net.sf.basedb.util.formatter
Class PrefixSuffixFormatter<T>
java.lang.Object
net.sf.basedb.util.formatter.PrefixSuffixFormatter<T>
- All Implemented Interfaces:
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
-
Constructor Summary
ConstructorDescriptionPrefixSuffixFormatter
(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
-
Field Details
-
NBSP
public static final char NBSPThe character representing a non-breaking space. Usefule to avoid line wrapping between prefix/suffix and value.- See Also:
-
prefix
-
parent
-
suffix
-
usePrefixForNull
private final boolean usePrefixForNull -
useSuffixForNull
private final boolean useSuffixForNull
-
-
Constructor Details
-
PrefixSuffixFormatter
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 Details
-
format
Description copied from interface:Formatter
Format a value by converting it to a string. -
parseString
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
-