Class CheckerList<T>
- Type Parameters:
T
- the type of elements in the list
- All Implemented Interfaces:
InterfaceChecker<AbstractChecker<List<T>,
CheckerList<T>>, List<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:
-
Field Summary
Fields inherited from class util.AbstractChecker
backObject, exceptionTracker, name, object, saveErrors, stop
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
CheckerList
(List<T> list, String name) Constructs a newCheckerList
with the specified list and name. -
Method Summary
Modifier and TypeMethodDescriptionChecks if all elements in the list are distinct.Checks if all elements in the list match the given predicate.Checks if any element in the list matches the given predicate.static <T> CheckerList
<T> Creates a CheckerList for the given list with a default name.static <T> CheckerList
<T> Creates a CheckerList for the given list and assigns a custom name.isEmpty()
Checks if the list is empty.isSubset
(Collection<T> collection) Checks if the list is a subset of the given collection.isSufficientPercentage
(Predicate<T> matching, double percentage) Checks if at least the specified percentage of elements in the list match the given predicate.isSuperset
(Collection<T> collection) Checks if the list is a superset of the given collection.protected CheckerList
<T> self()
Returns this instance (for fluent API).Methods inherited from class util.AbstractChecker
checkProperty, checkProperty, checkProperty, end, getMethod, getObject, getProperty, hasErrors, hasNotErrors, is, is, isEqual, isNonNull, isNot, isNot, isNull, notSaveErrors, saveErrors, show, showNotThrownException, showThrownException, stop
-
Constructor Details
-
CheckerList
-
-
Method Details
-
check
Creates a CheckerList for the given list and assigns a custom name.- Type Parameters:
T
- theList
's element type- Parameters:
list
- the list to checkname
- the name to assign to this checker- Returns:
- a CheckerList instance for the given list
-
check
Creates a CheckerList for the given list with a default name.- Type Parameters:
T
- theList
's element type- Parameters:
list
- the list to check- Returns:
- a CheckerList instance for the given list
-
self
Returns this instance (for fluent API).- Specified by:
self
in classAbstractChecker<List<T>,
CheckerList<T>> - Returns:
- this CheckerList instance
-
isEmpty
-
anyMatch
Checks if any element in the list matches the given predicate.- Parameters:
predicate
- the condition to test elements- Returns:
- this CheckerList instance
-
allMatch
Checks if all elements in the list match the given predicate.- Parameters:
predicate
- the condition to test elements- Returns:
- this CheckerList instance
-
allDistinct
Checks if all elements in the list are distinct.- Returns:
- this CheckerList instance
-
isSubset
Checks if the list is a subset of the given collection.- Parameters:
collection
- the collection to compare with- Returns:
- this CheckerList instance
-
isSuperset
Checks if the list is a superset of the given collection.- Parameters:
collection
- the collection to compare with- Returns:
- this CheckerList instance
-
isSufficientPercentage
Checks if at least the specified percentage of elements in the list match the given predicate.- Parameters:
matching
- the condition to test elementspercentage
- the minimum percentage (0-100) of elements that must match- Returns:
- this CheckerList instance
-