Class FractionConverter.FromInteger
java.lang.Object
org.apache.sis.internal.converter.FractionConverter.FromInteger
- All Implemented Interfaces:
Serializable,Function<Integer,,Fraction> ObjectConverter<Integer,Fraction>
- Enclosing class:
FractionConverter
The inverse of
FractionConverter.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final FractionConverter.FromIntegerThe unique instance of this converter. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreates a new fraction from the given integer.final booleanPerforms the comparisons documented inObject.equals(Object)with an additional check: if both objects to compare areSystemConverter, then also requires the two objects to be of the same class.Returns the source class given at construction time.Returns the target class given at construction time.final inthashCode()Returns a hash code value for thisClassPair.inverse()Default to non-invertible conversion.Returns the manner in which source values (S) are mapped to target values (T).protected final ObjectReturns the singleton instance on deserialization, if any.toString()Returns a string representation for this entry.unique()Returns an unique instance of this converter if one exists.
-
Field Details
-
INSTANCE
The unique instance of this converter.
-
-
Constructor Details
-
FromInteger
public FromInteger()Creates a new converter. Only one instance is enough, but this constructor needs to be public for allowing invocation byServiceLoader.
-
-
Method Details
-
unique
Returns an unique instance of this converter if one exists. If a converter already exists for the same source an target classes, then this converter is returned. Otherwise this converter is returned without being cached.- Returns:
- the unique instance, or
thisif no unique instance can be found. - See Also:
-
inverse
Default to non-invertible conversion. Must be overridden by subclasses that support inversions.- Specified by:
inversein interfaceObjectConverter<Integer,Fraction> - Returns:
- a converter for converting instances of T back to instances of S.
- See Also:
-
properties
Description copied from interface:ObjectConverterReturns the manner in which source values (S) are mapped to target values (T). Some possible function properties are:- Injective if no pair of S can produce
the same T value (e.g.: conversions from
IntegertoString). - Surjective if every values of T can be
created from one or many values of S (e.g.: conversions from
StringtoInteger). - Bijective if there is a one-to-one relationship between the S and T values.
- Order preserving if any sequence of
increasing S values (in the sense of
Comparable) is mapped to a sequence of increasing T values. - Order reversing if any sequence of
increasing S values (in the sense of
Comparable) is mapped to a sequence of decreasing T values.
ObjectConverter.apply(Object)method returnsnullfor unconvertible source values, then this properties set cannot containFunctionProperty.INJECTIVEbecause more than one source value could be converted to the samenulltarget value.- Returns:
- the manners in which source values are mapped to target values. May be an empty set, but never null.
- Injective if no pair of S can produce
the same T value (e.g.: conversions from
-
apply
Creates a new fraction from the given integer.- Parameters:
value- the integer to convert.- Returns:
- a fraction equals to the given integer.
-
getSourceClass
Returns the source class given at construction time.- Specified by:
getSourceClassin interfaceObjectConverter<S,T> - Returns:
- the type of objects to convert.
-
getTargetClass
Returns the target class given at construction time.- Specified by:
getTargetClassin interfaceObjectConverter<S,T> - Returns:
- the type of converted objects.
-
equals
Performs the comparisons documented inObject.equals(Object)with an additional check: if both objects to compare areSystemConverter, then also requires the two objects to be of the same class. We do that in order to differentiate the "ordinary" converters from theFallbackConverter.Implementation note
This is admittedly a little bit convolved. A cleaner approach would have been to not allow theConverterRegisterhash map to contain anything else thanClassPairkeys, 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 compareObjectConverters in a separated method, but users invokingequalson our system converters could be surprised.Our
equals(Object)definition have the following implications regarding the way to use theConverterRegistry.convertersmap:- 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 theMap.get(K)method. TheMapis "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 ofClassPairinstance (not a subclass).
- Parameters:
other- the object to compare with thisSystemConverter.- Returns:
trueif the given object is aClassPairor a converter of the same class thanthis, and both have the same source and target classes.
- When searching for a converter of the same class than the key (as in the
-
readResolve
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 thisClassPair. SeeObject.equals(Object)javadoc for information on the scope of this method. -
toString
Returns a string representation for this entry. Used for formatting error messages.
-