Record Class Throwing<T>
java.lang.Object
java.lang.Record
com.winterhavenmc.library.messagebuilder.validation.Throwing<T>
- Type Parameters:
T
- the type of the value being validated
- All Implemented Interfaces:
Validator<T>
public record Throwing<T>(Supplier<ValidationException> exceptionSupplier)
extends Record
implements Validator<T>
A
Validator
implementation that throws a ValidationException
when a value fails validation.
The exception is supplied via a Supplier
, allowing
lazy instantiation and support for dynamic message construction.
The exception's stack trace is reset via Throwable.fillInStackTrace()
to ensure that the reported call site accurately reflects the point of failure,
rather than the supplier's origin.
Typical usage:
validate(value, Predicate, Validator.throwing(ErrorMessageKey, Parameter));
- See Also:
-
Field Summary
Fields inherited from interface com.winterhavenmc.library.messagebuilder.validation.Validator
BUNDLE_NAME
-
Constructor Summary
ConstructorsConstructorDescriptionThrowing
(Supplier<ValidationException> exceptionSupplier) Creates an instance of aThrowing
record class. -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
Indicates whether some other object is "equal to" this one.Returns the value of theexceptionSupplier
record component.handleInvalid
(T value) Throws the supplied exception when the value is invalid.final int
hashCode()
Returns a hash code value for this object.final String
toString()
Returns a string representation of this record class.
-
Constructor Details
-
Throwing
Creates an instance of aThrowing
record class.- Parameters:
exceptionSupplier
- the value for theexceptionSupplier
record component
-
-
Method Details
-
handleInvalid
Throws the supplied exception when the value is invalid.- Specified by:
handleInvalid
in interfaceValidator<T>
- Parameters:
value
- the invalid value- Returns:
- never returns normally
- Throws:
ValidationException
- always thrown when this handler is invoked
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object)
. -
exceptionSupplier
Returns the value of theexceptionSupplier
record component.- Returns:
- the value of the
exceptionSupplier
record component
-