Class Assert

java.lang.Object
org.eclipse.keyple.core.util.Assert

public final class Assert extends Object
Exposes useful methods for testing method call parameters and raising a IllegalArgumentException unchecked exception.
Since:
2.0.0
  • Method Details

    • getInstance

      public static Assert getInstance()
      Gets the unique instance.
      Returns:
      the instance
    • notNull

      public Assert notNull(Object obj, String name)
      Assert that the input object is not null.
      Parameters:
      obj - the object to check
      name - the object name
      Returns:
      the current instance
      Throws:
      IllegalArgumentException - if object is null
      Since:
      2.0.0
    • notEmpty

      public Assert notEmpty(String obj, String name)
      Assert that the input string is not null and not empty.
      Parameters:
      obj - the object to check
      name - the object name
      Returns:
      the current instance
      Throws:
      IllegalArgumentException - if object is null or empty
      Since:
      2.0.0
    • notEmpty

      public Assert notEmpty(Collection<?> obj, String name)
      Assert that a collection of objects is not null and not empty.
      Parameters:
      obj - the object to check
      name - the object name
      Returns:
      the current instance
      Throws:
      IllegalArgumentException - if object is null or empty
      Since:
      2.0.0
    • notEmpty

      public Assert notEmpty(byte[] obj, String name)
      Assert that a byte array is not null and not empty.
      Parameters:
      obj - the object to check
      name - the object name
      Returns:
      the current instance
      Throws:
      IllegalArgumentException - if object is null or empty
      Since:
      2.0.0
    • isTrue

      public Assert isTrue(Boolean condition, String name)
      Assert that a condition is true.
      Parameters:
      condition - the condition to check
      name - the object name
      Returns:
      the current instance
      Throws:
      IllegalArgumentException - if condition is null or false
      Since:
      2.0.0
    • greaterOrEqual

      public Assert greaterOrEqual(Integer number, int minValue, String name)
      Assert that an integer is not null and is greater than or equal to minValue.
      Parameters:
      number - the number to check
      minValue - the min accepted value
      name - the object name
      Returns:
      the current instance
      Throws:
      IllegalArgumentException - if number is null or has a value less than minValue.
      Since:
      2.0.0
    • isEqual

      public Assert isEqual(Integer number, int value, String name)
      Assert that an integer is equal to value.
      Parameters:
      number - the number to check
      value - the expected value
      name - the object name
      Returns:
      the current instance
      Throws:
      IllegalArgumentException - if number is null or has a value less than minValue.
      Since:
      2.0.0
    • isInRange

      public Assert isInRange(Integer number, int minValue, int maxValue, String name)
      Assert that an integer is not null and is in the range minValue, maxValue.
      Parameters:
      number - the number to check
      minValue - the min accepted value
      maxValue - the max accepted value
      name - the object name
      Returns:
      the current instance
      Throws:
      IllegalArgumentException - if number is null or is out of range.
      Since:
      2.0.0
    • isHexString

      public Assert isHexString(String hex, String name)
      Assert that a string has a valid hexadecimal format.
      Parameters:
      hex - The string to check.
      name - The object name.
      Returns:
      The current instance.
      Throws:
      IllegalArgumentException - If the provided string is null, empty or has not a valid hexadecimal format.
      Since:
      2.1.0