Class IdentityConverter<S extends T,T>

Type Parameters:
S - the base type of source objects.
T - the base type of converted objects.
All Implemented Interfaces:
Serializable, Function<S,T>, ObjectConverter<S,T>

public final class IdentityConverter<S extends T,T> extends SystemConverter<S,T>
An object converter which returns the source unchanged.

Immutability and thread safety

This class is immutable and thus inherently thread-safe.
Since:
0.3
Version:
0.3
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      For cross-version compatibility.
      See Also:
    • inverse

      private final ObjectConverter<T,S extends T> inverse
      The inverse converter specified at construction time, or null if none.
  • Constructor Details

    • IdentityConverter

      public IdentityConverter(Class<S> sourceClass, Class<T> targetClass, ObjectConverter<T,S> inverse)
      Creates a new identity converter.
      Parameters:
      sourceClass - the source class.
      targetClass - the target class.
      inverse - the inverse converter, or null if none.
  • Method Details

    • properties

      public Set<FunctionProperty> properties()
      Returns the properties of this converter. This method returns a new EnumSet instead of returning a constant, because creating EnumSet is cheap and the standard JDK implementation has optimizations for bulk operations between EnumSet instances. Those optimizations are lost (at least on JDK6) is we wrap the EnumSet in a Collections.unmodifiableSet view.
      Returns:
      the manners in which source values are mapped to target values.
    • inverse

      Returns the inverse converter, if any.
      Specified by:
      inverse in interface ObjectConverter<S extends T,T>
      Overrides:
      inverse in class SystemConverter<S extends T,T>
      Returns:
      a converter for converting instances of T back to instances of S.
      Throws:
      UnsupportedOperationException - if this converter is not invertible.
      See Also:
    • apply

      public T apply(S source)
      Returns the given object unchanged.
      Parameters:
      source - the value to convert.
      Returns:
      the given value unchanged.