Package com.inductiveautomation.rm.base
Class RMClassUtils
- java.lang.Object
-
- com.inductiveautomation.rm.base.RMClassUtils
-
public class RMClassUtils extends java.lang.Object
Utility methods for Class.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.Class
fromPrimitive(java.lang.Class aClass)
Returns primitive type for non-primitive.static java.lang.Class
getClass(java.lang.Object anObj)
Returns the class for an object.static java.lang.Class[]
getClasses(java.lang.String aPackageName)
Returns the classes in a package name.static java.lang.Class
getClassForName(java.lang.String aName)
Returns a class for a given name.static java.lang.Class
getClassForName(java.lang.String aName, java.lang.Object anObj)
Returns a class for a given name, using the class loader of the given class.static java.lang.String
getClassSimpleName(java.lang.Object anObj)
Returns simple class name of an object.static java.lang.String
getClassStandardName(java.lang.Object anObj, boolean doSimple)
Returns a standard class name of an object, minus any weird notation, like inner-class $, etc.static java.lang.Class
getCommonClass(java.lang.Object... theObjects)
Returns the common ancestor class for a list of objects.static java.lang.Class
getCommonClass(java.lang.Object anObj1, java.lang.Object anObj2)
Returns the common ancestor class for two objects.static java.lang.Class
getCommonClass(java.util.List aList)
Returns the common ancestor class for a list of objects.static java.lang.Class
getDeclaredClass(java.lang.Class aClass, java.lang.String aName)
Returns a class for a parent class and a name.static java.lang.reflect.Field
getDeclaredField(java.lang.Class aClass, java.lang.String aName)
Returns a field for a parent class and a name.static java.lang.reflect.Method
getDeclaredMethod(java.lang.Class aClass, java.lang.String aName, java.lang.Class[] theClasses)
Returns the declared method for a given class, name and parameter types array.static java.lang.reflect.Field
getField(java.lang.Class aClass, java.lang.String aName)
Returns a field for a parent class and a name.static <T> T
getInstance(java.lang.Object anObj, java.lang.Class<T> aClass)
Returns the given object as instance of given class, if it is.static java.net.URL
getJarURL(java.lang.Class aClass)
Returns the Jar URL for given class.static java.lang.String
getJarURLS(java.lang.Class aClass)
Returns the root URL for given class (could be a "file:" (directory) or "jar:").static java.lang.reflect.Method
getMethod(java.lang.Class aClass, java.lang.String aName, java.lang.Class[] theClasses)
Returns the method for given class, name and parameter types.static java.lang.Class
getPrimitiveClassForName(java.lang.String aName)
Returns a primitive class for name.static java.net.URL
getRootURL(java.lang.Class aClass)
Returns the plain URL (http: or file:) to the jar for given class.static java.lang.Class
getTypeParameterClass(java.lang.Class aClass)
Returns a type parameter class.static boolean
isAssignable(java.lang.Class[] theClasses1, java.lang.Class[] theClasses2, int aCount)
Returns whether second batch of classes is assignable to first batch of classes (accounting for auto-boxing).static boolean
isAssignable(java.lang.Class aClass1, java.lang.Class aClass2)
Returns whether a given class could be assigned a value from the second given class (accounting for auto-boxing).static boolean
isAssignablePrimitive(java.lang.Class aClass1, java.lang.Class aClass2)
Returns whether a given primitive class could be assigned a value from the second given class.static boolean
isCompatible(java.lang.reflect.Method aMethod, java.lang.Class[] theClasses)
Returns whether arg classes are compatible.static boolean
isPrimitiveClassName(java.lang.String aName)
Returns whether name is a primitive class name.static <T> T
newInstance(java.lang.Class<T> aClass)
Returns a new instance of a given class.static <T> T
newInstance(T anObject)
Returns a new instance of a given object.static java.lang.Class
toPrimitive(java.lang.Class aClass)
Returns non primitive type for primitive.
-
-
-
Method Detail
-
getClass
@Nullable public static java.lang.Class getClass(java.lang.Object anObj)
Returns the class for an object.
-
getInstance
public static <T> T getInstance(java.lang.Object anObj, java.lang.Class<T> aClass)
Returns the given object as instance of given class, if it is.
-
getClassSimpleName
@Nonnull public static java.lang.String getClassSimpleName(java.lang.Object anObj)
Returns simple class name of an object.
-
getClassStandardName
@Nonnull public static java.lang.String getClassStandardName(java.lang.Object anObj, boolean doSimple)
Returns a standard class name of an object, minus any weird notation, like inner-class $, etc.
-
getClassForName
public static java.lang.Class getClassForName(java.lang.String aName)
Returns a class for a given name.
-
getClassForName
public static java.lang.Class getClassForName(java.lang.String aName, java.lang.Object anObj)
Returns a class for a given name, using the class loader of the given class.
-
isPrimitiveClassName
public static boolean isPrimitiveClassName(java.lang.String aName)
Returns whether name is a primitive class name.
-
getPrimitiveClassForName
@Nullable public static java.lang.Class getPrimitiveClassForName(java.lang.String aName)
Returns a primitive class for name.
-
newInstance
public static <T> T newInstance(@Nonnull T anObject)
Returns a new instance of a given object.
-
newInstance
public static <T> T newInstance(java.lang.Class<T> aClass)
Returns a new instance of a given class.
-
getField
public static java.lang.reflect.Field getField(@Nonnull java.lang.Class aClass, @Nullable java.lang.String aName)
Returns a field for a parent class and a name.
-
getDeclaredField
public static java.lang.reflect.Field getDeclaredField(@Nonnull java.lang.Class aClass, @Nullable java.lang.String aName)
Returns a field for a parent class and a name.
-
getMethod
public static java.lang.reflect.Method getMethod(java.lang.Class aClass, java.lang.String aName, java.lang.Class[] theClasses)
Returns the method for given class, name and parameter types.
-
getDeclaredMethod
public static java.lang.reflect.Method getDeclaredMethod(java.lang.Class aClass, java.lang.String aName, java.lang.Class[] theClasses)
Returns the declared method for a given class, name and parameter types array.
-
getDeclaredClass
public static java.lang.Class getDeclaredClass(java.lang.Class aClass, java.lang.String aName)
Returns a class for a parent class and a name.
-
isCompatible
public static boolean isCompatible(java.lang.reflect.Method aMethod, java.lang.Class[] theClasses)
Returns whether arg classes are compatible.
-
isAssignable
public static boolean isAssignable(java.lang.Class[] theClasses1, java.lang.Class[] theClasses2, int aCount)
Returns whether second batch of classes is assignable to first batch of classes (accounting for auto-boxing).
-
isAssignable
public static boolean isAssignable(java.lang.Class aClass1, java.lang.Class aClass2)
Returns whether a given class could be assigned a value from the second given class (accounting for auto-boxing).
-
isAssignablePrimitive
public static boolean isAssignablePrimitive(java.lang.Class aClass1, java.lang.Class aClass2)
Returns whether a given primitive class could be assigned a value from the second given class.
-
toPrimitive
public static java.lang.Class toPrimitive(java.lang.Class aClass)
Returns non primitive type for primitive.
-
fromPrimitive
public static java.lang.Class fromPrimitive(java.lang.Class aClass)
Returns primitive type for non-primitive.
-
getCommonClass
public static java.lang.Class getCommonClass(java.lang.Object anObj1, java.lang.Object anObj2)
Returns the common ancestor class for two objects.
-
getCommonClass
public static java.lang.Class getCommonClass(java.lang.Object... theObjects)
Returns the common ancestor class for a list of objects.
-
getCommonClass
public static java.lang.Class getCommonClass(java.util.List aList)
Returns the common ancestor class for a list of objects.
-
getTypeParameterClass
public static java.lang.Class getTypeParameterClass(java.lang.Class aClass)
Returns a type parameter class.
-
getClasses
public static java.lang.Class[] getClasses(java.lang.String aPackageName)
Returns the classes in a package name. Busted for JNLP Web Start.
-
getRootURL
public static java.net.URL getRootURL(java.lang.Class aClass)
Returns the plain URL (http: or file:) to the jar for given class.
-
getJarURL
public static java.net.URL getJarURL(java.lang.Class aClass)
Returns the Jar URL for given class.
-
getJarURLS
public static java.lang.String getJarURLS(java.lang.Class aClass)
Returns the root URL for given class (could be a "file:" (directory) or "jar:").
-
-