Record Class Logging<T>
java.lang.Object
java.lang.Record
com.winterhavenmc.library.messagebuilder.validation.Logging<T>
- Type Parameters:
T
- the type of the value being validated
- All Implemented Interfaces:
Validator<T>
public record Logging<T>(LogLevel logLevel, ErrorMessageKey messageKey, Parameter parameter)
extends Record
implements Validator<T>
A
Validator
implementation that logs a warning or error
when a value fails validation, but does not throw.
This handler is useful in cases where validation failures are non-critical or should be tracked without disrupting normal flow.
The message is localized using Validator.formatMessage(ErrorMessageKey, Parameter)
,
and is logged using the Java Logger
API.
The LogLevel
enum provides a clearer abstraction over
Level
for improved readability and intent.
Typical usage:
validate(value, Predicate, Validator.logging(logLevel, ErrorMessageKey, Parameter));
- See Also:
-
Field Summary
Fields inherited from interface com.winterhavenmc.library.messagebuilder.validation.Validator
BUNDLE_NAME
-
Constructor Summary
ConstructorsConstructorDescriptionLogging
(LogLevel logLevel, ErrorMessageKey messageKey, Parameter parameter) Creates an instance of aLogging
record class. -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
Indicates whether some other object is "equal to" this one.handleInvalid
(T value) Logs a validation failure using the specified log level and message, but continues execution by returning the original value.final int
hashCode()
Returns a hash code value for this object.logLevel()
Returns the value of thelogLevel
record component.Returns the value of themessageKey
record component.Returns the value of theparameter
record component.final String
toString()
Returns a string representation of this record class.
-
Constructor Details
-
Logging
Creates an instance of aLogging
record class.- Parameters:
logLevel
- the value for thelogLevel
record componentmessageKey
- the value for themessageKey
record componentparameter
- the value for theparameter
record component
-
-
Method Details
-
handleInvalid
Logs a validation failure using the specified log level and message, but continues execution by returning the original value.- Specified by:
handleInvalid
in interfaceValidator<T>
- Parameters:
value
- the invalid value- Returns:
- an
Optional
containing the value, despite being invalid
-
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)
. -
logLevel
Returns the value of thelogLevel
record component.- Returns:
- the value of the
logLevel
record component
-
messageKey
Returns the value of themessageKey
record component.- Returns:
- the value of the
messageKey
record component
-
parameter
Returns the value of theparameter
record component.- Returns:
- the value of the
parameter
record component
-