## cascading.tuple.coerce
Class Coercions

    java.lang.Object
      cascading.tuple.coerce.Coercions

    public final class Coercions

extends Object

Coercions class is a helper class for managing primitive value coercions.

The `Coercions.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.

See Also:
  `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

`<T> T`

`

`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

### coercions

    public static final Map<Type,Coercions.Coerce> coercions

### types

    public static final Map<String,Type> types

### OBJECT

    public static final Coercions.Coerce<Object> OBJECT

### STRING

    public static final Coercions.Coerce<String> STRING

### CHARACTER

    public static final Coercions.Coerce<Character> CHARACTER

### CHARACTER_OBJECT

    public static final Coercions.Coerce<Character> CHARACTER_OBJECT

### SHORT

    public static final Coercions.Coerce<Short> SHORT

### SHORT_OBJECT

    public static final Coercions.Coerce<Short> SHORT_OBJECT

### INTEGER

    public static final Coercions.Coerce<Integer> INTEGER

### INTEGER_OBJECT

    public static final Coercions.Coerce<Integer> INTEGER_OBJECT

### DOUBLE

    public static final Coercions.Coerce<Double> DOUBLE

### DOUBLE_OBJECT

    public static final Coercions.Coerce<Double> DOUBLE_OBJECT

### LONG

    public static final Coercions.Coerce<Long> LONG

### LONG_OBJECT

    public static final Coercions.Coerce<Long> LONG_OBJECT

### FLOAT

    public static final Coercions.Coerce<Float> FLOAT

### FLOAT_OBJECT

    public static final Coercions.Coerce<Float> FLOAT_OBJECT

### BOOLEAN

    public static final Coercions.Coerce<Boolean> BOOLEAN

### BOOLEAN_OBJECT

    public static final Coercions.Coerce<Boolean> BOOLEAN_OBJECT

### BIG_DECIMAL

    public static final Coercions.Coerce<BigDecimal> BIG_DECIMAL

### primitives

    public static final Map<Class,Class> primitives

Constructor Detail

### Coercions

    public Coercions()

Method Detail

### asNonPrimitive

    public 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.

  Parameters:
    `type` - of type Class
  Returns:
    a Class

### asNonPrimitive

    public static Class[] asNonPrimitive(Class[] types)

### coercibleTypeFor

    public static CoercibleType coercibleTypeFor(Type type)

  Method coercibleTypeFor returns the `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.

  Parameters:
    `type` - the type to look up
  Returns:
    a CoercibleType for the given type

### coerce

    public static final <T> T coerce(Object value,
                                     Type type)

  Method coerce will coerce the given value to the given type using any `CoercibleType` mapping available.

  If no mapping is found, the `OBJECT` CoercibleType will be use.

  Type Parameters:
    `T` - the type expected
  Parameters:
    `value` - the value to coerce, may be null.
    `type` - the type to coerce to via any mapped CoercibleType
  Returns:
    the coerced value

### coerce

    public static final Object coerce(CoercibleType currentType,
                                      Object value,
                                      Type type)

  Method coerce will coerce the given value to the given type using the given `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.

  Parameters:
    `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
  Returns:
    the coerced value

### coercibleArray

    public static CoercibleType[] coercibleArray(Fields fields)

  Method coercibleArray will return an array of `CoercibleType` instances based on the given field type information. Each element of `Fields.getTypes()` will be used to lookup the corresponding CoercibleType.

  Parameters:
    `fields` - an instance of Fields with optional type information.
  Returns:
    array of CoercibleType

### coercibleArray

    public static CoercibleType[] coercibleArray(int size,
                                                 Type[] types)

  Method coercibleArray will return an array of `CoercibleType` instances based on the given type array. Each element of the type array will be used to lookup the corresponding CoercibleType.

  Parameters:
    `size` - the size of the expected array, must equal `types.length` if `types != null`
    `types` - an array of types to lookup
  Returns:
    array of CoercibleType

### asClass

    public 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.

  Parameters:
    `type` - of type Type
  Returns:
    of type Class

### asType

    public 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.

  If the name is not in the `types` map, the classname will be loaded from the current `ClassLoader`.

  Parameters:
    `typeName` - a string class or type nam.
  Returns:
    an instance of the requested type class.

### getTypeNames

    public static String[] getTypeNames(Type[] types)

### getTypes

    public static Type[] getTypes(String[] names)

### getCanonicalTypes

    public static Class[] getCanonicalTypes(Type[] types)

Copyright © 2007-2014 Concurrent, Inc. All Rights Reserved.