Package com.winterhavenmc.library.messagebuilder.models.validation
package com.winterhavenmc.library.messagebuilder.models.validation
Provides a flexible, localized validation framework for use within the MessageBuilder library.
Logging error and returning default value:
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 thevalidatemethod to check against a parameter.ErrorMessageKey— an enum constant that corresponds to an error message string in theResourceBundleParameter— an enum of symbolic parameter names used to identify invalid arguments in error messages.
Usage Pattern
Throwing exception: import com.winterhavenmc.library.messagebuilder.models.validation.ErrorMessageKey;import com.winterhavenmc.library.messagebuilder.models.validation.Parameter;validate(recipient, Objects::isNull, throwing(ErrorMessageKey.PARAMETER_NULL, Parameter.RECIPIENT));
import com.winterhavenmc.library.messagebuilder.models.validation.ErrorMessageKey;import com.winterhavenmc.library.messagebuilder.models.validation.LogLevel;import com.winterhavenmc.library.messagebuilder.models.validation.Parameter;Section validName = validate(name, Section::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:
-
ClassDescriptionEnumeration of structured keys used to identify localized error messages for validation and configuration-related exceptions.Logging<T>A
Validatorimplementation 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.Throwing<T>AValidatorimplementation that throws aValidationExceptionwhen 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.Validator<T>A functional interface representing a strategy for handling invalid values detected during validation.