Class Contract

java.lang.Object
com.avoka.core.util.Contract

public class Contract extends Object

Provides design by contract programming validation functions.

Since:
17.10.0
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    isFalse(boolean value, String message, Object... args)
    Ensure the specified condition value is false, or throw an IllegalArgumentExcpetion if true.
    static void
    isTrue(boolean value, String message, Object... args)
    Ensure the specified condition value is true, or throw an IllegalArgumentExcpetion if false.
    static void
    notBlank(String value, String message)
    Validate specified is not null, or blank throw a IllegalArgumentException if null or blank.
    static void
    notEmpty(Object[] array, String message, Object... args)
    Validate that the specified argument array is neither null nor a length of zero (no elements); otherwise throwing an exception with the specified message.
    static void
    notEmpty(Collection collection, String message, Object... args)
    Validate that the specified argument collection is neither null nor a size of zero (no elements); otherwise throwing an exception with the specified message.
    static void
    notEmpty(Map map, String message, Object... args)
    Validate that the specified argument map is neither null nor a size of zero (no elements); otherwise throwing an exception with the specified message.
    static void
    notNull(Object value, String message)
    Validate specified value is not null, throw a IllegalArgumentException if null.

    Methods inherited from class java.lang.Object

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

    • isTrue

      public static void isTrue(boolean value, String message, Object... args)
      Ensure the specified condition value is true, or throw an IllegalArgumentExcpetion if false.
      Parameters:
      value - the conditional value to test
      message - the IllegalArgumentException message if the conditional value is false
      args - the optional message format arguments (optional)
    • isFalse

      public static void isFalse(boolean value, String message, Object... args)
      Ensure the specified condition value is false, or throw an IllegalArgumentExcpetion if true.
      Parameters:
      value - the conditional value to test
      message - the IllegalArgumentException message if the conditional value is true
      args - the optional message format arguments (optional)
    • notNull

      public static void notNull(Object value, String message)
      Validate specified value is not null, throw a IllegalArgumentException if null.
      Parameters:
      value - the value to verify not null
      message - the IllegalArgumentException message if the conditional value is not null
    • notBlank

      public static void notBlank(String value, String message)
      Validate specified is not null, or blank throw a IllegalArgumentException if null or blank.
      Parameters:
      value - the value to verify not null, or blank
      message - the IllegalArgumentException message if the conditional value is null or blank
    • notEmpty

      public static void notEmpty(Map map, String message, Object... args)

      Validate that the specified argument map is neither null nor a size of zero (no elements); otherwise throwing an exception with the specified message.

      Contract.notEmpty(myMap, "The map must not be empty");
      Parameters:
      map - the map to check, validated not null by this method
      message - the String.format(String, Object...) exception message if invalid, not null
      args - the optional values for the formatted exception message, null array not recommended
      Throws:
      IllegalArgumentException - if the map is empty
      Since:
      18.11.0
    • notEmpty

      public static void notEmpty(Collection collection, String message, Object... args)

      Validate that the specified argument collection is neither null nor a size of zero (no elements); otherwise throwing an exception with the specified message.

      Contract.notEmpty(myCollection, "The collection must not be empty");
      Parameters:
      collection - the collection to check, validated not null by this method
      message - the String.format(String, Object...) exception message if invalid, not null
      args - the optional values for the formatted exception message, null array not recommended
      Throws:
      NullPointerException - if the collection is null
      IllegalArgumentException - if the collection is empty
      Since:
      18.11.0
    • notEmpty

      public static void notEmpty(Object[] array, String message, Object... args)

      Validate that the specified argument array is neither null nor a length of zero (no elements); otherwise throwing an exception with the specified message.

      Validate.notEmpty(myArray, "The array must not be empty");
      Parameters:
      array - the array to check, validated not null by this method
      message - the String.format(String, Object...) exception message if invalid, not null
      Throws:
      NullPointerException - if the array is null
      IllegalArgumentException - if the array is empty
      Since:
      18.11.0