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 Details

    • 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:
    • prefix

      private final String prefix
    • parent

      private final Formatter<T> parent
    • suffix

      private final String suffix
    • usePrefixForNull

      private final boolean usePrefixForNull
    • useSuffixForNull

      private final boolean useSuffixForNull
  • Constructor Details

    • 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 prefix
      parent - The parent formatter, if null a ToStringFormatter is automatically created
      suffix - 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 prefix
      usePrefixForNull - If set, the prefix is always included, otherwise only for non-null values
      parent - The parent formatter, if null a ToStringFormatter is automatically created
      suffix - The suffix, or null to not use any suffix
      useSuffixForNull - If set, the suffix is always included, otherwise only for non-null values
  • Method Details

    • 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