Class Ensures

java.lang.Object
net.apartium.cocoabeans.Ensures

public class Ensures extends Object
Helper class used to validate conditions
  • Constructor Details

    • Ensures

      public Ensures()
  • Method Details

    • notEmpty

      public static void notEmpty(String string, RuntimeException ex)
      Validates if a String is empty or not
      Parameters:
      string - the String instance to perform the validation on
      ex - the exception to throw if the String is empty
      Throws:
      RuntimeException - ex if argument does not match requested precondition
    • notNull

      public static void notNull(Object obj, RuntimeException ex)
      Checks if an object is null.
      Parameters:
      obj - the object instance to check
      ex - the exception to throw if the object is null, if null will be replaced by npe
      Throws:
      RuntimeException - ex if argument does not match requested precondition
    • notEmpty

      public static void notEmpty(Collection<?> collection, RuntimeException ex)
      Makes sure that given collection is not null or empty
      Parameters:
      collection - the collection to check
      ex - the exception to throw if the object does not match requested precondition
      Throws:
      RuntimeException - ex if argument does not match requested precondition
    • notEmpty

      public static void notEmpty(Collection<?> collection, String message)
      Makes sure that given collection is not null or empty
      Parameters:
      collection - the collection to check
      message - the message, "+-" will be replaced to "cannot be null or empty"
      Throws:
      RuntimeException - ex if argument does not match requested precondition
    • notEmpty

      public static void notEmpty(Map<?,?> map, RuntimeException ex)
      Makes sure that given map is not null or empty
      Parameters:
      map - the map to check
      ex - the exception to throw if the object does not match requested precondition
      Throws:
      RuntimeException - ex if argument does not match requested precondition
    • notEmpty

      public static void notEmpty(Map<?,?> map, String message)
      Makes sure that given map is not null or empty
      Parameters:
      map - the map object to check
      message - the message, "+-" will be replaced to "cannot be null or empty"
      Throws:
      RuntimeException - if argument does not match requested precondition
    • notEmpty

      public static void notEmpty(Object[] array, RuntimeException ex)
      Make sure that given array is not null or empty
      Parameters:
      array - the array to check
      ex - the exception to throw if the object is invalid
      Throws:
      RuntimeException - ex if argument does not match requested precondition
    • notEmpty

      public static void notEmpty(Object[] array, String message)
      Makes sure that given array is not null or empty
      Parameters:
      array - the array to check
      message - the message, "+-" will be replaced to "cannot be null or empty"
      Throws:
      RuntimeException - ex if argument does not match requested precondition
    • notNull

      public static void notNull(Object obj, String message)
      Make sure an object is not null.
      Parameters:
      obj - the object to check
      message - the message to throw with the exception if the object is null, +- will be replaced with "cannot be null"
      Throws:
      NullPointerException - ex if argument does not match requested precondition
    • notEmpty

      public static void notEmpty(String string, String message)
      Makes sure given string is not null or empty
      Parameters:
      string - the String instance to validate on
      message - the message to throw with the exception if the String is empty, "+-" will be replaced to "cannot be null or empty"
      Throws:
      RuntimeException - if argument does not match requested precondition
    • largerThan

      public static void largerThan(int num1, int num2, RuntimeException ex)
      Makes sure given number is larger than second given number.
      Parameters:
      num1 - the first number
      num2 - the second number
      ex - the exception to throw if not larger than
      Throws:
      RuntimeException - if argument does not match requested precondition
    • largerThan

      public static void largerThan(int num1, int num2, String message)
      Makes sure given number is larger than second given number.
      Parameters:
      num1 - the first number
      num2 - the second number
      message - the message, "+-" will be replaced to "must be larger than"
      Throws:
      RuntimeException - if argument does not match requested precondition
    • isTrue

      public static void isTrue(boolean bool)
      Makes sure given condition is true
      Parameters:
      bool - the condition
      Throws:
      RuntimeException - if argument does not match requested precondition
    • isTrue

      public static void isTrue(boolean bool, String message)
      Makes sure given condition is true
      Parameters:
      bool - the condition
      message - the message to send with the exception, "+-" will be replaced with "must be true"
      Throws:
      RuntimeException - if argument does not match requested precondition
    • isTrue

      public static void isTrue(boolean bool, RuntimeException ex)
      Makes sure given condition is true
      Parameters:
      bool - the condition
      ex - the exception to throw if the boolean is false
      Throws:
      RuntimeException - ex if argument does not match requested precondition
    • isFalse

      @AvailableSince("0.0.40") public static void isFalse(boolean bool, RuntimeException ex)
      Makes sure given condition is false
      Parameters:
      bool - the condition
      ex - the exception to throw if the boolean is true
      Throws:
      RuntimeException - ex if argument does not match requested precondition
    • isFalse

      @AvailableSince("0.0.40") public static void isFalse(boolean bool)
      Makes sure given condition is false
      Parameters:
      bool - the condition
      Throws:
      RuntimeException - if argument does not match requested precondition
    • isFalse

      @AvailableSince("0.0.40") public static void isFalse(boolean bool, String message)
      Makes sure given condition is false
      Parameters:
      bool - the condition
      message - the message to send with the exception, "+-" will be replaced with "must be false"
      Throws:
      RuntimeException - if argument does not match requested precondition