Class Preconditions

java.lang.Object
io.flutter.util.Preconditions

public final class Preconditions extends Object
Static convenience methods that help a method or constructor check whether it was invoked correctly (that is, whether its preconditions were met).
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> T
    checkNotNull(T reference)
    Ensures that an object reference passed as a parameter to the calling method is not null.
    static void
    checkState(boolean expression)
    Ensures the truth of an expression involving the state of the calling instance.
    static void
    checkState(boolean expression, Object errorMessage)
    Ensures the truth of an expression involving the state of the calling instance.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • checkNotNull

      public static <T> T checkNotNull(T reference)
      Ensures that an object reference passed as a parameter to the calling method is not null.
      Parameters:
      reference - an object reference
      Returns:
      the non-null reference that was validated
      Throws:
      NullPointerException - if reference is null
    • checkState

      public static void checkState(boolean expression)
      Ensures the truth of an expression involving the state of the calling instance.
      Parameters:
      expression - a boolean expression that must be checked to be true
      Throws:
      IllegalStateException - if expression is false
    • checkState

      public static void checkState(boolean expression, @Nullable Object errorMessage)
      Ensures the truth of an expression involving the state of the calling instance.
      Parameters:
      expression - a boolean expression that must be checked to be true
      errorMessage - the exception message to use if the check fails; will be converted to a string using String.valueOf(Object)
      Throws:
      IllegalStateException - if expression is false