Class KiwiCasts2.StandardListCheckStrategy

java.lang.Object
org.kiwiproject.beta.base.KiwiCasts2.StandardListCheckStrategy
All Implemented Interfaces:
KiwiCasts2.ListCheckStrategy
Enclosing class:
KiwiCasts2

public static class KiwiCasts2.StandardListCheckStrategy extends Object implements KiwiCasts2.ListCheckStrategy
Standard implementation of KiwiCasts2.ListCheckStrategy that allows configuring the number of non-null and type checks to perform.
  • Method Details

    • ofDefaults

      public static KiwiCasts2.StandardListCheckStrategy ofDefaults()
      Creates a new instance with default settings for maximum non-null and type checks.

      Uses KiwiCasts2.DEFAULT_MAX_NON_NULL_CHECKS and KiwiCasts2.DEFAULT_MAX_TYPE_CHECKS as the values for maxNonNullChecks and maxElementTypeChecks, respectively.

      Returns:
      a new instance
    • of

      public static KiwiCasts2.StandardListCheckStrategy 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 perform
      maxElementTypeChecks - the maximum number of element type checks to perform
      Returns:
      a new instance with the specified settings
    • checkElements

      public <T> List<T> checkElements(Class<T> expectedType, List<T> list) throws TypeMismatchException
      Checks that elements in the list are of the expected type.
      Specified by:
      checkElements in interface KiwiCasts2.ListCheckStrategy
      Type Parameters:
      T - the expected element type
      Parameters:
      expectedType - the expected type of elements in the list
      list - the list to check
      Returns:
      the original list if all elements match the expected type
      Throws:
      TypeMismatchException - if an element is found with an incompatible type