Package eu.simuline.octave.type.cast
Class Cast
- java.lang.Object
-
- eu.simuline.octave.type.cast.Cast
-
public final class Cast extends Object
Helper class for the auto cast functionality. Currently, only a single caster is implemented:DoubleToComplexCaster
but this can be dynamically extended.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
Cast.ClassPair<F,T>
Represents a pair of classes, essentially a cast from one to the other class.
-
Field Summary
Fields Modifier and Type Field Description private static Map<Cast.ClassPair<?,?>,Caster<?,?>>
casterMap
Maps a class pair to an according caster.private static int
PRIME
-
Constructor Summary
Constructors Modifier Constructor Description private
Cast()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <F extends OctaveObject,T extends OctaveObject>
Tcast(Class<T> toClass, F from)
Cast and transform the object.private static <F extends OctaveObject,T extends OctaveObject>
Caster<F,T>casterMapGet(Cast.ClassPair<F,T> cp)
private static void
initIfNecessary()
private static <F,T>
voidregister(Caster<F,T> caster)
private static <F> Class<F>
unsafeGetClass(F from)
-
-
-
Field Detail
-
PRIME
private static final int PRIME
- See Also:
- Constant Field Values
-
casterMap
private static Map<Cast.ClassPair<?,?>,Caster<?,?>> casterMap
Maps a class pair to an according caster.
-
-
Method Detail
-
initIfNecessary
private static void initIfNecessary()
-
register
private static <F,T> void register(Caster<F,T> caster)
-
cast
public static <F extends OctaveObject,T extends OctaveObject> T cast(Class<T> toClass, F from)
Cast and transform the object.- Type Parameters:
F
- the class type of the objectfrom
to be cast.T
- the target classtoClass
as a type variable.- Parameters:
toClass
- the classfrom
from
- the object to be cast ornull
.- Returns:
- The object of type
toClass
which is by castingfrom
ornull
forfrom == null
.
-
unsafeGetClass
private static <F> Class<F> unsafeGetClass(F from)
-
casterMapGet
private static <F extends OctaveObject,T extends OctaveObject> Caster<F,T> casterMapGet(Cast.ClassPair<F,T> cp)
-
-