public final class Reflections extends Object
| Modifier and Type | Method and Description |
|---|---|
static boolean |
accessedFrom(Class<?> clazz)
Returns whether or not the current context was called from a class
(instance or otherwise) that is passed to this method.
|
static boolean |
accessedFrom(String regex)
Returns whether or not the current context was called from a class
(instance or otherwise) that is passed to this method.
|
static <T> T |
defaultPrimitiveValue(Class<T> c)
Returns a "default value" of -1 or
false for a default type's
class or autoboxing class. |
static <K,V> Map<K,V> |
difference(Map<K,V> initial,
Map<K,V> replacer) |
static File |
findPluginJarfile(String name)
Checks whether or not there is a plugin on the server with the name of
the passed
name paramater. |
static Class<?> |
getArrayClass(Class<?> componentType) |
static StackTraceElement |
getCaller()
Returns a
StackTraceElement of the direct caller of the current
method's context. |
static StackTraceElement |
getCaller(int offset)
Returns a
StackTraceElement of the direct caller of the current
method's context. |
static boolean |
hasAnnotation(AnnotatedElement target,
Class<? extends Annotation> check)
Returns
true if the specified target has the passed
Annotation |
static Set<String> |
matchClosestKeys(Map<String,?> map,
String search)
Returns a
Set of keys that closest match the passed in string
value |
static <T> List<T> |
matchClosestValues(Map<String,T> map,
String search)
Returns a
List of values mapped from keys that closest match the
passed in string value |
static <T> List<T> |
nonFixedList(T... items)
Returns a new
ArrayList of the passed parameters that is not
fixed-size, akin to what Arrays.asList(Object...) returns |
static <I,R> R |
nullSafeMutation(I in,
Function<I,R> act)
Provides a way of mutating an object (into a new result) without worrying
about null safety.
|
static String |
objectString(Object in) |
static void |
operateLock(Lock lock,
Runnable operation)
Performs an operation with a lock, saving room by not requiring a lot of
try-finally blocks |
static <R> R |
operateLock(Lock lock,
Supplier<R> operation)
Performs an operation with a lock, saving room by not requiring a lot of
try-finally blocks |
static Optional<Byte> |
parseByte(String s) |
static Optional<Double> |
parseDouble(String s) |
static Optional<Float> |
parseFloat(String s) |
static Optional<Integer> |
parseInt(String s) |
static Optional<Long> |
parseLong(String s) |
static Optional<Short> |
parseShort(String s) |
static UUID |
parseUUID(String uuid) |
static String |
properEnumName(Enum<?> val) |
static String |
stackTraceToString(Throwable t)
Converts a stack trace into a String for ease-of-use in network-level debugging
|
static <T> Stream<T> |
stream(Iterable<T> itr)
Façade method for streaming
Iterable, so that Iterable can be accepted as a general parameter |
static <T> Stream<T> |
stream(T... obj)
Façade method for arrays, to simplify accepting general parameters even further
|
static void |
trace()
Prints out the stack history 10 calls back
|
static void |
trace(int length)
Prints out the stack history
length calls back |
public static boolean hasAnnotation(AnnotatedElement target, Class<? extends Annotation> check)
true if the specified target has the passed
Annotationtarget - The relevant element to check for an Annotationcheck - The Annotation class type to check fortrue if the Annotation is presentpublic static boolean accessedFrom(String regex)
regex - The regex to check against the calling classtrue if accessed from a class that matches the regexpublic static boolean accessedFrom(Class<?> clazz)
clazz - The class to checktrue if accessed from this classpublic static StackTraceElement getCaller(int offset)
StackTraceElement of the direct caller of the current
method's context.offset - The number of additional methods to look backStackTraceElement representing where the current
context was called frompublic static StackTraceElement getCaller()
StackTraceElement of the direct caller of the current
method's context. This method is equivalent to calling
Reflections.getCaller(0)StackTraceElement representing where the current
context was called frompublic static File findPluginJarfile(String name)
name paramater. This method achieves this by scanning
the plugins folder and reading the plugin.yml files of any
respective jarfiles in the directory.name - The name of the plugin as specified in the plugin.ymlFile for the plugin jarfile, or null if not
foundpublic static <T> T defaultPrimitiveValue(Class<T> c)
false for a default type's
class or autoboxing class. Will return null if not relevant to
primitivesT - The type of the primitivec - The primitive classnull if not a primitivepublic static Set<String> matchClosestKeys(Map<String,?> map, String search)
Set of keys that closest match the passed in string
valuemap - The Map with a string key to look throughsearch - The string to use as a base to search forpublic static <T> List<T> matchClosestValues(Map<String,T> map, String search)
List of values mapped from keys that closest match the
passed in string valueT - The type of the valuesmap - The Map to look throughsearch - The string to use as a base to search forpublic static <T> List<T> nonFixedList(T... items)
ArrayList of the passed parameters that is not
fixed-size, akin to what Arrays.asList(Object...) returnsT - The type of the objects being passed initems - The parameters to add to a listList of the items, or an empty list if no paramspublic static <I,R> R nullSafeMutation(I in,
Function<I,R> act)
I - The potentially null variable to be mutatedR - The expected result typein - The variable to evaluate for a mutationact - The action to take on the variableIllegalArgumentException - if the passed parameter is nullpublic static void operateLock(Lock lock, Runnable operation)
try-finally blockslock - The Lock to utilizeoperation - The code to be runpublic static <R> R operateLock(Lock lock, Supplier<R> operation)
try-finally blockspublic static void trace()
public static void trace(int length)
length calls backlength - The number of calls back on the stack to print outpublic static Class<?> getArrayClass(Class<?> componentType) throws ClassNotFoundException
ClassNotFoundExceptionpublic static <T> Stream<T> stream(Iterable<T> itr)
Iterable, so that Iterable can be accepted as a general parameterpublic static <T> Stream<T> stream(T... obj)
T - The type of the objects and streamobj - The object(s) to streamStream of the iterable elementsCopyright © 2017. All rights reserved.