Class EnumFormatter<T extends Enum<T>>

java.lang.Object
net.sf.basedb.util.formatter.EnumFormatter<T>
All Implemented Interfaces:
Formatter<Enum<T>>

public class EnumFormatter<T extends Enum<T>> extends Object implements Formatter<Enum<T>>
Formatter implementation that converts an enum constant into it's name() as the formatted value.
Since:
3.8
Author:
Nicklas
  • Field Details

    • enumClass

      private final Class<T extends Enum<T>> enumClass
    • nullValue

      private String nullValue
  • Constructor Details

    • EnumFormatter

      public EnumFormatter(Class<T> enumClass)
      Create a new formatter. Null values are formatted as an empty string.
      Parameters:
      enumClass - Only required if using the parseString method
    • EnumFormatter

      public EnumFormatter(Class<T> enumClass, String nullValue)
      Create a new formatter.
      Parameters:
      enumClass - Only required if using the parseString method
      nullValue - The string to return if a null item is passed to format(Enum)
  • Method Details

    • format

      public String format(Enum<T> value)
      Description copied from interface: Formatter
      Format a value by converting it to a string.
      Specified by:
      format in interface Formatter<T extends Enum<T>>
      Parameters:
      value - The value to format
      Returns:
      A formatted string
    • parseString

      public Enum<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 extends Enum<T>>
      Parameters:
      value - The string to parse
      Returns:
      An object