Class Util

java.lang.Object
net.ME1312.Galaxi.Library.Util

public final class Util extends Object
Random Utility Class
  • 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:
      Value
      Throws:
      NullPointerException - if any are null
    • nullpo

      @SafeVarargs public static <T> T[] nullpo(T... values)
      Checks values to make sure they're not null
      Parameters:
      values - Values to check
      Returns:
      Values
      Throws:
      NullPointerException - if any are null
    • isNull

      public static boolean isNull(Object value)
      Checks a value to make sure it's not null
      Parameters:
      value - Value to check
      Returns:
      If any are null
    • isNull

      public static boolean isNull(Object... values)
      Checks values to make sure they're not null
      Parameters:
      values - Values to check
      Returns:
      If any are null
    • getBackwards

      public static <K, V> List<K> getBackwards(Map<K,V> map, V value)
      Get keys by value from map
      Type Parameters:
      K - Key
      V - Value
      Parameters:
      map - Map to search
      value - Value to search for
      Returns:
      Search results
    • getCaseInsensitively

      public static <V> V getCaseInsensitively(Map<String,V> map, String key)
      Get an item from a map ignoring case
      Type Parameters:
      V - Value
      Parameters:
      map - Map to search
      key - Key to search with
      Returns:
      Search Result
    • getNew

      public static <V> V getNew(Collection<? extends V> existing, Supplier<V> generator)
      Gets a new Variable that doesn't match the existing Variables
      Type Parameters:
      V - Variable Type
      Parameters:
      existing - Existing Variables
      generator - Variable Generator
      Returns:
      Variable
    • readAll

      public static String readAll(Reader rd) throws IOException
      Read Everything from Reader
      Parameters:
      rd - Reader
      Returns:
      Reader Contents
      Throws:
      IOException
    • copyFromJar

      public static void copyFromJar(ClassLoader loader, String resource, String destination)
      Copy a file from the ClassLoader
      Parameters:
      loader - ClassLoader
      resource - Location From
      destination - Location To
    • reflect

      public static <R> R reflect(Field field, Object instance) throws IllegalAccessException
      Get a Field's value using Reflection
      This method is likely to be removed the moment multi-module JPMS jarfiles become available to us
      Type Parameters:
      R - Return Type
      Parameters:
      field - Field to grab
      instance - 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
      This method is likely to be removed the moment multi-module JPMS jarfiles become available to us
      Parameters:
      field - Field to write to
      instance - 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
      This method is likely to be removed the moment multi-module JPMS jarfiles become available to us
      Type Parameters:
      R - Return Type
      Parameters:
      method - Method to call
      instance - Object Instance (Null for static methods)
      arguments - Method Arguments
      Returns:
      Returned Value
      Throws:
      InvocationTargetException
      IllegalAccessException
    • reflect

      public static <R> R reflect(Constructor<?> constructor, Object... arguments) throws InvocationTargetException, IllegalAccessException, InstantiationException
      Construct an object using Reflection
      This method is likely to be removed the moment multi-module JPMS jarfiles become available to us
      Type Parameters:
      R - Return Type
      Parameters:
      constructor - Constructor to use
      arguments - Constructor Arguments
      Returns:
      New Instance
      Throws:
      InvocationTargetException
      IllegalAccessException
      InstantiationException
    • sneakyThrow

      public static RuntimeException sneakyThrow(Throwable e)
      Sneak an exception past the compiler
      Parameters:
      e - Exception
      Returns:
      Nothing — this method will always throw the given exception
      See Also:
    • unescapeJavaString

      public static String unescapeJavaString(String str)
      Parse Java escapes in a String
      Parameters:
      str - String
      Returns:
      Unescaped String