|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object cascading.tuple.coerce.Coercions
public final class Coercions
Coercions class is a helper class for managing primitive value coercions.
TheCoercions.Coerce
constants are the default coercions for the specified type.
To override the behavior, you must create a new CoercibleType
and assign it to the Fields
field position/name the custom behavior should apply.
Coercions are always used if Tuple
elements are accessed via a TupleEntry
wrapper instance.
CoercibleType
Nested Class Summary | |
---|---|
static class |
Coercions.Coerce<T>
|
Field Summary | |
---|---|
static Coercions.Coerce<BigDecimal> |
BIG_DECIMAL
|
static Coercions.Coerce<Boolean> |
BOOLEAN
|
static Coercions.Coerce<Boolean> |
BOOLEAN_OBJECT
|
static Coercions.Coerce<Character> |
CHARACTER
|
static Coercions.Coerce<Character> |
CHARACTER_OBJECT
|
static Map<Type,Coercions.Coerce> |
coercions
|
static Coercions.Coerce<Double> |
DOUBLE
|
static Coercions.Coerce<Double> |
DOUBLE_OBJECT
|
static Coercions.Coerce<Float> |
FLOAT
|
static Coercions.Coerce<Float> |
FLOAT_OBJECT
|
static Coercions.Coerce<Integer> |
INTEGER
|
static Coercions.Coerce<Integer> |
INTEGER_OBJECT
|
static Coercions.Coerce<Long> |
LONG
|
static Coercions.Coerce<Long> |
LONG_OBJECT
|
static Coercions.Coerce<Object> |
OBJECT
|
static Map<Class,Class> |
primitives
|
static Coercions.Coerce<Short> |
SHORT
|
static Coercions.Coerce<Short> |
SHORT_OBJECT
|
static Coercions.Coerce<String> |
STRING
|
static Map<String,Type> |
types
|
Constructor Summary | |
---|---|
Coercions()
|
Method Summary | ||
---|---|---|
static Class |
asClass(Type type)
Method asClass is a convenience method for casting the given type to a Class if an instance of Class
or to Object if not. |
|
static Class |
asNonPrimitive(Class type)
Returns the primitive wrapper fo the given type, if the given type represents a primitive, otherwise the type is returned. |
|
static Class[] |
asNonPrimitive(Class[] types)
|
|
static Type |
asType(String typeName)
Method asType is a convenience method for looking up a type name (like "int" or "java.lang.String"
to its corresponding Class or instance of CoercibleType. |
|
static Object |
coerce(CoercibleType currentType,
Object value,
Type type)
Method coerce will coerce the given value to the given type using the given CoercibleType . |
|
static
|
coerce(Object value,
Type type)
Method coerce will coerce the given value to the given type using any CoercibleType mapping available. |
|
static CoercibleType[] |
coercibleArray(Fields fields)
Method coercibleArray will return an array of CoercibleType instances based on the
given field type information. |
|
static CoercibleType[] |
coercibleArray(int size,
Type[] types)
Method coercibleArray will return an array of CoercibleType instances based on the
given type array. |
|
static CoercibleType |
coercibleTypeFor(Type type)
Method coercibleTypeFor returns the CoercibleType for the given Type instance. |
|
static Class[] |
getCanonicalTypes(Type[] types)
|
|
static String[] |
getTypeNames(Type[] types)
|
|
static Type[] |
getTypes(String[] names)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final Map<Type,Coercions.Coerce> coercions
public static final Map<String,Type> types
public static final Coercions.Coerce<Object> OBJECT
public static final Coercions.Coerce<String> STRING
public static final Coercions.Coerce<Character> CHARACTER
public static final Coercions.Coerce<Character> CHARACTER_OBJECT
public static final Coercions.Coerce<Short> SHORT
public static final Coercions.Coerce<Short> SHORT_OBJECT
public static final Coercions.Coerce<Integer> INTEGER
public static final Coercions.Coerce<Integer> INTEGER_OBJECT
public static final Coercions.Coerce<Double> DOUBLE
public static final Coercions.Coerce<Double> DOUBLE_OBJECT
public static final Coercions.Coerce<Long> LONG
public static final Coercions.Coerce<Long> LONG_OBJECT
public static final Coercions.Coerce<Float> FLOAT
public static final Coercions.Coerce<Float> FLOAT_OBJECT
public static final Coercions.Coerce<Boolean> BOOLEAN
public static final Coercions.Coerce<Boolean> BOOLEAN_OBJECT
public static final Coercions.Coerce<BigDecimal> BIG_DECIMAL
public static final Map<Class,Class> primitives
Constructor Detail |
---|
public Coercions()
Method Detail |
---|
public static Class asNonPrimitive(Class type)
type
- of type Class
public static Class[] asNonPrimitive(Class[] types)
public static CoercibleType coercibleTypeFor(Type type)
CoercibleType
for the given Type
instance.
If type is null, the OBJECT
CoercibleType is returned.
If type is an instance of CoercibleType, the given type is returned.
If no mapping is found, an IllegalStateException
will be thrown.
type
- the type to look up
public static final <T> T coerce(Object value, Type type)
CoercibleType
mapping available.
If no mapping is found, the OBJECT
CoercibleType will be use.
T
- the type expectedvalue
- the value to coerce, may be null.type
- the type to coerce to via any mapped CoercibleType
public static final Object coerce(CoercibleType currentType, Object value, Type type)
CoercibleType
.
If the given CoercibleType is equivalent (Object.equals(Object)
) to the given Type, the value
is returned. Note the Type can be itself a CoercibleType, so unnecessary work is prevented.
currentType
- the current Type of the value.value
- the value to coerce, may be null.type
- the type to coerce to via any mapped CoercibleType
public static CoercibleType[] coercibleArray(Fields fields)
CoercibleType
instances based on the
given field type information. Each element of Fields.getTypes()
will be used to lookup the corresponding CoercibleType.
fields
- an instance of Fields with optional type information.
public static CoercibleType[] coercibleArray(int size, Type[] types)
CoercibleType
instances based on the
given type array. Each element of the type array
will be used to lookup the corresponding CoercibleType.
size
- the size of the expected array, must equal types.length
if types != null
types
- an array of types to lookup
public static Class asClass(Type type)
Class
if an instance of Class
or to Object
if not.
type
- of type Type
public static Type asType(String typeName)
"int"
or "java.lang.String"
to its corresponding Class
or instance of CoercibleType.
If the name is not in the types
map, the classname will be loaded from the current ClassLoader
.
typeName
- a string class or type nam.
public static String[] getTypeNames(Type[] types)
public static Type[] getTypes(String[] names)
public static Class[] getCanonicalTypes(Type[] types)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |