Class CheckerList<T>

java.lang.Object
util.AbstractChecker<List<T>,CheckerList<T>>
specialized_checkers.collection.CheckerList<T>
Type Parameters:
T - the type of elements in the list
All Implemented Interfaces:
InterfaceChecker<AbstractChecker<List<T>,CheckerList<T>>,List<T>>

public class CheckerList<T> extends AbstractChecker<List<T>,CheckerList<T>>
A specialized checker for List collections, providing fluent API methods to perform various checks and validations on lists.

This class extends AbstractChecker and offers methods to check for emptiness, element matching, distinctness, subset/superset relationships, and percentage-based conditions.

Example usage:


 List<String> names = Arrays.asList("Alice", "Bob", "Charlie");
 CheckerList<String> checker = CheckerList.check(names);
 checker.isEmpty().allDistinct().anyMatch(name -> name.startsWith("A"));
 
See Also:
  • Constructor Details

    • CheckerList

      protected CheckerList(List<T> list, String name)
      Constructs a new CheckerList with the specified list and name.
      Parameters:
      list - the underlying list to be wrapped by this CheckerList
      name - the name associated with this CheckerList
  • Method Details

    • check

      public static <T> CheckerList<T> check(List<T> list, String name)
      Creates a CheckerList for the given list and assigns a custom name.
      Type Parameters:
      T - the List's element type
      Parameters:
      list - the list to check
      name - the name to assign to this checker
      Returns:
      a CheckerList instance for the given list
    • check

      public static <T> CheckerList<T> check(List<T> list)
      Creates a CheckerList for the given list with a default name.
      Type Parameters:
      T - the List's element type
      Parameters:
      list - the list to check
      Returns:
      a CheckerList instance for the given list
    • self

      protected CheckerList<T> self()
      Returns this instance (for fluent API).
      Specified by:
      self in class AbstractChecker<List<T>,CheckerList<T>>
      Returns:
      this CheckerList instance
    • isEmpty

      public CheckerList<T> isEmpty()
      Checks if the list is empty.
      Returns:
      this CheckerList instance
    • anyMatch

      public CheckerList<T> anyMatch(Predicate<T> predicate)
      Checks if any element in the list matches the given predicate.
      Parameters:
      predicate - the condition to test elements
      Returns:
      this CheckerList instance
    • allMatch

      public CheckerList<T> allMatch(Predicate<T> predicate)
      Checks if all elements in the list match the given predicate.
      Parameters:
      predicate - the condition to test elements
      Returns:
      this CheckerList instance
    • allDistinct

      public CheckerList<T> allDistinct()
      Checks if all elements in the list are distinct.
      Returns:
      this CheckerList instance
    • isSubset

      public CheckerList<T> isSubset(Collection<T> collection)
      Checks if the list is a subset of the given collection.
      Parameters:
      collection - the collection to compare with
      Returns:
      this CheckerList instance
    • isSuperset

      public CheckerList<T> isSuperset(Collection<T> collection)
      Checks if the list is a superset of the given collection.
      Parameters:
      collection - the collection to compare with
      Returns:
      this CheckerList instance
    • isSufficientPercentage

      public CheckerList<T> isSufficientPercentage(Predicate<T> matching, double percentage)
      Checks if at least the specified percentage of elements in the list match the given predicate.
      Parameters:
      matching - the condition to test elements
      percentage - the minimum percentage (0-100) of elements that must match
      Returns:
      this CheckerList instance