Class CheckerMap<K,V>
java.lang.Object
com.luchersol.core.util.AbstractChecker<Map<K,V>,CheckerMap<K,V>>
com.luchersol.core.specialized_checkers.collection.CheckerMap<K,V>
- Type Parameters:
K- the type of keys maintained by the mapV- the type of mapped values
- All Implemented Interfaces:
InterfaceChecker<AbstractChecker<Map<K,V>, CheckerMap<K, V>>, Map<K, V>>
A specialized checker for
Map instances, providing fluent assertion methods
for validating map properties and contents.
This class extends AbstractChecker and allows for expressive, chainable
checks on Map objects, such as verifying emptiness, matching entries
against predicates, and more.
Example usage:
Map<String, Integer> ages = Map.of("Alice", 19, "Bob", 40);
CheckerMap<String> checker = CheckerMap.check(ages)
.isEmpty()
.anyMatch((name, age) -> name.startsWith("A") && age >= 18);
- See Also:
-
Field Summary
Fields inherited from class com.luchersol.core.util.AbstractChecker
backObject, exceptionTracker, name, object, saveErrors, stop -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCheckerMap(Map<K, V> map, String name) Constructs a newCheckerMapwith the specified backing map and name. -
Method Summary
Modifier and TypeMethodDescriptionCheckerMap<K, V> allMatch(BiPredicate<K, V> predicate) Checks if all entries in the map match the given bi-predicate.CheckerMap<K, V> Checks if all entries in the map match the given predicate.CheckerMap<K, V> anyMatch(BiPredicate<K, V> predicate) Checks if any entry in the map matches the given bi-predicate.CheckerMap<K, V> Checks if any entry in the map matches the given predicate.static <K,V> CheckerMap <K, V> Creates a CheckerMap for the given map with a default name.static <K,V> CheckerMap <K, V> Creates a CheckerMap for the given map and assigns a custom name.CheckerMap<K, V> isEmpty()Checks if the map is empty.protected CheckerMap<K, V> self()Returns this instance (for fluent API).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
-
CheckerMap
-
-
Method Details
-
check
Creates a CheckerMap for the given map and assigns a custom name.- Type Parameters:
K- theMap's key typeV- theMap's value type- Parameters:
map- the map to checkname- the name to assign to this checker- Returns:
- a CheckerMap instance for the given map
-
check
Creates a CheckerMap for the given map with a default name.- Type Parameters:
K- theMap's key typeV- theMap's value type- Parameters:
map- the map to check- Returns:
- a CheckerMap instance for the given map
-
self
Returns this instance (for fluent API).- Specified by:
selfin classAbstractChecker<Map<K,V>, CheckerMap<K, V>> - Returns:
- this CheckerMap instance
-
isEmpty
-
anyMatch
-
anyMatch
Checks if any entry in the map matches the given bi-predicate.- Parameters:
predicate- the condition to test key-value pairs- Returns:
- this CheckerMap instance
-
allMatch
-
allMatch
Checks if all entries in the map match the given bi-predicate.- Parameters:
predicate- the condition to test key-value pairs- Returns:
- this CheckerMap instance
-