Class Validation
This class centralizes common input checks such as ISO 4217 currency validation, date range validation, and minimum supported date enforcement. It is intended for internal use by configuration builders and endpoint methods, and is not part of the public API surface.
- Since:
- 1.0
- Author:
- Erik C. Thauvin
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringformatNullMessage(String name) Formats a standard "must not be null" message for the given parameter name.static voidrequireAllNonNull(String name, String... values) Ensures that the given varargs array and all of its elements are non‑null.static <T> voidrequireAllNonNull(String name, Collection<T> values) Ensures that the given collection and all of its elements are non‑null.static StringrequireIsoCurrency(String name, String code) Validates that the given value is a non-blank ISO 4217 alphabetic currency code.static String[]requireIsoCurrencyArray(String name, String[] values) Validates an array of ISO currency codes, uppercases, and removes duplicates.static String[]requireNonBlankDistinct(String name, String[] values) Validates an array of strings, filters out blanks, trims, and removes duplicates.static StringrequireNonNullOrBlank(String name, String value) Checks that the specified string is neithernullnor blank.static LocalDaterequireSupportedDate(String name, LocalDate date) Validates that the given date is not earlier than the earliest supported Frankfurter reference date.
-
Method Details
-
formatNullMessage
Formats a standard "must not be null" message for the given parameter name.Used by validation methods to ensure consistent exception messages.
- Parameters:
name- the parameter name- Returns:
name + " must not be null"- Throws:
NullPointerException- ifnameisnull
-
requireAllNonNull
Ensures that the given varargs array and all of its elements are non‑null.- Parameters:
name- a descriptive name for the parameter being validatedvalues- the array to validate- Throws:
NullPointerException- if the array or any element isnull
-
requireAllNonNull
Ensures that the given collection and all of its elements are non‑null.This method validates both the collection reference and each individual element. If the collection itself is
null, or if any element within it isnull, aNullPointerExceptionis thrown. The exception message includes the supplied field name to make validation errors easier to diagnose.- Type Parameters:
T- the element type- Parameters:
name- a descriptive name for the parameter being validatedvalues- the collection to validate- Throws:
NullPointerException- if the collection or any element isnull
-
requireIsoCurrency
Validates that the given value is a non-blank ISO 4217 alphabetic currency code.The code must consist of exactly three letters. Whitespace is not trimmed. This method performs only structural validation; it does not verify that the code corresponds to a known currency.
- Parameters:
name- a descriptive name for the parameter being validatedcode- the currency code to validate- Returns:
- the validated currency code in uppercase
- Throws:
IllegalArgumentException- if thecodeis blank, or not three lettersNullPointerException- if thecodeisnull
-
requireIsoCurrencyArray
@NonNull public static String[] requireIsoCurrencyArray(@NonNull String name, @NonNull String[] values) Validates an array of ISO currency codes, uppercases, and removes duplicates.Each element must be non-null and a valid 3-letter ISO 4217 code. Blank strings, whitespace-only strings, and strings with leading/trailing whitespace are rejected. Whitespace is not trimmed.
- Parameters:
name- a descriptive name for the parameter being validatedvalues- the currency codes to validate- Returns:
- a new array with validated, normalized currency codes
- Throws:
NullPointerException- if array or any element isnullIllegalArgumentException- if any element is blank or not 3 letters
-
requireNonBlankDistinct
@NonNull public static String[] requireNonBlankDistinct(@NonNull String name, @NonNull String[] values) Validates an array of strings, filters out blanks, trims, and removes duplicates.- Parameters:
name- a descriptive name for the parameter being validatedvalues- the array to validate and clean- Returns:
- a new array with blanks removed, values trimmed, and duplicates removed
- Throws:
NullPointerException- if array or any element isnull
-
requireNonNullOrBlank
Checks that the specified string is neithernullnor blank.- Parameters:
name- a descriptive name for the parameter being validatedvalue- the string value to validate- Returns:
valueif it is notnulland not blank- Throws:
NullPointerException- ifvalueisnullIllegalArgumentException- ifvalueis blank
-
requireSupportedDate
Validates that the given date is not earlier than the earliest supported Frankfurter reference date.This method enforces the minimum supported date of
MIN_SUPPORTED_DATE. It does not validate future dates, which are permitted by the API.- Parameters:
name- a descriptive name for the parameter being validateddate- the date to validate- Returns:
- the validated date
- Throws:
IllegalArgumentException- if the date is earlier than the minimum supported date
-