Class ObjectToString<S>
java.lang.Object
org.apache.sis.internal.converter.ClassPair<S,T>
org.apache.sis.internal.converter.SystemConverter<S,String>
org.apache.sis.internal.converter.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
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final class
ObjectToString.CodeList<S extends org.opengis.util.CodeList<S>>
Specialized instance forCodeList
.(package private) static final class
ObjectToString.Enum<S extends Enum<S>>
Specialized instance forEnum
. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final SystemConverter<String,
S> The inverse converter specified at construction time.private static final long
For cross-version compatibility.Fields inherited from class org.apache.sis.internal.converter.ClassPair
sourceClass, targetClass
-
Constructor Summary
ConstructorsConstructorDescriptionObjectToString
(Class<S> sourceClass, SystemConverter<String, S> inverse) Creates a new converter from the given type of objects toString
instances. -
Method Summary
Modifier and TypeMethodDescriptionConverts the given number to a string.final ObjectConverter<String,
S> inverse()
Returns the inverse given at construction time.Declares this converter as injective on the assumption that all instances of the source class produce distinct string representations.final ObjectConverter<S,
String> unique()
Returns the singleton instance on deserialization, if any.Methods inherited from class org.apache.sis.internal.converter.SystemConverter
bijective, equals, formatErrorMessage, getSourceClass, getTargetClass, readResolve
Methods inherited from class org.apache.sis.internal.converter.ClassPair
cast, hashCode, parentSource, toString
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor cross-version compatibility.- See Also:
-
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 toString
instances.
-
-
Method Details
-
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
Converts the given number to a string.- Parameters:
source
- the object to convert, ornull
.- Returns:
- the converted object, or
null
.
-
inverse
Returns the inverse given at construction time.- Specified by:
inverse
in interfaceObjectConverter<S,
String> - Overrides:
inverse
in classSystemConverter<S,
String> - Returns:
- a converter for converting instances of T back to instances of S.
- See Also:
-
unique
Returns the singleton instance on deserialization, if any.- Overrides:
unique
in classSystemConverter<S,
String> - Returns:
- the unique instance, or
this
if no unique instance can be found. - See Also:
-