Package com.winterhavenmc.library.messagebuilder.validation


package com.winterhavenmc.library.messagebuilder.validation
Provides a flexible, localized validation framework for use within the MessageBuilder library.

This package defines a lightweight set of tools for validating input parameters and plugin configuration in a way that supports both exception-based and logging-based workflows. All error messages are resolved using structured keys from ErrorMessageKey, enabling localization through a ResourceBundle.

Core Concepts

  • Validator — a functional interface representing a strategy for handling invalid values (e.g., throwing or logging).
  • ValidationException — a custom runtime exception for reporting validation failures with localized messages.
  • Predicate — a funtional predicate passed as a parameter to the validate method to check against a parameter.
  • ErrorMessageKey — an enum constant that corresponds to an error message key in the ResourceBundle
  • Parameter — an enum of symbolic parameter names used to identify invalid arguments in error messages.

Usage Pattern

Throwing exception:
    validate(recipient, Objects::isNull, throwing(ErrorMessageKey.PARAMETER_NULL, Parameter.RECIPIENT));
Logging error and returning default value:
    String validName = validate(name, String::isBlank, logging(LogLevel.INFO, ErrorMessageKey.STRING_BLANK, Parameter.NAME)).orElse("Steve");

Localization

Localized messages are loaded from the exception.messages resource bundle. The locale may default to Locale.getDefault(), but is designed to be overridable via plugin configuration through a global locale context.

See Also:
  • Class
    Description
    Enumeration of structured keys used to identify localized error messages for validation and configuration-related exceptions.
    A Validator implementation that logs a warning or error when a value fails validation, but does not throw.
    Represents standard log severity levels used for validation feedback and internal diagnostics.
    Enumerates the names of parameters that may be subject to validation within the MessageBuilder library.
    A Validator implementation that throws a ValidationException when a value fails validation.
    Provides global access to the plugin-configured locale used during validation message formatting.
    Thrown to indicate that a parameter validation has failed.
    A functional interface representing a strategy for handling invalid values detected during validation.