public class ClassUtil
extends java.lang.Object
Constructor and Description |
---|
ClassUtil() |
Modifier and Type | Method and Description |
---|---|
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 org.eclipse.emf.ecore.EAnnotation |
basicGetMetamodelAnnotation(org.eclipse.emf.ecore.EPackage ePackage)
Return the DomainConstants.AS_METAMODEL_ANNOTATION_SOURCE for ePackage or null if none.
|
static <T> T |
getAdapter(java.lang.Class<T> adapterClass,
java.util.List<org.eclipse.emf.common.notify.Adapter> eAdapters) |
static <T> T |
getAdapter(java.lang.Class<T> adapterClass,
org.eclipse.emf.common.notify.Notifier notifier) |
static <T> T |
getAdapter(org.eclipse.core.runtime.IAdaptable iAdaptable,
java.lang.Class<T> adapterClass)
Return the non-null adapterClass if iAdfaptable has an adapterClass adapter.
|
static <T> java.lang.Class<T> |
getClass(T object)
Return the fully typed class of an object.
|
static org.eclipse.emf.ecore.EAnnotation |
getEAnnotation(org.eclipse.emf.ecore.EModelElement eModelElement,
java.lang.String sourceURI)
Return the sourceURI annotation of eModelElement, creating and installing it if required.
|
static org.eclipse.emf.ecore.EAnnotation |
getMetamodelAnnotation(org.eclipse.emf.ecore.EPackage ePackage)
Return the DomainConstants.AS_METAMODEL_ANNOTATION_SOURCE for ePackage, creating it if needed.
|
static <T> T |
isInstanceOf(java.lang.Object anObject,
java.lang.Class<T> aClass)
Return anObject cast to aClass if type-safe or null otherwise.
|
static boolean |
isRegistered(org.eclipse.emf.ecore.resource.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> org.eclipse.emf.common.util.EList<T> |
nullFree(org.eclipse.emf.common.util.EList<T> nullFreeList) |
static <T> java.util.List<T> |
nullFree(java.util.List<T> nullFreeList)
Cast a logically nullFreeList such as EMF collection to a declared null free list.
|
static <T extends java.lang.Comparable<T>> |
safeCompareTo(T object,
T otherObject)
Safely determines the relative order of
object and
otherObject , i.e. |
static boolean |
safeEquals(java.lang.Object object,
java.lang.Object otherObject)
Safely determines whether
object equals
otherObject , i.e. |
static <T> void |
sort(java.util.List<? extends T> aList,
java.util.Comparator<T> comparator)
Sort aList using comparator, using an Ecollections.sort if aLIst is an EList.
|
static java.lang.String |
toString(java.lang.Object anObject)
Deprecated.
String.valueOf()now annotated to be @NonNull
|
@Nullable public static <T> T asClassOrNull(java.lang.Object object, java.lang.Class<T> requiredClass)
object
- to cast.requiredClass
- to cast to.public static <T> T asClassUnchecked(java.lang.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(java.lang.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 cast@Nullable public static org.eclipse.emf.ecore.EAnnotation basicGetMetamodelAnnotation(@NonNull org.eclipse.emf.ecore.EPackage ePackage)
@Nullable public static <T> T getAdapter(@Nullable org.eclipse.core.runtime.IAdaptable iAdaptable, @NonNull java.lang.Class<T> adapterClass)
public static <T> java.lang.Class<T> getClass(T object)
T
- typeobject
- the object@NonNull public static org.eclipse.emf.ecore.EAnnotation getEAnnotation(@NonNull org.eclipse.emf.ecore.EModelElement eModelElement, java.lang.String sourceURI)
@NonNull public static org.eclipse.emf.ecore.EAnnotation getMetamodelAnnotation(@NonNull org.eclipse.emf.ecore.EPackage ePackage)
@Nullable public static <T> T isInstanceOf(java.lang.Object anObject, java.lang.Class<T> aClass)
anObject
- for which cast requiredaClass
- the type to which cast requiredpublic static boolean isRegistered(org.eclipse.emf.ecore.resource.Resource resource)
@NonNull public static <T> T nonNull(@Nullable 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.
@NonNull public static <T> T nonNullEMF(@Nullable T aT)
@NonNull public static <T> T nonNullModel(@Nullable T aT)
Return aT, checking the assertion that this call would not be necessary if the Ecore model was guaranteed to be valid.
@NonNull public static <T> T nonNullPivot(@Nullable T aT)
@NonNull public static <T> T nonNullState(@Nullable 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.
@NonNull public static <T> java.util.List<T> nullFree(@Nullable java.util.List<T> nullFreeList)
@NonNull public static <T> org.eclipse.emf.common.util.EList<T> nullFree(@Nullable org.eclipse.emf.common.util.EList<T> nullFreeList)
public static <T extends java.lang.Comparable<T>> int safeCompareTo(@Nullable T object, @Nullable T otherObject)
object
and
otherObject
, i.e. without throwing an exception if
object
is null
.public static boolean safeEquals(@Nullable java.lang.Object object, @Nullable java.lang.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(@NonNull java.util.List<? extends T> aList, @NonNull java.util.Comparator<T> comparator)
@Nullable public static <T> T getAdapter(@NonNull java.lang.Class<T> adapterClass, @NonNull org.eclipse.emf.common.notify.Notifier notifier)
@Nullable public static <T> T getAdapter(@NonNull java.lang.Class<T> adapterClass, @NonNull java.util.List<org.eclipse.emf.common.notify.Adapter> eAdapters)
@Deprecated @NonNull public static java.lang.String toString(java.lang.Object anObject)