Class ObjectToString<S>

Type Parameters:
S - the source type.
All Implemented Interfaces:
Serializable, Function<S,String>, ObjectConverter<S,String>
Direct Known Subclasses:
ObjectToString.CodeList, ObjectToString.Enum

class ObjectToString<S> extends SystemConverter<S,String>
Handles conversions from arbitrary objects to String. This converter is suitable to any object for which the ClassPair.toString() method is sufficient.

Some predefined unique instances of ObjectToString are available by the following pattern:

Immutability and thread safety

This base class and all inner classes are immutable, and thus inherently thread-safe.
Since:
0.3
Version:
1.0
  • Field Details

    • serialVersionUID

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

      private final SystemConverter<String,S> inverse
      The inverse converter specified at construction time.
  • Constructor Details

    • ObjectToString

      ObjectToString(Class<S> sourceClass, SystemConverter<String,S> inverse)
      Creates a new converter from the given type of objects to String instances.
  • Method Details

    • properties

      public Set<FunctionProperty> properties()
      Declares this converter as injective on the assumption that all instances of the source class produce distinct string representations.
      Returns:
      the manners in which source values are mapped to target values. May be an empty set, but never null.
    • apply

      public String apply(S source)
      Converts the given number to a string.
      Parameters:
      source - the object to convert, or null.
      Returns:
      the converted object, or null.
    • inverse

      public final ObjectConverter<String,S> inverse()
      Returns the inverse given at construction time.
      Specified by:
      inverse in interface ObjectConverter<S,String>
      Overrides:
      inverse in class SystemConverter<S,String>
      Returns:
      a converter for converting instances of T back to instances of S.
      See Also:
    • unique

      public final ObjectConverter<S,String> unique()
      Returns the singleton instance on deserialization, if any.
      Overrides:
      unique in class SystemConverter<S,String>
      Returns:
      the unique instance, or this if no unique instance can be found.
      See Also: