public class ClassUtil extends Object
Constructor and Description |
---|
ClassUtil() |
Modifier and Type | Method and Description |
---|---|
static <T> T |
asClassOrNull(Object object,
Class<T> requiredClass)
Return object cast to requiredClass.
|
static <T> T |
asClassUnchecked(Object object)
Return object cast to T without a check.
|
static <T> T |
asClassUnchecked(Object object,
T requiredClassObject)
Return object cast to T without a check.
|
static EAnnotation |
basicGetMetamodelAnnotation(EPackage ePackage)
Return the DomainConstants.AS_METAMODEL_ANNOTATION_SOURCE for ePackage or null if none.
|
static <T> Iterator<T> |
emptyIterator()
Return an iterator over no content.
|
static <T> T |
getAdapter(Class<T> adapterClass,
List<Adapter> eAdapters) |
static <T> T |
getAdapter(Class<T> adapterClass,
Notifier notifier) |
static <T> T |
getAdapter(IAdaptable iAdaptable,
Class<T> adapterClass)
Return the non-null adapterClass if iAdfaptable has an adapterClass adapter.
|
static <T> Class<T> |
getClass(T object)
Return the fully typed class of an object.
|
static EAnnotation |
getEAnnotation(EModelElement eModelElement,
String sourceURI)
Return the sourceURI annotation of eModelElement, creating and installing it if required.
|
static EAnnotation |
getMetamodelAnnotation(EPackage ePackage)
Return the DomainConstants.AS_METAMODEL_ANNOTATION_SOURCE for ePackage, creating it if needed.
|
static <T> T |
isInstanceOf(Object anObject,
Class<T> aClass)
Return anObject cast to aClass if type-safe or null otherwise.
|
static boolean |
isRegistered(Resource resource)
Return true if resource is a registered resource; hosting a compile Java model.
|
static <T> T |
nonNull(T aT)
Check for an in appropriate program state.
|
static <T> T |
nonNullEMF(T aT)
Return aT, checking the assertion that this call would not be necessary if EMF had comprehensive @NonNull annotations.
|
static <T> T |
nonNullModel(T aT)
Check for an in appropriate model state which should have been detected by a model validation pass.
|
static <T> T |
nonNullPivot(T aT)
Return aT, checking the assertion that this call would not be necessary if the Pivot model was guaranteed to be valid.
|
static <T> T |
nonNullState(T aT)
Check for an in appropriate program state.
|
static <T> <any> |
nullFree(<any> nullFreeList) |
static <T> List<T> |
nullFree(List<T> nullFreeList)
Cast a logically nullFreeList such as EMF collection to a declared null free list.
|
static <T extends Comparable<T>> |
safeCompareTo(T object,
T otherObject)
Safely determines the relative order of
object and
otherObject , i.e. |
static boolean |
safeEquals(Object object,
Object otherObject)
Safely determines whether
object equals
otherObject , i.e. |
static <T> void |
sort(List<? extends T> aList,
Comparator<T> comparator)
Sort aList using comparator, using an Ecollections.sort if aLIst is an EList.
|
static String |
toString(Object anObject)
Deprecated.
String.valueOf()now annotated to be @NonNull
|
public static <T> T asClassOrNull(Object object, Class<T> requiredClass)
object
- to cast.requiredClass
- to cast to.public static <T> T asClassUnchecked(Object object, T requiredClassObject)
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)
T
- required typeobject
- to castrequiredClassObject
- dummy argument: use nullpublic static <T> T asClassUnchecked(Object object)
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);
T
- required typeobject
- to castpublic static EAnnotation basicGetMetamodelAnnotation(EPackage ePackage)
public static <T> Iterator<T> emptyIterator()
public static <T> T getAdapter(IAdaptable iAdaptable, Class<T> adapterClass)
public static <T> T getAdapter(Class<T> adapterClass, Notifier notifier)
public static <T> Class<T> getClass(T object)
T
- typeobject
- the objectpublic static EAnnotation getEAnnotation(EModelElement eModelElement, String sourceURI)
public static EAnnotation getMetamodelAnnotation(EPackage ePackage)
public static <T> T isInstanceOf(Object anObject, Class<T> aClass)
anObject
- for which cast requiredaClass
- the type to which cast requiredpublic static boolean isRegistered(Resource resource)
public static <T> T nonNull(T aT)
If the inappropriate state really cannot happen, an assertion should be used instead to avoid non-debug run-time cost.
Return aT, throwing an IllegalStateException if null.
public static <T> T nonNullEMF(T aT)
public static <T> T nonNullModel(T aT)
Return aT, checking the assertion that this call would not be necessary if the Ecore model was guaranteed to be valid.
public static <T> T nonNullPivot(T aT)
public static <T> T nonNullState(T aT)
If the inappropriate state really cannot happen, an assertion should be used instead to avoid non-debug run-time cost.
Return aT, throwing an IllegalStateException if null.
public static <T> List<T> nullFree(List<T> nullFreeList)
public static <T> <any> nullFree(<any> nullFreeList)
public static <T extends Comparable<T>> int safeCompareTo(T object, T otherObject)
object
and
otherObject
, i.e. without throwing an exception if
object
is null
.public static boolean safeEquals(Object object, Object otherObject)
object
equals
otherObject
, i.e. without throwing an exception if
object
is null
.object
- The first object to compare.otherObject
- The second object to compare.true
if object
equals
otherObject
; false
otherwise.public static <T> void sort(List<? extends T> aList, Comparator<T> comparator)
@Deprecated public static String toString(Object anObject)
Copyright © 2005, 2018 IBM Corporation and others. All Rights Reserved.