org.eclipse.ocl.examples.common.utils
Class ClassUtils

java.lang.Object
  extended by org.eclipse.ocl.examples.common.utils.ClassUtils

public class ClassUtils
extends java.lang.Object


Constructor Summary
ClassUtils()
           
 
Method Summary
static
<T> T
asClassOrNull(java.lang.Object object, java.lang.Class<T> requiredClass)
          Return object cast to requiredClass.
static
<T> T
asClassUnchecked(java.lang.Object object)
          Return object cast to T without a check.
static
<T> T
asClassUnchecked(java.lang.Object object, T requiredClassObject)
          Return object cast to T without a check.
static boolean equals(java.lang.Object left, java.lang.Object right)
          Return true if left and right are equal, avoiding an NPE by first using left==right before attempting left.equals(right).
static
<T> java.lang.Class<T>
getClass(T object)
          Return the fully typed class of an object.
static
<T> T
isInstanceOf(java.lang.Object anObject, java.lang.Class<T> aClass)
          Return anObject cast to aClass if type-safe or null otherwise.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassUtils

public ClassUtils()
Method Detail

asClassOrNull

public static <T> T asClassOrNull(java.lang.Object object,
                                  java.lang.Class<T> requiredClass)
Return object cast to requiredClass.

Parameters:
object - to cast.
requiredClass - to cast to.
Returns:
cast object or null

asClassUnchecked

public static <T> T asClassUnchecked(java.lang.Object object,
                                     T requiredClassObject)
Return object cast to T without a check.

This enables type-checking to be suppressed on a single expression term avoiding the need for suppressing unchecked warnings throughout the rest of an invoking method.

Use as: asClassUnchecked(object, (ArbitrarilyComplicatedType)null)

Type Parameters:
T - required type
Parameters:
object - to cast
requiredClassObject - dummy argument: use null
Returns:
cast type

asClassUnchecked

public static <T> T asClassUnchecked(java.lang.Object object)
Return object cast to T without a check.

This enables type-checking to suppressed on a single expression term avoiding the need for suppressing unchecked warnings throughout the rest of an invoking method.

Use as: ArbitrarilyComplicatedType castObject = asClassUnchecked(object);

Type Parameters:
T - required type
Parameters:
object - to cast
Returns:
cast type

equals

public static boolean equals(java.lang.Object left,
                             java.lang.Object right)
Return true if left and right are equal, avoiding an NPE by first using left==right before attempting left.equals(right).

Parameters:
left -
right -
Returns:
true if equals

getClass

public static <T> java.lang.Class<T> getClass(T object)
Return the fully typed class of an object.

Type Parameters:
T - type
Parameters:
object - the object
Returns:
the class

isInstanceOf

public static <T> T isInstanceOf(java.lang.Object anObject,
                                 java.lang.Class<T> aClass)
Return anObject cast to aClass if type-safe or null otherwise.

Parameters:
anObject - for which cast required
aClass - the type to which cast required
Returns:
the non-null cast of anObject if safe