Class NullConversion<I,O>

java.lang.Object
com.univocity.parsers.conversions.NullConversion<I,O>
Type Parameters:
I - The object type resulting from conversions of values of type O.
O - The object type resulting from conversions of values of type I.
All Implemented Interfaces:
Conversion<I,O>
Direct Known Subclasses:
ObjectConversion, ToStringConversion

public abstract class NullConversion<I,O> extends Object implements Conversion<I,O>
Default implementation for conversions from input Objects of type I to output Objects of type O

Extending classes must implement a proper String to T conversion in ObjectConversion.fromString(String)

This abstract class provides default results for conversions when the input is null.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private O
     
    private I
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a Conversion from an object to another object of a different type, with default values to return when the input is null.
    NullConversion(O valueOnNullInput, I valueOnNullOutput)
    Creates a Conversion from an object to another object of a different type, with default values to return when the input is null.
  • Method Summary

    Modifier and Type
    Method
    Description
    execute(I input)
    Converts the given instance of type I to an instance of O
    protected abstract O
    fromInput(I input)
    Creates an instance of O from a I object
    returns a default value of type O to be returned when the input of type I is null.
    returns default instance of I to be returned when an input of type O is null.
    revert(O input)
    Converts a value of type O back to a value of type I
    void
    setValueOnNullInput(O valueOnNullInput)
    defines the default value of type O which should be returned when execute(Object) is invoked with a null I..
    void
    setValueOnNullOutput(I valueOnNullOutput)
    defines the default value of type I which should be returned when revert(Object) is invoked with a null O.
    protected abstract I
    undo(O 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
  • Field Details

    • valueOnNullInput

      private O valueOnNullInput
    • valueOnNullOutput

      private I valueOnNullOutput
  • Constructor Details

    • NullConversion

      public NullConversion()
      Creates a Conversion from an object to another object of a different type, 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
    • NullConversion

      public NullConversion(O valueOnNullInput, I valueOnNullOutput)
      Creates a Conversion from an object to another object of a different type, with default values to return when the input is null.
      Parameters:
      valueOnNullInput - default value of type O to be returned when the input object I is null. Used when execute(Object) is invoked.
      valueOnNullOutput - default value of type I to be returned when an input of type I is null. Used when revert(Object) is invoked.
  • Method Details

    • execute

      public O execute(I input)
      Converts the given instance of type I to an instance of O
      Specified by:
      execute in interface Conversion<I,O>
      Parameters:
      input - the input value of type I to be converted to an object of type O
      Returns:
      the conversion result, or the value of valueOnNullInput if the input object is null.
    • fromInput

      protected abstract O fromInput(I input)
      Creates an instance of O from a I object
      Parameters:
      input - The object of type I to be converted to O
      Returns:
      an instance of O, converted from the I input.
    • revert

      public I revert(O input)
      Converts a value of type O back to a value of type I
      Specified by:
      revert in interface Conversion<I,O>
      Parameters:
      input - the input of type O to be converted to an output I
      Returns:
      the conversion result, or the value of valueOnNullOutput if the input object is null.
    • undo

      protected abstract I undo(O input)
      Converts a value of type O back to I.
      Parameters:
      input - the input object to be converted to I
      Returns:
      the conversion result
    • getValueOnNullInput

      public O getValueOnNullInput()
      returns a default value of type O to be returned when the input of type I is null. Used when execute(Object) is invoked.
      Returns:
      the default value of type O used when converting from a null I
    • getValueOnNullOutput

      public I getValueOnNullOutput()
      returns default instance of I to be returned when an input of type O is null. Used when revert(Object) is invoked.
      Returns:
      the default I instance used when converting from a null O
    • setValueOnNullInput

      public void setValueOnNullInput(O valueOnNullInput)
      defines the default value of type O which should be returned when execute(Object) is invoked with a null I..
      Parameters:
      valueOnNullInput - the default value of type T when converting from a null input
    • setValueOnNullOutput

      public void setValueOnNullOutput(I valueOnNullOutput)
      defines the default value of type I which should be returned when revert(Object) is invoked with a null O.
      Parameters:
      valueOnNullOutput - a default value of type I when converting from a null input