Class EnumFormatter<E extends java.lang.Enum<E>>

  • Type Parameters:
    E -
    All Implemented Interfaces:
    Converter<java.lang.String,​E>

    public class EnumFormatter<E extends java.lang.Enum<E>>
    extends java.lang.Object
    implements Converter<java.lang.String,​E>
    Formats an enum type. Outputs null when the value of the enum is equal to a default value.
    Author:
    Neil Bartlett
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String convert​(E input)  
      static <E extends java.lang.Enum<E>>
      EnumFormatter<E>
      create​(java.lang.Class<E> enumType)
      Construct a new formatter with no default value, i.e.
      static <E extends java.lang.Enum<E>>
      EnumFormatter<E>
      create​(java.lang.Class<E> enumType, E defaultValue)
      Construct a new formatter with the specified default value.
      java.lang.String error​(java.lang.String msg)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • create

        public static <E extends java.lang.Enum<E>> EnumFormatter<E> create​(java.lang.Class<E> enumType)
        Construct a new formatter with no default value, i.e. any non-null value of the enum will print that value.
        Parameters:
        enumType - The enum type.
      • create

        public static <E extends java.lang.Enum<E>> EnumFormatter<E> create​(java.lang.Class<E> enumType,
                                                                            E defaultValue)
        Construct a new formatter with the specified default value.
        Parameters:
        enumType - The enum type.
        defaultValue - The default value, which will never be output.
      • convert

        public java.lang.String convert​(E input)
                                 throws java.lang.IllegalArgumentException
        Specified by:
        convert in interface Converter<java.lang.String,​E extends java.lang.Enum<E>>
        Throws:
        java.lang.IllegalArgumentException
      • error

        public java.lang.String error​(java.lang.String msg)
        Specified by:
        error in interface Converter<java.lang.String,​E extends java.lang.Enum<E>>