Class CheckerEnum<T extends Enum<T>>

java.lang.Object
com.luchersol.core.util.AbstractChecker<T,CheckerEnum<T>>
com.luchersol.core.specialized_checkers.CheckerEnum<T>
Type Parameters:
T - Enum type being validated
All Implemented Interfaces:
InterfaceChecker<AbstractChecker<T,CheckerEnum<T>>,T>

public class CheckerEnum<T extends Enum<T>> extends AbstractChecker<T,CheckerEnum<T>>
A specialized checker for Enum instances, providing a fluent API to assert enum properties such as equality, name, ordinal, inclusion, ordering and reflective attributes.

Typical usage:


 CheckerEnum.check(status)
     .is(Status.ACTIVE)
     .isNot(Status.CANCELLED)
     .hasName("ACTIVE")
     .ordinalGreaterThan(0)
     .isIn(Status.ACTIVE, Status.PENDING);
 

Custom rule example:


 CheckerEnum.check(status)
     .matches(s -> s.ordinal() >= Status.ACTIVE.ordinal(),
              "status must be ACTIVE or higher");
 

Reflective property example:


 CheckerEnum.check(status)
     .hasProperty("enabled", true);
 

This class supports chaining multiple assertions in a fluent style and integrates with AbstractChecker for generalized validation handling.

See Also:
  • Constructor Details

    • CheckerEnum

      protected CheckerEnum(T enumerate, String name)
      Constructs a new CheckerEnum with the specified enum and name.
      Parameters:
      enumerate - the enum instance associated with this checker
      name - the logical name of the enum
  • Method Details

    • check

      public static <T extends Enum<T>> CheckerEnum<T> check(T enumerate, String name)
      Creates a new CheckerEnum instance for the given enum and name.
      Type Parameters:
      T - Enum type
      Parameters:
      enumerate - the enum value to be checked
      name - the logical name used in error messages
      Returns:
      a CheckerEnum instance for further validations
    • check

      public static <T extends Enum<T>> CheckerEnum<T> check(T enumerate)
      Creates a new CheckerEnum instance with a default name.
      Type Parameters:
      T - Enum type
      Parameters:
      enumerate - the enum value to be checked
      Returns:
      a CheckerEnum instance for further validations
    • self

      protected CheckerEnum<T> self()
      Returns this instance (for fluent API usage).
      Specified by:
      self in class AbstractChecker<T extends Enum<T>,CheckerEnum<T extends Enum<T>>>
      Returns:
      this CheckerEnum instance
    • isEqual

      public CheckerEnum<T> isEqual(T expected)
      Checks if the enum equals the expected value.

      Uses identity comparison (==).

      Parameters:
      expected - expected enum value
      Returns:
      this CheckerEnum instance for chaining
    • isNotEqual

      public CheckerEnum<T> isNotEqual(T value)
      Checks if the enum is different from the given value.
      Parameters:
      value - enum value that must not match
      Returns:
      this CheckerEnum instance for chaining
    • isIn

      @SafeVarargs public final CheckerEnum<T> isIn(T... values)
      Checks if the enum belongs to the specified values.
      Parameters:
      values - allowed enum values
      Returns:
      this CheckerEnum instance for chaining
    • isIn

      public CheckerEnum<T> isIn(Collection<T> values)
      Checks inclusion against a collection.
      Parameters:
      values - allowed enum values
      Returns:
      this CheckerEnum instance for chaining
    • isIn

      public CheckerEnum<T> isIn(EnumSet<T> values)
      Checks inclusion against a collection.
      Parameters:
      values - allowed enum values
      Returns:
      this CheckerEnum instance for chaining
    • isNotIn

      @SafeVarargs public final CheckerEnum<T> isNotIn(T... values)
      Checks if the enum does NOT belong to the specified values.
      Parameters:
      values - disallowed enum values
      Returns:
      this CheckerEnum instance for chaining
    • isNotIn

      public final CheckerEnum<T> isNotIn(Collection<T> values)
      Checks if the enum does NOT belong to the specified values.
      Parameters:
      values - disallowed enum values
      Returns:
      this CheckerEnum instance for chaining
    • isNotIn

      public final CheckerEnum<T> isNotIn(EnumSet<T> values)
      Checks if the enum does NOT belong to the specified values.
      Parameters:
      values - disallowed enum values
      Returns:
      this CheckerEnum instance for chaining
    • hasName

      public CheckerEnum<T> hasName(String name)
      Checks if enum name matches the expected name.
      Parameters:
      name - expected enum name (case-insensitive)
      Returns:
      this CheckerEnum instance for chaining
    • hasOrdinal

      public CheckerEnum<T> hasOrdinal(int ordinal)
      Checks if enum ordinal matches the expected value.
      Parameters:
      ordinal - expected ordinal
      Returns:
      this CheckerEnum instance for chaining
    • ordinalGreaterThan

      public CheckerEnum<T> ordinalGreaterThan(int ordinal)
      Checks if ordinal is greater than specified value.
      Parameters:
      ordinal - lower bound
      Returns:
      this CheckerEnum instance for chaining
    • ordinalLessThan

      public CheckerEnum<T> ordinalLessThan(int ordinal)
      Checks if ordinal is less than specified value.
      Parameters:
      ordinal - upper bound
      Returns:
      this CheckerEnum instance for chaining
    • isAfter

      public CheckerEnum<T> isAfter(T other)
      Checks if enum appears after another enum.
      Parameters:
      other - reference enum
      Returns:
      this CheckerEnum instance for chaining
    • isBefore

      public CheckerEnum<T> isBefore(T other)
      Checks if enum appears before another enum.
      Parameters:
      other - reference enum
      Returns:
      this CheckerEnum instance for chaining
    • hasProperty

      public CheckerEnum<T> hasProperty(String fieldName, Object expected)
      Checks enum internal property using reflection.
      Parameters:
      fieldName - enum field name
      expected - expected value
      Returns:
      this CheckerEnum instance for chaining
    • isSameType

      public CheckerEnum<T> isSameType(Enum<?> other)
      Checks if enums belong to the same declaring type.
      Parameters:
      other - enum to compare
      Returns:
      this CheckerEnum instance for chaining