Package util.safety

Class Preconditions

java.lang.Object
util.safety.Preconditions

public final class Preconditions extends Object
Since:
18.06.2021
Author:
Juyas
  • Constructor Details

    • Preconditions

      public Preconditions()
  • Method Details

    • ensureMainThread

      public static void ensureMainThread(String location)
      Test if the current call is executed in the main thread. This is especially necessary if you run a mac, since mac doesnt like OpenGl calls in ANY thread except the first one. This method does NOT provide a valid exception if the whole program wasnt launched with VM argument -XstartOnFirstThread, because only with this argument, its guaranteed that the main thread is actually is the first.
    • nonNull

      public static <T> T nonNull(T obj)
      Improve code stability by doing non-null checks inline.
      Type Parameters:
      T - any type
      Parameters:
      obj - any object expected to be non-null
      Returns:
      the object, if and only if its not null. throws a NullPointerException otherwise.
    • nonNull

      public static <T> T nonNull(String name, T obj)
      Improve code stability by doing non-null checks inline.
      Type Parameters:
      T - any type
      Parameters:
      obj - any object expected to be non-null
      name - the name of the object to improve locating process
      Returns:
      the object, if and only if its not null. throws a NullPointerException otherwise.