public class PrefixSuffixFormatter<T> extends Object implements Formatter<T>
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.
Modifier and Type | Field and 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 and 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.
|
public static final char NBSP
private final String prefix
private final String suffix
private final boolean usePrefixForNull
private final boolean useSuffixForNull
public PrefixSuffixFormatter(String prefix, Formatter<T> parent, String suffix)
prefix
- The prefix, or null to not use any prefixparent
- The parent formatter, if null a ToStringFormatter
is automatically createdsuffix
- The suffix, or null to not use any suffixpublic PrefixSuffixFormatter(String prefix, boolean usePrefixForNull, Formatter<T> parent, String suffix, boolean useSuffixForNull)
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 a ToStringFormatter
is automatically createdsuffix
- The suffix, or null to not use any suffixuseSuffixForNull
- If set, the suffix is always included, otherwise only for non-null
valuespublic String format(T value)
Formatter
public T parseString(String value)
Formatter
parseString
in interface Formatter<T>
value
- The string to parse