Class AngleConverter.Inverse

java.lang.Object
org.apache.sis.internal.converter.AngleConverter.Inverse
All Implemented Interfaces:
Serializable, Function<Double,Angle>, ObjectConverter<Double,Angle>
Enclosing class:
AngleConverter

public static final class AngleConverter.Inverse extends Object
The inverse of AngleConverter.

Thread safety

This class is immutable, and thus inherently thread-safe.
See Also:
  • Constructor Details

    • Inverse

      public Inverse()
      Creates a new converter.
  • Method Details

    • unique

      public ObjectConverter<Double,Angle> unique()
      Returns the unique instance.
      Returns:
      the unique instance.
      See Also:
      • SystemConverter.unique()
    • inverse

      public ObjectConverter<Angle,Double> inverse()
      Returns the inverse converter.
      Specified by:
      inverse in interface ObjectConverter<Double,Angle>
      Returns:
      AngleConverter.
      See Also:
    • properties

      public Set<FunctionProperty> properties()
      Declares that the converter is bijective.
      Returns:
      injective and surjective function properties (among others).
    • apply

      public Angle apply(Double object)
      Converts the given angle.
      Parameters:
      object - angular value in degrees.
      Returns:
      the angle object for the given value.
    • getSourceClass

      public final Class<Double> getSourceClass()
      Returns the source class given at construction time.
      Specified by:
      getSourceClass in interface ObjectConverter<S,T>
      Returns:
      the type of objects to convert.
    • getTargetClass

      public final Class<Angle> getTargetClass()
      Returns the target class given at construction time.
      Specified by:
      getTargetClass in interface ObjectConverter<S,T>
      Returns:
      the type of converted objects.
    • equals

      public final boolean equals(Object other)
      Performs the comparisons documented in Object.equals(Object) with an additional check: if both objects to compare are SystemConverter, then also requires the two objects to be of the same class. We do that in order to differentiate the "ordinary" converters from the FallbackConverter.

      Implementation note

      This is admittedly a little bit convolved. A cleaner approach would have been to not allow the ConverterRegister hash map to contain anything else than ClassPair keys, but the current strategy of using the same instance for keys and values reduces a little bit the number of objects to create in the JVM. Another cleaner approach would have been to compare ObjectConverters in a separated method, but users invoking equals on our system converters could be surprised.

      Our equals(Object) definition have the following implications regarding the way to use the ConverterRegistry.converters map:

      • When searching for a converter of the same class than the key (as in the ConverterRegistry.findEquals(SystemConverter) method), then there is no restriction on the key that can be given to the Map.get(K) method. The Map is "normal".
      • When searching for a converter for a pair of source and target classes (as in ConverterRegistry.find(Class, Class)), the key shall be an instance of ClassPair instance (not a subclass).
      Parameters:
      other - the object to compare with this SystemConverter.
      Returns:
      true if the given object is a ClassPair or a converter of the same class than this, and both have the same source and target classes.
    • readResolve

      protected final Object readResolve() throws ObjectStreamException
      Returns the singleton instance on deserialization, if any. If no instance already exist in the virtual machine, we do not cache the instance (for now) for security reasons.
      Returns:
      the object to use after deserialization.
      Throws:
      ObjectStreamException - if the serialized object defines an unknown data type.
    • hashCode

      public final int hashCode()
      Returns a hash code value for this ClassPair. See Object.equals(Object) javadoc for information on the scope of this method.
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Returns a string representation for this entry. Used for formatting error messages.
      Overrides:
      toString in class Object