Class CheckerSet<T>

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

public class CheckerSet<T> extends AbstractChecker<Set<T>,CheckerSet<T>>
A specialized checker for Set collections, providing fluent assertion methods for validating set properties and contents.

This class extends AbstractChecker and offers a variety of checks such as emptiness, subset/superset relationships, and element matching based on predicates.

 Example usage:
   Set<String> mySet = Set.of("a", "b", "c");
   CheckerSet.check(mySet).isSuperset(List.of("a")).isEmpty();
 
See Also:
  • Constructor Details

    • CheckerSet

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

    • check

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

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

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

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

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

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

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

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

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