cascading.tuple.coerce

## Class Coercions

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

    public final class Coercions
    extends java.lang.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

Nested Classes
`static class` `Coercions.Coerce<T>`

### Field Summary

Fields
`static Coercions.Coerce<java.math.BigDecimal>` `BIG_DECIMAL`
`static Coercions.Coerce<java.lang.Boolean>` `BOOLEAN`
`static Coercions.Coerce<java.lang.Boolean>` `BOOLEAN_OBJECT`
`static Coercions.Coerce<java.lang.Character>` `CHARACTER`
`static Coercions.Coerce<java.lang.Character>` `CHARACTER_OBJECT`
`static java.util.Map<java.lang.reflect.Type,Coercions.Coerce>` `coercions`
`static Coercions.Coerce<java.lang.Double>` `DOUBLE`
`static Coercions.Coerce<java.lang.Double>` `DOUBLE_OBJECT`
`static Coercions.Coerce<java.lang.Float>` `FLOAT`
`static Coercions.Coerce<java.lang.Float>` `FLOAT_OBJECT`
`static Coercions.Coerce<java.lang.Integer>` `INTEGER`
`static Coercions.Coerce<java.lang.Integer>` `INTEGER_OBJECT`
`static Coercions.Coerce<java.lang.Long>` `LONG`
`static Coercions.Coerce<java.lang.Long>` `LONG_OBJECT`
`static Coercions.Coerce<java.lang.Object>` `OBJECT`
`static java.util.Map<java.lang.Class,java.lang.Class>` `primitives`
`static Coercions.Coerce<java.lang.Short>` `SHORT`
`static Coercions.Coerce<java.lang.Short>` `SHORT_OBJECT`
`static Coercions.Coerce<java.lang.String>` `STRING`
`static java.util.Map<java.lang.String,java.lang.reflect.Type>` `types`

### Constructor Summary

Constructors
Constructor and Description
`Coercions()`

### Method Summary

Methods
`static java.lang.Class` `asClass(java.lang.reflect.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 java.lang.Class` `asNonPrimitive(java.lang.Class type)` Returns the primitive wrapper fo the given type, if the given type represents a primitive, otherwise the type is returned.
`static java.lang.Class[]` `asNonPrimitive(java.lang.Class[] types)`
`static java.lang.reflect.Type` `asType(java.lang.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 java.lang.Object` `coerce(CoercibleType currentType, java.lang.Object value, java.lang.reflect.Type type)` Method coerce will coerce the given value to the given type using the given `CoercibleType`.
`static <T> T` `coerce(java.lang.Object value, java.lang.reflect.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, java.lang.reflect.Type[] types)` Method coercibleArray will return an array of `CoercibleType` instances based on the given type array.
`static CoercibleType` `coercibleTypeFor(java.lang.reflect.Type type)` Method coercibleTypeFor returns the `CoercibleType` for the given `Type` instance.
`static java.lang.Class[]` `getCanonicalTypes(java.lang.reflect.Type[] types)`
`static java.lang.String[]` `getTypeNames(java.lang.reflect.Type[] types)`
`static java.lang.reflect.Type[]` `getTypes(java.lang.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 java.util.Map<java.lang.reflect.Type,Coercions.Coerce> coercions

#### types

    public static final java.util.Map<java.lang.String,java.lang.reflect.Type> types

#### OBJECT

    public static final Coercions.Coerce<java.lang.Object> OBJECT

#### STRING

    public static final Coercions.Coerce<java.lang.String> STRING

#### CHARACTER

    public static final Coercions.Coerce<java.lang.Character> CHARACTER

#### CHARACTER_OBJECT

    public static final Coercions.Coerce<java.lang.Character> CHARACTER_OBJECT

#### SHORT

    public static final Coercions.Coerce<java.lang.Short> SHORT

#### SHORT_OBJECT

    public static final Coercions.Coerce<java.lang.Short> SHORT_OBJECT

#### INTEGER

    public static final Coercions.Coerce<java.lang.Integer> INTEGER

#### INTEGER_OBJECT

    public static final Coercions.Coerce<java.lang.Integer> INTEGER_OBJECT

#### DOUBLE

    public static final Coercions.Coerce<java.lang.Double> DOUBLE

#### DOUBLE_OBJECT

    public static final Coercions.Coerce<java.lang.Double> DOUBLE_OBJECT

#### LONG

    public static final Coercions.Coerce<java.lang.Long> LONG

#### LONG_OBJECT

    public static final Coercions.Coerce<java.lang.Long> LONG_OBJECT

#### FLOAT

    public static final Coercions.Coerce<java.lang.Float> FLOAT

#### FLOAT_OBJECT

    public static final Coercions.Coerce<java.lang.Float> FLOAT_OBJECT

#### BOOLEAN

    public static final Coercions.Coerce<java.lang.Boolean> BOOLEAN

#### BOOLEAN_OBJECT

    public static final Coercions.Coerce<java.lang.Boolean> BOOLEAN_OBJECT

#### BIG_DECIMAL

    public static final Coercions.Coerce<java.math.BigDecimal> BIG_DECIMAL

#### primitives

    public static final java.util.Map<java.lang.Class,java.lang.Class> primitives

### Constructor Detail

#### Coercions

    public Coercions()

### Method Detail

#### asNonPrimitive

    public static java.lang.Class asNonPrimitive(java.lang.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 java.lang.Class[] asNonPrimitive(java.lang.Class[] types)

#### coercibleTypeFor

    public static CoercibleType coercibleTypeFor(java.lang.reflect.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(java.lang.Object value,
               java.lang.reflect.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 java.lang.Object coerce(CoercibleType currentType,
                          java.lang.Object value,
                          java.lang.reflect.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,
                                 java.lang.reflect.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 java.lang.Class asClass(java.lang.reflect.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 java.lang.reflect.Type asType(java.lang.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 java.lang.String[] getTypeNames(java.lang.reflect.Type[] types)

#### getTypes

    public static java.lang.reflect.Type[] getTypes(java.lang.String[] names)

#### getCanonicalTypes

    public static java.lang.Class[] getCanonicalTypes(java.lang.reflect.Type[] types)