Package org.kiwiproject.beta.base
Class KiwiCasts2.StandardCollectionCheckStrategy
java.lang.Object
org.kiwiproject.beta.base.KiwiCasts2.StandardCollectionCheckStrategy
- All Implemented Interfaces:
KiwiCasts2.CollectionCheckStrategy
- Enclosing class:
- KiwiCasts2
public static class KiwiCasts2.StandardCollectionCheckStrategy
extends Object
implements KiwiCasts2.CollectionCheckStrategy
Standard implementation of
KiwiCasts2.CollectionCheckStrategy that allows configuring
the number of non-null and type checks to perform.-
Method Summary
Modifier and TypeMethodDescription<T> Collection<T>checkElements(Class<T> expectedType, Collection<T> coll) Checks that elements in the collection are of the expected type.of(int maxNonNullChecks, int maxElementTypeChecks) Creates a new instance with the specified maximum non-null and type checks.Creates a new instance with default settings for maximum non-null and type checks.
-
Method Details
-
ofDefaults
Creates a new instance with default settings for maximum non-null and type checks.Uses
KiwiCasts2.DEFAULT_MAX_NON_NULL_CHECKSandKiwiCasts2.DEFAULT_MAX_TYPE_CHECKSas the values formaxNonNullChecksandmaxElementTypeChecks, respectively.- Returns:
- a new instance
-
of
public static KiwiCasts2.StandardCollectionCheckStrategy of(int maxNonNullChecks, int maxElementTypeChecks) Creates a new instance with the specified maximum non-null and type checks.- Parameters:
maxNonNullChecks- the maximum number of non-null checks to performmaxElementTypeChecks- the maximum number of element type checks to perform- Returns:
- a new instance with the specified settings
-
checkElements
public <T> Collection<T> checkElements(Class<T> expectedType, Collection<T> coll) throws TypeMismatchException Checks that elements in the collection are of the expected type.- Specified by:
checkElementsin interfaceKiwiCasts2.CollectionCheckStrategy- Type Parameters:
T- the expected element type- Parameters:
expectedType- the expected type of elements in the collectioncoll- the collection to check- Returns:
- the original collection if all elements match the expected type
- Throws:
TypeMismatchException- if an element is found with an incompatible type
-