Class ClassPair<S,T>
java.lang.Object
org.apache.sis.internal.converter.ClassPair<S,T>
- Type Parameters:
S
- the base type of source objects.T
- the base type of converted objects.
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
SystemConverter
Holds explicit
sourceClass
and targetClass
values. Used as key in a hash
map of converters. Also used as the base class for converters defined in this package.
The only direct subtype allowed is SystemConverter
.
No other direct subtype shall exist.
See equals(Object)
for an explanation.
Immutability and thread safety
This base class is immutable and thus inherently thread-safe.ClassPair
immutability is necessary
for ConverterRegistry
. Subclasses should also be immutable, but this requirement is not as strong
as for ClassPair
(because subclasses are not used as keys in hash map).- Since:
- 0.3
- Version:
- 0.3
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final long
For cross-version compatibility.The source class.The target class. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) final ObjectConverter<? super S,
? extends T> cast
(ObjectConverter<?, ?> converter) Casts the given converter to the source and target classes of thisClassPair
.boolean
Compares the given object with thisClassPair
for equality.final int
hashCode()
Returns a hash code value for thisClassPair
.Returns a key for the parent source, ornull
if none.toString()
Returns a string representation for this entry.
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor cross-version compatibility.- See Also:
-
sourceClass
The source class. -
targetClass
The target class.
-
-
Constructor Details
-
ClassPair
Creates an entry for the given source and target classes.- Parameters:
sourceClass
- the source class.targetClass
- the target class.
-
-
Method Details
-
parentSource
Returns a key for the parent source, ornull
if none. This method applies the following rules:- If
sourceClass
is a class and have a parent class, then returns a newClassPair
having that parent class as the source. - Otherwise if
sourceClass
is an interface extending at least one interface, then returns a newClassPair
having the first parent interface as the source. we select the first interface on the assumption that it is the mean one. - Otherwise (i.e. if there is no parent class or interface), returns
null
.
- Returns:
- a key for the parent source, or
null
.
- If
-
cast
Casts the given converter to the source and target classes of thisClassPair
. This method is not public because the checks are performed using assertions only. If this method was to goes public, the assertions would need to be replaced by unconditional checks.This method is used by
ConverterRegistry
after fetching a value from a hash map using thisClassPair
as a key. In this context, the cast should never fail (assuming that the converters do not change their source and target classes). -
equals
Compares the given object with thisClassPair
for equality. TwoClassPair
instances are considered equal if they have the same source and target classes, ignoring all other properties eventually defined in subclasses.This method is designed for use by
ConverterRegistry
asHashMap
keys. Its primary purpose is not to determine if two objects are converters doing the same conversions. However, theSystemConverter
subclass overrides this method with an additional safety check. -
hashCode
public final int hashCode()Returns a hash code value for thisClassPair
. Seeequals(Object)
javadoc for information on the scope of this method. -
toString
Returns a string representation for this entry. Used for formatting error messages.
-