Brooklyn

brooklyn.util.flags
[Java] Class TypeCoercions

java.lang.Object
  brooklyn.util.flags.TypeCoercions

public class TypeCoercions

Field Summary
static java.util.Map BOXED_TO_UNBOXED_TYPES

static java.util.Map UNBOXED_TO_BOXED_TYPES

 
Method Summary
static java.lang.Object castPrimitive(java.lang.Object value, java.lang.Class targetType)

Sometimes need to explicitly cast primitives, rather than relying on Java casting.

static java.lang.Object coerce(java.lang.Object value, java.lang.Class targetType)

attempts to coerce 'value' to 'targetType', using a variety of strategies, including looking at:

static java.lang.Object getMatchingConstructor(java.lang.Class target, java.lang.Object... arguments)

for automatic conversion

static java.lang.String getVerySimpleName(java.lang.Class c)

returns the simple class name, and for any inner class the portion after the $

static boolean isPrimitiveOrBoxer(java.lang.Class type)

static void registerAdapter(java.lang.Class sourceType, java.lang.Class targetType, Function fn)

static java.lang.Object stringToPrimitive(java.lang.String value, java.lang.Class targetType)

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Field Detail

BOXED_TO_UNBOXED_TYPES

public static final java.util.Map BOXED_TO_UNBOXED_TYPES


UNBOXED_TO_BOXED_TYPES

public static final java.util.Map UNBOXED_TO_BOXED_TYPES


 
Method Detail

castPrimitive

@SuppressWarnings("unchecked")
public static java.lang.Object castPrimitive(java.lang.Object value, java.lang.Class targetType)
Sometimes need to explicitly cast primitives, rather than relying on Java casting. For example, when using generics then type-erasure means it doesn't actually cast, which causes tests to fail with 0 != 0.0


coerce

@SuppressWarnings({ "unchecked", "rawtypes" })
public static java.lang.Object coerce(java.lang.Object value, java.lang.Class targetType)
attempts to coerce 'value' to 'targetType', using a variety of strategies, including looking at: value.asTargetType() static TargetType.fromType(value) where value instanceof Type value.targetTypeValue() //handy for primitives registeredAdapters.get(targetType).findFirst({ k,v -> k.isInstance(value) }, { k,v -> v.apply(value) })


getMatchingConstructor

public static java.lang.Object getMatchingConstructor(java.lang.Class target, java.lang.Object... arguments)
for automatic conversion


getVerySimpleName

public static java.lang.String getVerySimpleName(java.lang.Class c)
returns the simple class name, and for any inner class the portion after the $


isPrimitiveOrBoxer

@SuppressWarnings("unchecked")
public static boolean isPrimitiveOrBoxer(java.lang.Class type)


registerAdapter

public static void registerAdapter(java.lang.Class sourceType, java.lang.Class targetType, Function fn)


stringToPrimitive

@SuppressWarnings("unchecked")
public static java.lang.Object stringToPrimitive(java.lang.String value, java.lang.Class targetType)


 

Brooklyn Multi-Cloud Application Management Platform
brooklyncentral.github.com. Apache License. © 2012.