S
- The type of objects to convert.T
- The type of converted objects.public interface ObjectConverter<S,T>
extends Function<S,T>
ObjectConverter
actually converts
the values rather than the type.
The main method of this interface is apply(Object)
, which receives an object of type
S and returns an object of type T. The set of all S values for which
apply(S)
does not throw UnconvertibleObjectException
is called the domain
of this function, regardless of whether the T result is null
or not.
properties()
enumeration, together with the getSourceClass()
and
getTargetClass()
methods. Some possible function properties are:
Integer
to String
).String
to
Integer
).Comparable
) is mapped to a
sequence of increasing T values.Comparable
) is mapped to
a sequence of decreasing T values.Range
objects.
For example if the converter reverses the value ordering (e.g. reverses the sign of numerical values), then the
minimum and maximum values in each Range
instance need to be interchanged. If the ordering is not preserved
at all (neither directly or reversed), as for example in the conversion from Number
to String
, then
we can not convert ranges at all.apply(S)
returns null
for unconvertible objects, then this ObjectConverter
can not be declared injective because more than one S value can produce the same
T value (namely null
).apply(S)
throws an exception for unconvertible objects, then this ObjectConverter
can be declared as an injective function if the other values meet the criteria.
ObjectConverters
Defined in the sis-utility
module
Modifier and Type | Method and Description |
---|---|
T |
apply(S object)
Converts the given object from the source type S to the target type T.
|
Class<S> |
getSourceClass()
Returns the type of objects to convert.
|
Class<T> |
getTargetClass()
Returns the type of converted objects.
|
ObjectConverter<T,S> |
inverse()
Returns a converter capable to convert instances of T back to instances of
S.
|
Set<FunctionProperty> |
properties()
Returns the manner in which source values (S) are mapped to target values
(T).
|
Set<FunctionProperty> properties()
Integer
to String
).String
to
Integer
).Comparable
) is mapped to a
sequence of increasing T values.Comparable
) is mapped to
a sequence of decreasing T values.apply(Object)
method returns null
for any non-convertible
source value, then this properties set can not contain the FunctionProperty.INJECTIVE
value. See class javadoc for more discussion.Class<S> getSourceClass()
Class<T> getTargetClass()
T apply(S object) throws UnconvertibleObjectException
null
or
throws an exception, at implementation choice. Note that this choice may affect the set of
function properties - see the class Javadoc for more discussion.apply
in interface Function<S,T>
object
- The object to convert, or null
.null
.UnconvertibleObjectException
- If the given object is not an element of the function domain.ObjectConverter<T,S> inverse() throws UnsupportedOperationException
if (converter.properties().contains(FunctionProperty.INVERTIBLE)) { // Call to converter.inverse() is allowed here. }
UnsupportedOperationException
- If this converter is not invertible.FunctionProperty.INVERTIBLE
Copyright © 2010–2015 The Apache Software Foundation. All rights reserved.