Class Checks


  • public final class Checks
    extends java.lang.Object
    Common facilities to check precondition, postcondition and invariants.
    • Constructor Summary

      Constructors 
      Constructor Description
      Checks()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void checkArgument​(boolean condition, java.lang.String message)
      Checks that an argument satisfies requirement.
      static void checkArgument​(boolean condition, java.lang.String message, java.lang.Object... args)
      Checks that an argument satisfies requirement.
      static int checkMax​(int max)
      Checks that max isn't negative.
      static int checkMin​(int min)
      Checks that min isn't negative.
      static void checkMinMax​(int min, int max)
      Checks that neither min or max is negative and min <= max.
      static int checkNonNegative​(int n, java.lang.String message)
      Checks that n isn't negative.
      static <T> T checkNotNull​(T value)
      Checks that value cannot be null.
      static void checkNotNullState​(java.lang.Object object, java.lang.String message)
      Checks that object is not null.
      static void checkNotNullState​(java.lang.Object object, java.lang.String message, java.lang.Object... args)
      Checks that object is not null.
      static void checkState​(boolean condition, java.lang.String message)
      Checks a certain state.
      static void checkState​(boolean condition, java.lang.String message, java.lang.Object... args)
      Checks a certain state.
      • Methods inherited from class java.lang.Object

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

      • Checks

        public Checks()
    • Method Detail

      • checkNotNull

        public static <T> T checkNotNull​(T value)
                                  throws java.lang.NullPointerException
        Checks that value cannot be null.
        Throws:
        java.lang.NullPointerException
      • checkArgument

        public static void checkArgument​(boolean condition,
                                         java.lang.String message)
                                  throws java.lang.IllegalArgumentException
        Checks that an argument satisfies requirement.
        Parameters:
        condition - the condition that has to be true
        message - the error message if condition is false
        args - the arguments to the error message
        Throws:
        java.lang.IllegalArgumentException - if condition is false
      • checkArgument

        public static void checkArgument​(boolean condition,
                                         java.lang.String message,
                                         java.lang.Object... args)
                                  throws java.lang.IllegalArgumentException
        Checks that an argument satisfies requirement.
        Parameters:
        condition - the condition that has to be true
        message - the error message if condition is false
        args - the arguments to the error message
        Throws:
        java.lang.IllegalArgumentException - if condition is false
      • checkState

        public static void checkState​(boolean condition,
                                      java.lang.String message)
                               throws java.lang.IllegalStateException
        Checks a certain state.
        Parameters:
        condition - the condition of the state that has to be true
        message - the error message if condition is false
        args - the arguments to the error message
        Throws:
        java.lang.IllegalStateException - if condition is false
      • checkState

        public static void checkState​(boolean condition,
                                      java.lang.String message,
                                      java.lang.Object... args)
                               throws java.lang.IllegalStateException
        Checks a certain state.
        Parameters:
        condition - the condition of the state that has to be true
        message - the error message if condition is false
        args - the arguments to the error message
        Throws:
        java.lang.IllegalStateException - if condition is false
      • checkNotNullState

        public static void checkNotNullState​(java.lang.Object object,
                                             java.lang.String message)
        Checks that object is not null.
        Parameters:
        object - the object that cannot be null
        message - the error message if condition is false
        args - the arguments to the error message
        Throws:
        java.lang.IllegalStateException - if object is null
      • checkNotNullState

        public static void checkNotNullState​(java.lang.Object object,
                                             java.lang.String message,
                                             java.lang.Object... args)
        Checks that object is not null.
        Parameters:
        object - the object that cannot be null
        message - the error message if condition is false
        args - the arguments to the error message
        Throws:
        java.lang.IllegalStateException - if object is null
      • checkMinMax

        public static void checkMinMax​(int min,
                                       int max)
        Checks that neither min or max is negative and min &lt;= max.
      • checkMin

        public static int checkMin​(int min)
        Checks that min isn't negative.
      • checkMax

        public static int checkMax​(int max)
        Checks that max isn't negative.
      • checkNonNegative

        public static int checkNonNegative​(int n,
                                           java.lang.String message)
        Checks that n isn't negative. Or throws an IllegalArgumentException with message.