public class TypeUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static java.util.HashMap<java.lang.Class<?>,java.lang.String> |
class2Name |
private static java.util.HashMap<java.lang.Class<?>,java.lang.reflect.Method> |
class2Value |
static int |
CR |
static int |
LF |
private static java.lang.invoke.MethodHandle[] |
LOCATION_METHODS |
private static Logger |
LOG |
private static ModuleLocation |
MODULE_LOCATION |
private static java.util.HashMap<java.lang.String,java.lang.Class<?>> |
name2Class |
static java.lang.Class<?>[] |
NO_ARGS |
Constructor and Description |
---|
TypeUtil() |
Modifier and Type | Method and Description |
---|---|
static <T> java.util.List<T> |
asList(T[] a)
Array to List.
|
static java.lang.Object |
call(java.lang.Class<?> oClass,
java.lang.String methodName,
java.lang.Object obj,
java.lang.Object[] arg)
Deprecated.
|
static java.lang.Object |
construct(java.lang.Class<?> klass,
java.lang.Object[] arguments)
Deprecated.
|
static java.lang.Object |
construct(java.lang.Class<?> klass,
java.lang.Object[] arguments,
java.util.Map<java.lang.String,java.lang.Object> namedArgMap)
Deprecated.
|
static byte |
convertHexDigit(byte c) |
static int |
convertHexDigit(char c) |
static int |
convertHexDigit(int c) |
static void |
dump(java.lang.Class<?> c) |
static void |
dump(java.lang.ClassLoader cl) |
static byte[] |
fromHexString(java.lang.String s) |
static java.lang.Class<?> |
fromName(java.lang.String name)
Class from a canonical name for a type.
|
static java.net.URI |
getClassLoaderLocation(java.lang.Class<?> clazz) |
static java.net.URI |
getClassLoaderLocation(java.lang.Class<?> clazz,
java.lang.ClassLoader loader) |
static java.net.URI |
getCodeSourceLocation(java.lang.Class<?> clazz) |
static java.net.URI |
getLocationOfClass(java.lang.Class<?> clazz)
Attempt to find the Location of a loaded Class.
|
static java.net.URI |
getModuleLocation(java.lang.Class<?> clazz) |
static java.net.URI |
getSystemClassLoaderLocation(java.lang.Class<?> clazz) |
static boolean |
isFalse(java.lang.Object o) |
static boolean |
isTrue(java.lang.Object o) |
static byte[] |
parseBytes(java.lang.String s,
int base) |
static int |
parseInt(byte[] b,
int offset,
int length,
int base)
Parse an int from a byte array of ascii characters.
|
static int |
parseInt(java.lang.String s,
int offset,
int length,
int base)
Parse an int from a substring.
|
static java.lang.String |
toClassReference(java.lang.Class<?> clazz)
Return the Classpath / Classloader reference for the
provided class file.
|
static java.lang.String |
toClassReference(java.lang.String className)
Return the Classpath / Classloader reference for the
provided class file.
|
static void |
toHex(byte b,
java.lang.Appendable buf) |
static void |
toHex(int value,
java.lang.Appendable buf) |
static void |
toHex(long value,
java.lang.Appendable buf) |
static java.lang.String |
toHexString(byte b) |
static java.lang.String |
toHexString(byte[] b) |
static java.lang.String |
toHexString(byte[] b,
int offset,
int length) |
static java.lang.String |
toName(java.lang.Class<?> type)
Canonical name for a type.
|
static java.lang.String |
toString(byte[] bytes,
int base) |
static java.lang.Object |
valueOf(java.lang.Class<?> type,
java.lang.String value)
Convert String value to instance.
|
static java.lang.Object |
valueOf(java.lang.String type,
java.lang.String value)
Convert String value to instance.
|
private static final Logger LOG
public static final java.lang.Class<?>[] NO_ARGS
public static final int CR
public static final int LF
private static final java.util.HashMap<java.lang.String,java.lang.Class<?>> name2Class
private static final java.util.HashMap<java.lang.Class<?>,java.lang.String> class2Name
private static final java.util.HashMap<java.lang.Class<?>,java.lang.reflect.Method> class2Value
private static final java.lang.invoke.MethodHandle[] LOCATION_METHODS
private static final ModuleLocation MODULE_LOCATION
public static <T> java.util.List<T> asList(T[] a)
Works like Arrays.asList(Object...)
, but handles null arrays.
T
- the array and list entry typea
- the array to convert to a listpublic static java.lang.Class<?> fromName(java.lang.String name)
name
- A class or type name.public static java.lang.String toName(java.lang.Class<?> type)
type
- A class , which may be a primitive TYPE field.public static java.lang.String toClassReference(java.lang.Class<?> clazz)
Convenience method for the code
String ref = myObject.getClass().getName().replace('.','/') + ".class";
clazz
- the class to referencepublic static java.lang.String toClassReference(java.lang.String className)
Convenience method for the code
String ref = myClassName.replace('.','/') + ".class";
className
- the class to referencepublic static java.lang.Object valueOf(java.lang.Class<?> type, java.lang.String value)
type
- The class of the instance, which may be a primitive TYPE field.value
- The value as a string.public static java.lang.Object valueOf(java.lang.String type, java.lang.String value)
type
- classname or type (eg int)value
- The value as a string.public static int parseInt(java.lang.String s, int offset, int length, int base) throws java.lang.NumberFormatException
s
- Stringoffset
- Offset within stringlength
- Length of integer or -1 for remainder of stringbase
- base of the integerjava.lang.NumberFormatException
- if the string cannot be parsedpublic static int parseInt(byte[] b, int offset, int length, int base) throws java.lang.NumberFormatException
b
- byte arrayoffset
- Offset within stringlength
- Length of integer or -1 for remainder of stringbase
- base of the integerjava.lang.NumberFormatException
- if the array cannot be parsed into an integerpublic static byte[] parseBytes(java.lang.String s, int base)
public static java.lang.String toString(byte[] bytes, int base)
public static byte convertHexDigit(byte c)
c
- An ASCII encoded character 0-9 a-f A-Fpublic static int convertHexDigit(char c)
c
- An ASCII encoded character 0-9 a-f A-Fpublic static int convertHexDigit(int c)
c
- An ASCII encoded character 0-9 a-f A-Fpublic static void toHex(byte b, java.lang.Appendable buf)
public static void toHex(int value, java.lang.Appendable buf) throws java.io.IOException
java.io.IOException
public static void toHex(long value, java.lang.Appendable buf) throws java.io.IOException
java.io.IOException
public static java.lang.String toHexString(byte b)
public static java.lang.String toHexString(byte[] b)
public static java.lang.String toHexString(byte[] b, int offset, int length)
public static byte[] fromHexString(java.lang.String s)
public static void dump(java.lang.Class<?> c)
public static void dump(java.lang.ClassLoader cl)
@Deprecated public static java.lang.Object call(java.lang.Class<?> oClass, java.lang.String methodName, java.lang.Object obj, java.lang.Object[] arg) throws java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
@Deprecated public static java.lang.Object construct(java.lang.Class<?> klass, java.lang.Object[] arguments) throws java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
@Deprecated public static java.lang.Object construct(java.lang.Class<?> klass, java.lang.Object[] arguments, java.util.Map<java.lang.String,java.lang.Object> namedArgMap) throws java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
public static boolean isTrue(java.lang.Object o)
o
- Object to test for truepublic static boolean isFalse(java.lang.Object o)
o
- Object to test for falsepublic static java.net.URI getLocationOfClass(java.lang.Class<?> clazz)
This can be null for primitives, void, and in-memory classes.
clazz
- the loaded class to find a location for.jrt://
resource, etc), or null of no location available.public static java.net.URI getClassLoaderLocation(java.lang.Class<?> clazz)
public static java.net.URI getSystemClassLoaderLocation(java.lang.Class<?> clazz)
public static java.net.URI getClassLoaderLocation(java.lang.Class<?> clazz, java.lang.ClassLoader loader)
public static java.net.URI getCodeSourceLocation(java.lang.Class<?> clazz)
public static java.net.URI getModuleLocation(java.lang.Class<?> clazz)