Package net.ME1312.Galaxi.Library
Class Util
java.lang.Object
net.ME1312.Galaxi.Library.Util
Random Utility Class
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcopyFromJar(ClassLoader loader, String resource, String destination) Copy a file from the ClassLoaderstatic <K,V> List<K> getBackwards(Map<K, V> map, V value) Get keys by value from mapstatic <V> VgetCaseInsensitively(Map<String, V> map, String key) Get an item from a map ignoring casestatic <V> VgetNew(Collection<? extends V> existing, Supplier<V> generator) Gets a new Variable that doesn't match the existing Variablesstatic booleanChecks a value to make sure it's not nullstatic booleanChecks values to make sure they're not nullstatic <T> Tnullpo(T value) Checks a value to make sure it's not nullstatic <T> T[]nullpo(T... values) Checks values to make sure they're not nullstatic <T> T[]nullpoCopy(T[] values) Checks an array of values to make sure they're not null and returns a trusted copystatic StringRead Everything from Readerstatic <R> Rreflect(Constructor<?> constructor, Object... arguments) Construct an object using Reflectionstatic <R> RGet a Field's value using Reflectionstatic voidSet a Field's value using Reflectionstatic <R> RCall a method using Reflectionstatic RuntimeExceptionSneak an exception past the compilerstatic StringunescapeJavaString(String str) Parse Java escapes in a String
-
Method Details
-
nullpo
public static <T> T nullpo(T value) Checks a value to make sure it's not null- Parameters:
value- Value to check- Returns:
- The value
- Throws:
NullPointerException- if it is null
-
nullpo
Checks values to make sure they're not null- Parameters:
values- Values to check- Returns:
- The values array
- Throws:
NullPointerException- if anything is null
-
nullpoCopy
public static <T> T[] nullpoCopy(T[] values) Checks an array of values to make sure they're not null and returns a trusted copy- Parameters:
values- Array & values to check- Returns:
- A trusted copy of the values array
- Throws:
NullPointerException- if anything is null
-
isNull
Checks a value to make sure it's not null- Parameters:
value- Value to check- Returns:
- true if it is null
-
isNull
Checks values to make sure they're not null- Parameters:
values- Values to check- Returns:
- true if anything is null
-
getBackwards
Get keys by value from map- Type Parameters:
K- KeyV- Value- Parameters:
map- Map to searchvalue- Value to search for- Returns:
- Search results
-
getCaseInsensitively
Get an item from a map ignoring case- Type Parameters:
V- Value- Parameters:
map- Map to searchkey- Key to search with- Returns:
- Search Result
-
getNew
Gets a new Variable that doesn't match the existing Variables- Type Parameters:
V- Variable Type- Parameters:
existing- Existing Variablesgenerator- Variable Generator- Returns:
- Variable
-
readAll
Read Everything from Reader- Parameters:
rd- Reader- Returns:
- Reader Contents
- Throws:
IOException
-
copyFromJar
Copy a file from the ClassLoader- Parameters:
loader- ClassLoaderresource- Location Fromdestination- Location To
-
reflect
Get a Field's value using Reflection- Type Parameters:
R- Return Type- Parameters:
field- Field to grabinstance- Object Instance (Null for static fields)- Returns:
- Field Value
- Throws:
IllegalAccessException
-
reflect
public static void reflect(Field field, Object instance, Object value) throws IllegalAccessException Set a Field's value using Reflection- Parameters:
field- Field to write toinstance- Object Instance (Null for static fields)value- Value to write- Throws:
IllegalAccessException
-
reflect
public static <R> R reflect(Method method, Object instance, Object... arguments) throws InvocationTargetException, IllegalAccessException Call a method using Reflection- Type Parameters:
R- Return Type- Parameters:
method- Method to callinstance- Object Instance (Null for static methods)arguments- Method Arguments- Returns:
- Returned Value
- Throws:
InvocationTargetExceptionIllegalAccessException
-
reflect
public static <R> R reflect(Constructor<?> constructor, Object... arguments) throws InvocationTargetException, IllegalAccessException, InstantiationException Construct an object using Reflection- Type Parameters:
R- Return Type- Parameters:
constructor- Constructor to usearguments- Constructor Arguments- Returns:
- New Instance
- Throws:
InvocationTargetExceptionIllegalAccessExceptionInstantiationException
-
sneakyThrow
Sneak an exception past the compiler- Parameters:
e- Exception- Returns:
- Nothing — this method will always throw the given exception
- See Also:
-
unescapeJavaString
Parse Java escapes in a String- Parameters:
str- String- Returns:
- Unescaped String
-