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 sisutility
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 unconvertible source values,
then this properties set can not contain FunctionProperty.INJECTIVE
because more than one
source value could be converted to the same null
target value.Class<S> getSourceClass()
Class<T> getTargetClass()
T apply(S object) throws UnconvertibleObjectException
null
or throws an exception,
at implementation choice (except for injective functions, which must throw
an exception  see the class Javadoc for more discussion about function properties).
String
to Number
distinguish two kinds of
unconvertible objects:
null
value to be returned.""
value is unconvertible but nevertheless considered as part of the converter
domain, and is mapped to "no number". All other unparsable strings are considered outside the
converter domain.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–2017 The Apache Software Foundation. All rights reserved.