Class ArrayConverter<S,T>

All Implemented Interfaces:
Serializable, Function<S,T>, ObjectConverter<S,T>

final class ArrayConverter<S,T> extends SystemConverter<S,T>
Handles conversions between arrays. This converter delegates element conversions to another converter given at construction time. If the source and target types of this converter are <S[]> and <T[]>, then the source and target types of the element converter shall be <? super S> and <? extends T> respectively.

Immutability and thread safety

This class is immutable, and thus inherently thread-safe, if the converter given to the constructor is also immutable.
Since:
0.3
Version:
0.3
  • Field Details

    • serialVersionUID

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

      private static final EnumSet<FunctionProperty> PROPERTIES
      The function properties which can be preserved by this converter. We do not preserve ordering because we don't have a universal criterion for array comparisons. For example, we don't know how the user wants to handle arrays of different lengths, or null elements.
    • converter

      private final ObjectConverter<?,?> converter
      The converter for array elements. The source and target types shall be compatible with the array component types of <S> and <T> (this constraint cannot be expressed by JDK 7 parameterized types).
  • Constructor Details

    • ArrayConverter

      ArrayConverter(Class<S> sourceClass, Class<T> targetClass, ObjectConverter<?,?> converter)
      Creates a new converter for the given source and target classes.
      Parameters:
      sourceClass - the source class.
      targetClass - the target class.
      converter - the converter for array elements. The source and target types shall be the array component types of <S> and <T>.
  • Method Details

    • properties

      public Set<FunctionProperty> properties()
      Infers the properties of this converter from the properties of the elements converter.
      Returns:
      the manners in which source values are mapped to target values. May be an empty set, but never null.
    • apply

      public T apply(S source) throws UnconvertibleObjectException
      Converts the given array.
      Parameters:
      source - the object to convert, or null.
      Returns:
      the converted object, or null.
      Throws:
      UnconvertibleObjectException - if the given object is not an element of the function domain.