2.17.2: 2011-06-17

net.sf.basedb.util.formatter
Class PrefixSuffixFormatter<T>

java.lang.Object
  extended by 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: 2008-09-25 09:01:30 +0200 (Thu, 25 Sep 2008) $

Field Summary
static char NBSP
          The character representing a non-breaking space.
private  Formatter<T> parent
           
private  String prefix
           
private  String suffix
           
 
Constructor Summary
PrefixSuffixFormatter(String prefix, Formatter<T> parent, String suffix)
          Create a new formatter.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

parent

private final Formatter<T> parent

suffix

private final String suffix
Constructor Detail

PrefixSuffixFormatter

public PrefixSuffixFormatter(String prefix,
                             Formatter<T> parent,
                             String suffix)
Create a new formatter.

Parameters:
prefix - The prefix, or null to not use any prefix
parent - The parent formatter, if null a ToStringFormatter is automatically created
suffix - The suffix, or null to not use any suffix
Method Detail

format

public String format(T value)
Description copied from interface: Formatter
Format a value by converting it to a string.

Specified by:
format in interface Formatter<T>
Parameters:
value - The value to format
Returns:
A formatted 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 interface Formatter<T>
Parameters:
value - The string to parse
Returns:
An object

2.17.2: 2011-06-17