Package 

Class Preconditions


  • 
    public final class Preconditions
    
                        

    Simple static methods to be called at the start of your own methods to verify correct arguments and state. Each method supports 2 flavors - one that will always throw a runtime exception, and a NoThrow version that will only throw an exception when in strict mode. We use the former for internal state checks, and the later to validate arguments passed to the SDK.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      public final class Preconditions.NoThrow

      Preconditions checks that avoid throwing and exception in release mode. These versions returna boolean which the caller should check.

    • Method Summary

      Modifier and Type Method Description
      static void checkArgument(boolean expression) Ensures the truth of an expression.
      static void checkArgument(boolean expression, String errorMessage) Ensures the truth of an expression, with an error message.
      static void checkArgument(boolean expression, String errorMessageTemplate, Array<Object> errorMessageArgs) Ensures the truth of an expression, with an error message that takes arguments.
      static void checkState(boolean expression) Ensures the truth of an expression involving the state of the caller.
      static void checkState(boolean expression, String errorMessage) Ensures the truth of an expression involving the state of the caller, with an error message.
      static void checkState(boolean expression, String errorMessageTemplate, Array<Object> errorMessageArgs) Ensures the truth of an expression involving the state of the caller, with an error messagethat takes arguments.
      static void checkNotNull(Object reference) Ensures that an object reference is not null.
      static void checkNotNull(Object reference, String errorMessage) Ensures that an object reference is not null, with an error message.
      static void checkNotNull(Object reference, String errorMessageTemplate, Array<Object> errorMessageArgs) Ensures that an object reference is not null, with an error message that takes arguments.
      static void checkUiThread() Ensures that the current thread is the UI thread.
      static void checkUiThread(String errorMessage) Ensures that the current thread is the UI thread, with an error message.
      static void checkUiThread(String errorMessageTemplate, Array<Object> errorMessageArgs) Ensures that the current thread is the UI thread, with an error message that takesarguments.
      • Methods inherited from class java.lang.Object

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

      • checkArgument

         static void checkArgument(boolean expression)

        Ensures the truth of an expression.

      • checkArgument

         static void checkArgument(boolean expression, String errorMessage)

        Ensures the truth of an expression, with an error message.

      • checkArgument

         static void checkArgument(boolean expression, String errorMessageTemplate, Array<Object> errorMessageArgs)

        Ensures the truth of an expression, with an error message that takes arguments.

      • checkState

         static void checkState(boolean expression)

        Ensures the truth of an expression involving the state of the caller.

      • checkState

         static void checkState(boolean expression, String errorMessage)

        Ensures the truth of an expression involving the state of the caller, with an error message.

      • checkState

         static void checkState(boolean expression, String errorMessageTemplate, Array<Object> errorMessageArgs)

        Ensures the truth of an expression involving the state of the caller, with an error messagethat takes arguments.

      • checkNotNull

         static void checkNotNull(Object reference)

        Ensures that an object reference is not null.

      • checkNotNull

         static void checkNotNull(Object reference, String errorMessage)

        Ensures that an object reference is not null, with an error message.

      • checkNotNull

         static void checkNotNull(Object reference, String errorMessageTemplate, Array<Object> errorMessageArgs)

        Ensures that an object reference is not null, with an error message that takes arguments.

      • checkUiThread

         static void checkUiThread()

        Ensures that the current thread is the UI thread.

      • checkUiThread

         static void checkUiThread(String errorMessage)

        Ensures that the current thread is the UI thread, with an error message.

      • checkUiThread

         static void checkUiThread(String errorMessageTemplate, Array<Object> errorMessageArgs)

        Ensures that the current thread is the UI thread, with an error message that takesarguments.