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>
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:
-
Field Summary
Fields inherited from class com.luchersol.core.util.AbstractChecker
backObject, exceptionTracker, name, object, saveErrors, stop -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCheckerEnum(T enumerate, String name) Constructs a newCheckerEnumwith the specified enum and name. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Enum<T>>
CheckerEnum<T> check(T enumerate) Creates a new CheckerEnum instance with a default name.static <T extends Enum<T>>
CheckerEnum<T> Creates a new CheckerEnum instance for the given enum and name.Checks if enum name matches the expected name.hasOrdinal(int ordinal) Checks if enum ordinal matches the expected value.hasProperty(String fieldName, Object expected) Checks enum internal property using reflection.Checks if enum appears after another enum.Checks if enum appears before another enum.Checks if the enum equals the expected value.isIn(Collection<T> values) Checks inclusion against a collection.Checks inclusion against a collection.final CheckerEnum<T> Checks if the enum belongs to the specified values.isNotEqual(T value) Checks if the enum is different from the given value.final CheckerEnum<T> isNotIn(Collection<T> values) Checks if the enum does NOT belong to the specified values.final CheckerEnum<T> Checks if the enum does NOT belong to the specified values.final CheckerEnum<T> Checks if the enum does NOT belong to the specified values.isSameType(Enum<?> other) Checks if enums belong to the same declaring type.ordinalGreaterThan(int ordinal) Checks if ordinal is greater than specified value.ordinalLessThan(int ordinal) Checks if ordinal is less than specified value.protected CheckerEnum<T> self()Returns this 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
-
CheckerEnum
-
-
Method Details
-
check
Creates a new CheckerEnum instance for the given enum and name.- Type Parameters:
T- Enum type- Parameters:
enumerate- the enum value to be checkedname- the logical name used in error messages- Returns:
- a CheckerEnum instance for further validations
-
check
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
Returns this instance (for fluent API usage).- Specified by:
selfin classAbstractChecker<T extends Enum<T>,CheckerEnum<T extends Enum<T>>> - Returns:
- this CheckerEnum instance
-
isEqual
Checks if the enum equals the expected value.Uses identity comparison (==).
- Parameters:
expected- expected enum value- Returns:
- this CheckerEnum instance for chaining
-
isNotEqual
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
Checks if the enum belongs to the specified values.- Parameters:
values- allowed enum values- Returns:
- this CheckerEnum instance for chaining
-
isIn
Checks inclusion against a collection.- Parameters:
values- allowed enum values- Returns:
- this CheckerEnum instance for chaining
-
isIn
Checks inclusion against a collection.- Parameters:
values- allowed enum values- Returns:
- this CheckerEnum instance for chaining
-
isNotIn
Checks if the enum does NOT belong to the specified values.- Parameters:
values- disallowed enum values- Returns:
- this CheckerEnum instance for chaining
-
isNotIn
Checks if the enum does NOT belong to the specified values.- Parameters:
values- disallowed enum values- Returns:
- this CheckerEnum instance for chaining
-
isNotIn
Checks if the enum does NOT belong to the specified values.- Parameters:
values- disallowed enum values- Returns:
- this CheckerEnum instance for chaining
-
hasName
Checks if enum name matches the expected name.- Parameters:
name- expected enum name (case-insensitive)- Returns:
- this CheckerEnum instance for chaining
-
hasOrdinal
Checks if enum ordinal matches the expected value.- Parameters:
ordinal- expected ordinal- Returns:
- this CheckerEnum instance for chaining
-
ordinalGreaterThan
Checks if ordinal is greater than specified value.- Parameters:
ordinal- lower bound- Returns:
- this CheckerEnum instance for chaining
-
ordinalLessThan
Checks if ordinal is less than specified value.- Parameters:
ordinal- upper bound- Returns:
- this CheckerEnum instance for chaining
-
isAfter
Checks if enum appears after another enum.- Parameters:
other- reference enum- Returns:
- this CheckerEnum instance for chaining
-
isBefore
Checks if enum appears before another enum.- Parameters:
other- reference enum- Returns:
- this CheckerEnum instance for chaining
-
hasProperty
Checks enum internal property using reflection.- Parameters:
fieldName- enum field nameexpected- expected value- Returns:
- this CheckerEnum instance for chaining
-
isSameType
Checks if enums belong to the same declaring type.- Parameters:
other- enum to compare- Returns:
- this CheckerEnum instance for chaining
-