public abstract class Caster extends Object
cast(java.lang.Object): it performs the transformation.
A simple example would be to transform Doubles
into eu.simuline.arithmetics.left2right.FPNumbers.
Another example is given by BASIC_TYPES.
It is the foundation to transform arrays of elementary types
to arrays of their wrappers and the other way round
such as double[][] and Double[][].
Casters may be used to transform descriptors of objects into these objects.
A snippet of typical implementation for the cast(java.lang.Object)-method
would be "return new ExaClass(descriptor)" in this case.
| Modifier and Type | Class and Description |
|---|---|
(package private) static class |
Caster.Trivial
This is a trivial caster.
|
| Modifier and Type | Field and Description |
|---|---|
static Caster |
ASSIGNEMENT_COMPATIBLE
A trivial caster for which compatibility
is assignment compatibility.
|
static Caster |
BASIC_TYPES
A trivial caster for which compatibility
is assignment compatibility
up to wrapping and unwrapping of primitive types.
|
static Caster |
STRICT
A trivial caster for which compatibility
is equality of classes.
|
| Constructor and Description |
|---|
Caster() |
| Modifier and Type | Method and Description |
|---|---|
abstract boolean |
areCompatible(Class<?> cls,
Object obj)
Decides whether the given class and object
are compatible with respect to this caster.
|
abstract Object |
cast(Object obj)
The return value
cast(obj)
(which may well be null),
may be casted to class cls
if areCompatible(java.lang.Class<?>, java.lang.Object) returns true. |
public static final Caster ASSIGNEMENT_COMPATIBLE
public static final Caster STRICT
public static final Caster BASIC_TYPES
CollectionsExt.recToArray(Object,Class)
as a special case of
CollectionsExt.recToArray(Object,Class,Caster).public abstract boolean areCompatible(Class<?> cls, Object obj)
cls - a Class.obj - an Object.true if and only if either of the following holds:
cast(obj) may be casted to cls, i.e.
if either cast(obj) == null
(which is the case for obj == null)
or (sequentially) cls.isInstance(cast(obj)).
cls is a basic type,
cast(obj) != null and (sequentially)
cast(obj).getClass()
is the corresponding wrapper type.
BasicTypesCompatibilityChecker.areCompatible(java.lang.Class<?>, java.lang.Object)public abstract Object cast(Object obj)
cast(obj)
(which may well be null),
may be casted to class cls
if areCompatible(java.lang.Class<?>, java.lang.Object) returns true.obj - an arbitrary Object or even null.null for obj == null.
null if obj != null
but targetClass(obj.getClass()) == null. ****
null again
or an instance of targetClass(obj.getClass())
Copyright © 2012–2018 Simuline Organization (l2r). All rights reserved.