Class CheckerArray<T>
java.lang.Object
com.luchersol.core.util.AbstractChecker<T[],CheckerArray<T>>
com.luchersol.core.specialized_checkers.math.CheckerArray<T>
- Type Parameters:
T- the type of the array elements
- All Implemented Interfaces:
InterfaceChecker<AbstractChecker<T[],CheckerArray<T>>, T[]>
A specialized checker for array instances, providing fluent API methods
to assert various properties such as emptiness, sorting order (ascending/descending),
element matching conditions, and percentage-based validations.
Typical usage:
String[] names = {"Alice", "Bob", "Charlie"};
CheckerArray<String> checker = CheckerArray.check(names)
.isSortedAsc()
.anyMatch(name -> name.startsWith("A"))
.isSufficientPercentage(n -> n.length() > 2, 50.0);
This class supports chaining multiple assertions in a fluent style, making array validations more expressive and readable.
- See Also:
-
Field Summary
Fields inherited from class com.luchersol.core.util.AbstractChecker
backObject, exceptionTracker, name, object, saveErrors, stop -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCheckerArray(T[] array, String name) Constructs a newCheckerArraywith the specified array and name. -
Method Summary
Modifier and TypeMethodDescriptionAsserts that all elements in the array match the provided predicate.Asserts that any element in the array matches the provided predicate.static <T> CheckerArray<T> check(T[] array) Creates a newCheckerArrayfor the given array instance with a default name.static <T> CheckerArray<T> Creates a newCheckerArrayfor the given array instance with a custom name.isEmpty()Asserts that the array is empty (has zero length).Asserts that the array is sorted in ascending order according to the natural ordering of its elements.isSortedAsc(Comparator<T> comparator) Asserts that the array is sorted in ascending order according to the provided comparator.Asserts that the array is sorted in descending order according to the natural ordering of its elements.isSortedDesc(Comparator<T> comparator) Asserts that the array is sorted in descending order according to the provided comparator.isSufficientPercentage(Predicate<T> matching, double percentage) Asserts that at least the given percentage of elements in the array match the provided predicate.protected CheckerArray<T> self()Returns this checker instance (for fluent API usage).Methods inherited from class com.luchersol.core.util.AbstractChecker
checkProperty, checkProperty, checkProperty, checkProperty, end, getMethod, getObject, getProperty, hasErrors, hasNotErrors, is, is, is, isEqual, isNonNull, isNot, isNot, isNull, notSaveErrors, saveErrors, setBackObject, setExceptionTracker, setName, setObject, setSaveErrors, setStop, show, showPassedChecks, showThrownException, stop, toChecker, updateChecker
-
Constructor Details
-
CheckerArray
-
-
Method Details
-
check
Creates a newCheckerArrayfor 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 checkedname- the name to identify this checker instance (useful for error messages)- Returns:
- a new
CheckerArrayfor the provided array
-
check
Creates a newCheckerArrayfor 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
CheckerArrayfor the provided array
-
self
Returns this checker instance (for fluent API usage).- Specified by:
selfin classAbstractChecker<T[],CheckerArray<T>> - Returns:
- this
CheckerArrayinstance
-
isEmpty
Asserts that the array is empty (has zero length).- Returns:
- this
CheckerArrayinstance for further validation
-
isSortedAsc
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
CheckerArrayinstance for further validation
-
isSortedAsc
Asserts that the array is sorted in ascending order according to the natural ordering of its elements.- Returns:
- this
CheckerArrayinstance for further validation
-
isSortedDesc
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
CheckerArrayinstance for further validation
-
isSortedDesc
Asserts that the array is sorted in descending order according to the natural ordering of its elements.- Returns:
- this
CheckerArrayinstance for further validation
-
isSufficientPercentage
Asserts that at least the given percentage of elements in the array match the provided predicate.- Parameters:
matching- the predicate to test elementspercentage- the minimum percentage of elements that must match- Returns:
- this
CheckerArrayinstance for further validation
-
anyMatch
Asserts that any element in the array matches the provided predicate.- Parameters:
predicate- the predicate to test elements- Returns:
- this
CheckerArrayinstance for further validation
-
allMatch
Asserts that all elements in the array match the provided predicate.- Parameters:
predicate- the predicate to test elements- Returns:
- this
CheckerArrayinstance for further validation
-