Class TypeUtil
- Since:
 - Jetty 4.1
 
- 
Field Summary
Fields - 
Method Summary
Modifier and TypeMethodDescriptionstatic <T> List<T> asList(T[] a) Array to List.static <T> Iterator<T> static byteconvertHexDigit(byte c) static intconvertHexDigit(char c) static intconvertHexDigit(int c) static voidstatic voiddump(ClassLoader cl) static <T> Predicate<T> static Class<?> Class from a canonical name for a type.static URIgetClassLoaderLocation(Class<?> clazz) static URIgetClassLoaderLocation(Class<?> clazz, ClassLoader loader) static URIgetCodeSourceLocation(Class<?> clazz) static URIgetLocationOfClass(Class<?> clazz) Attempt to find the Location of a loaded Class.static URIgetModuleLocation(Class<?> clazz) static URIgetSystemClassLoaderLocation(Class<?> clazz) static booleanisDeclaredMethodOn(Object object, String methodName, Class<?>... args) Test is a method has been declared on the class of an instancestatic booleanstatic booleanstatic booleanstatic <T> ListIterator<T> listIteratorAtEnd(List<T> list) Returns aListIteratorpositioned at the last item in a list.static intparseInt(byte[] b, int offset, int length, int base) Parse an int from a byte array of ascii characters.static intParse an int from a substring.static <T> Stream<ServiceLoader.Provider<T>> serviceProviderStream(ServiceLoader<T> serviceLoader) Utility to create a stream which provides the same functionality asServiceLoader.stream().static <T> Stream<T> serviceStream(ServiceLoader<T> serviceLoader) Utility method to provide a stream of the service type from aServiceLoader.static StringtoClassReference(Class<?> clazz) Return the Classpath / Classloader reference for the provided class file.static StringtoClassReference(String className) Return the Classpath / Classloader reference for the provided class file.static voidtoHex(byte b, Appendable buf) static voidtoHex(int value, Appendable buf) static voidtoHex(long value, Appendable buf) static StringtoShortName(Class<?> type) static StringtoString(byte[] bytes, int base) static StringPretty print a map.static <T> Predicate<T> A Predicate that is always true, with optimizedand/or/notmethods.static ObjectConvert String value to instance.static ObjectConvert String value to instance. 
- 
Field Details
- 
NO_ARGS
 - 
CR
public static final int CR- See Also:
 
 - 
LF
public static final int LF- See Also:
 
 
 - 
 - 
Method Details
- 
asList
Array to List.Works like
Arrays.asList(Object...), but handles null arrays.- Type Parameters:
 T- the array and list entry type- Parameters:
 a- the array to convert to a list- Returns:
 - a list backed by the array.
 
 - 
listIteratorAtEnd
Returns a
ListIteratorpositioned at the last item in a list.- Type Parameters:
 T- the element type- Parameters:
 list- the list- Returns:
 - A 
ListIteratorpositioned at the last item of the list. 
 - 
fromName
 - 
toShortName
 - 
toClassReference
Return the Classpath / Classloader reference for the provided class file.Convenience method for the code
String ref = myObject.getClass().getName().replace('.','/') + ".class";- Parameters:
 clazz- the class to reference- Returns:
 - the classpath reference syntax for the class file
 
 - 
toClassReference
Return the Classpath / Classloader reference for the provided class file.Convenience method for the code
String ref = myClassName.replace('.','/') + ".class";- Parameters:
 className- the class to reference- Returns:
 - the classpath reference syntax for the class file
 
 - 
valueOf
 - 
valueOf
 - 
parseInt
Parse an int from a substring. Negative numbers are not handled.- Parameters:
 s- Stringoffset- Offset within stringlength- Length of integer or -1 for remainder of stringbase- base of the integer- Returns:
 - the parsed integer
 - Throws:
 NumberFormatException- if the string cannot be parsed
 - 
parseInt
Parse an int from a byte array of ascii characters. Negative numbers are not handled.- Parameters:
 b- byte arrayoffset- Offset within stringlength- Length of integer or -1 for remainder of stringbase- base of the integer- Returns:
 - the parsed integer
 - Throws:
 NumberFormatException- if the array cannot be parsed into an integer
 - 
toString
 - 
convertHexDigit
public static byte convertHexDigit(byte c) - Parameters:
 c- An ASCII encoded character 0-9 a-f A-F- Returns:
 - The byte value of the character 0-16.
 
 - 
convertHexDigit
public static int convertHexDigit(char c) - Parameters:
 c- An ASCII encoded character 0-9 a-f A-F- Returns:
 - The byte value of the character 0-16.
 
 - 
convertHexDigit
public static int convertHexDigit(int c) - Parameters:
 c- An ASCII encoded character 0-9 a-f A-F- Returns:
 - The byte value of the character 0-16.
 
 - 
isHex
 - 
toHex
 - 
toHex
- Throws:
 IOException
 - 
toHex
- Throws:
 IOException
 - 
dump
 - 
dump
 - 
isTrue
- Parameters:
 o- Object to test for true- Returns:
 - True if passed object is not null and is either a Boolean with value true or evaluates to a string that evaluates to true.
 
 - 
isFalse
- Parameters:
 o- Object to test for false- Returns:
 - True if passed object is not null and is either a Boolean with value false or evaluates to a string that evaluates to false.
 
 - 
getLocationOfClass
Attempt to find the Location of a loaded Class.This can be null for primitives, void, and in-memory classes.
- Parameters:
 clazz- the loaded class to find a location for.- Returns:
 - the location as a URI (this is a URI pointing to a holder of the class: a directory,
a jar file, a 
jrt://resource, etc), or null of no location available. 
 - 
getSystemClassLoaderLocation
 - 
getClassLoaderLocation
 - 
getClassLoaderLocation
 - 
getCodeSourceLocation
 - 
getModuleLocation
 - 
concat
 - 
serviceStream
Utility method to provide a stream of the service type from a
ServiceLoader.ServiceConfigurationErrors thrown when loading or instantiating the service instances are logged at DEBUG level and ignored, so that the stream can proceed with the next service provider.Consider using
serviceProviderStream(ServiceLoader)if you want to explicitly handleServiceConfigurationErrors thrown when loading or instantiating the service instances.- Type Parameters:
 T- the type of the service to load.- Parameters:
 serviceLoader- the ServiceLoader instance to use.- Returns:
 - a stream of the service type which will not throw 
ServiceConfigurationError. 
 - 
serviceProviderStream
public static <T> Stream<ServiceLoader.Provider<T>> serviceProviderStream(ServiceLoader<T> serviceLoader) Utility to create a stream which provides the same functionality as
ServiceLoader.stream().However, this also guards the case in which
Iterator.hasNext()throws. Any exceptions from the underlying iterator will be cached until theServiceLoader.Provider.get()is called.Consider using
serviceStream(ServiceLoader)to ignore exceptions and continue the iteration.- Type Parameters:
 T- the type of the service to load.- Parameters:
 serviceLoader- the ServiceLoader instance to use.- Returns:
 - A stream that lazily loads providers for this loader's service
 
 - 
truePredicate
A Predicate that is always true, with optimizedand/or/notmethods.- Type Parameters:
 T- The type of the predicate test- Returns:
 - true
 
 - 
falsePredicate
 - 
isDeclaredMethodOn
Test is a method has been declared on the class of an instance- Parameters:
 object- The object to checkmethodName- The method nameargs- The arguments to the method- Returns:
 trueiffClass.getDeclaredMethod(String, Class[])can be called on theClassof the object, without throwingNoSuchMethodException.
 - 
toString
 
 -