Class CheckerArray<T>

java.lang.Object
util.AbstractChecker<T[],CheckerArray<T>>
specialized_checkers.math.CheckerArray<T>
Type Parameters:
T - the type of the elements in the array being checked
All Implemented Interfaces:
InterfaceChecker<AbstractChecker<T[],CheckerArray<T>>,T[]>

public class CheckerArray<T> extends AbstractChecker<T[],CheckerArray<T>>
Checker for array instances, providing fluent validation methods for arrays of any reference type.

This class allows you to validate and assert properties of array objects in a fluent and readable way.

  • Constructor Details

    • CheckerArray

      protected CheckerArray(T[] array, String name)
      Constructs a new CheckerArray with the specified array and name.
      Parameters:
      array - the array to be used by this checker
      name - the name identifying this checker
  • Method Details

    • check

      public static <T> CheckerArray<T> check(T[] array, String name)
      Creates a new CheckerArray for the given array instance with a custom name.
      Type Parameters:
      T - the type of the elements in the array
      Parameters:
      array - the array instance to be checked
      name - the name to identify this checker instance (useful for error messages)
      Returns:
      a new CheckerArray for the provided array
    • check

      public static <T> CheckerArray<T> check(T[] array)
      Creates a new CheckerArray for the given array instance with a default name.
      Type Parameters:
      T - the type of the elements in the array
      Parameters:
      array - the array instance to be checked
      Returns:
      a new CheckerArray for the provided array
    • self

      protected CheckerArray<T> self()
      Returns this checker instance (for fluent API usage).
      Specified by:
      self in class AbstractChecker<T[],CheckerArray<T>>
      Returns:
      this CheckerArray instance
    • isEmpty

      public CheckerArray<T> isEmpty()
      Asserts that the array is empty (has zero length).
      Returns:
      this CheckerArray instance for further validation
    • isSortedAsc

      public CheckerArray<T> isSortedAsc(Comparator<T> comparator)
      Asserts that the array is sorted in ascending order according to the provided comparator.
      Parameters:
      comparator - the comparator to determine the order of the array
      Returns:
      this CheckerArray instance for further validation
    • isSortedAsc

      public CheckerArray<T> isSortedAsc()
      Asserts that the array is sorted in ascending order according to the natural ordering of its elements.
      Returns:
      this CheckerArray instance for further validation
    • isSortedDesc

      public CheckerArray<T> isSortedDesc(Comparator<T> comparator)
      Asserts that the array is sorted in descending order according to the provided comparator.
      Parameters:
      comparator - the comparator to determine the order of the array
      Returns:
      this CheckerArray instance for further validation
    • isSortedDesc

      public CheckerArray<T> isSortedDesc()
      Asserts that the array is sorted in descending order according to the natural ordering of its elements.
      Returns:
      this CheckerArray instance for further validation
    • isSufficientPercentage

      public CheckerArray<T> isSufficientPercentage(Predicate<T> matching, double percentage)
      Asserts that at least the given percentage of elements in the array match the provided predicate.
      Parameters:
      matching - the predicate to test elements
      percentage - the minimum percentage of elements that must match
      Returns:
      this CheckerArray instance for further validation
    • anyMatch

      public CheckerArray<T> anyMatch(Predicate<T> predicate)
      Asserts that any element in the array matches the provided predicate.
      Parameters:
      predicate - the predicate to test elements
      Returns:
      this CheckerArray instance for further validation
    • allMatch

      public CheckerArray<T> allMatch(Predicate<T> predicate)
      Asserts that all elements in the array match the provided predicate.
      Parameters:
      predicate - the predicate to test elements
      Returns:
      this CheckerArray instance for further validation