Class ObjectConversion<T>

    • Constructor Summary

      Constructors 
      Constructor Description
      ObjectConversion()
      Creates a Conversion from String to an Object with default values to return when the input is null.
      ObjectConversion​(T valueIfStringIsNull, java.lang.String valueIfObjectIsNull)
      Creates a Conversion from String to an Object with default values to return when the input is null.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      T execute​(java.lang.String input)
      Converts the given String to an instance of T
      protected T fromInput​(java.lang.String input)
      Creates an instance of T from a String representation.
      protected abstract T fromString​(java.lang.String input)
      Creates an instance of T from a String representation.
      java.lang.String getValueIfObjectIsNull()
      returns default String value to be returned when an input of type T is null.
      T getValueIfStringIsNull()
      returns a default value of type T to be returned when the input String is null.
      java.lang.String revert​(T input)
      Converts a value of type T back to a String
      void setValueIfObjectIsNull​(java.lang.String valueIfObjectIsNull)
      returns default value of type T which should be returned when the input String is null.
      void setValueIfStringIsNull​(T valueIfStringIsNull)
      defines a default value of type T which should be returned when the input String is null.
      protected java.lang.String undo​(T input)
      Converts a value of type O back to I.
      • Methods inherited from class java.lang.Object

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

      • ObjectConversion

        public ObjectConversion()
        Creates a Conversion from String to an Object with default values to return when the input is null. The default constructor assumes the output of a conversion should be null when input is null
      • ObjectConversion

        public ObjectConversion​(T valueIfStringIsNull,
                                java.lang.String valueIfObjectIsNull)
        Creates a Conversion from String to an Object with default values to return when the input is null.
        Parameters:
        valueIfStringIsNull - default value of type T to be returned when the input String is null. Used when execute(String) is invoked.
        valueIfObjectIsNull - default String value to be returned when an input of type T is null. Used when revert(Object) is invoked.
    • Method Detail

      • execute

        public T execute​(java.lang.String input)
        Converts the given String to an instance of T
        Specified by:
        execute in interface Conversion<java.lang.String,​T>
        Overrides:
        execute in class NullConversion<java.lang.String,​T>
        Parameters:
        input - the input String to be converted to an object of type T
        Returns:
        the conversion result, or the value of getValueIfStringIsNull() if the input String is null.
      • fromInput

        protected final T fromInput​(java.lang.String input)
        Creates an instance of T from a String representation.
        Specified by:
        fromInput in class NullConversion<java.lang.String,​T>
        Parameters:
        input - The String to be converted to T
        Returns:
        an instance of T, converted from the String input.
      • fromString

        protected abstract T fromString​(java.lang.String input)
        Creates an instance of T from a String representation.
        Parameters:
        input - The String to be converted to T
        Returns:
        an instance of T, converted from the String input.
      • revert

        public java.lang.String revert​(T input)
        Converts a value of type T back to a String

        This is a general implementation that simply returns the result of input.toString()

        Specified by:
        revert in interface Conversion<java.lang.String,​T>
        Overrides:
        revert in class NullConversion<java.lang.String,​T>
        Parameters:
        input - the input of type T to be converted to a String
        Returns:
        the conversion result, or the value of getValueIfObjectIsNull() if the input object is null.
      • undo

        protected final java.lang.String undo​(T input)
        Description copied from class: NullConversion
        Converts a value of type O back to I.
        Specified by:
        undo in class NullConversion<java.lang.String,​T>
        Parameters:
        input - the input object to be converted to I
        Returns:
        the conversion result
      • getValueIfStringIsNull

        public T getValueIfStringIsNull()
        returns a default value of type T to be returned when the input String is null. Used when execute(String) is invoked.
        Returns:
        the default value of type T used when converting from a null input
      • getValueIfObjectIsNull

        public java.lang.String getValueIfObjectIsNull()
        returns default String value to be returned when an input of type T is null. Used when revert(Object) is invoked.
        Returns:
        the default String value used when converting from a null input
      • setValueIfStringIsNull

        public void setValueIfStringIsNull​(T valueIfStringIsNull)
        defines a default value of type T which should be returned when the input String is null. Used when execute(String) is invoked.
        Parameters:
        valueIfStringIsNull - the default value of type T when converting from a null input
      • setValueIfObjectIsNull

        public void setValueIfObjectIsNull​(java.lang.String valueIfObjectIsNull)
        returns default value of type T which should be returned when the input String is null. Used when revert(Object) is invoked.
        Parameters:
        valueIfObjectIsNull - a default value of type T when converting from a null input