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:
  • Constructor Details

    • Logging

      public Logging(LogLevel logLevel, ErrorMessageKey messageKey, Parameter parameter)
      Creates an instance of a Logging record class.
      Parameters:
      logLevel - the value for the logLevel record component
      messageKey - the value for the messageKey record component
      parameter - the value for the parameter record component
  • Method Details

    • handleInvalid

      public Optional<T> handleInvalid(T value)
      Logs a validation failure using the specified log level and message, but continues execution by returning the original value.
      Specified by:
      handleInvalid in interface Validator<T>
      Parameters:
      value - the invalid value
      Returns:
      an Optional containing the value, despite being invalid
    • toString

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • logLevel

      public LogLevel logLevel()
      Returns the value of the logLevel record component.
      Returns:
      the value of the logLevel record component
    • messageKey

      public ErrorMessageKey messageKey()
      Returns the value of the messageKey record component.
      Returns:
      the value of the messageKey record component
    • parameter

      public Parameter parameter()
      Returns the value of the parameter record component.
      Returns:
      the value of the parameter record component