Class Validation

java.lang.Object
net.thauvin.erik.frankfurter.internal.Validation

public final class Validation extends Object
Internal validation helpers used throughout the Frankfurter client.

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 Details

    • formatNullMessage

      public static String formatNullMessage(@NonNull String name)
      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 - if name is null
    • requireAllNonNull

      public static void requireAllNonNull(@NonNull String name, @NonNull String... values)
      Ensures that the given varargs array and all of its elements are non‑null.
      Parameters:
      name - a descriptive name for the parameter being validated
      values - the array to validate
      Throws:
      NullPointerException - if the array or any element is null
    • requireAllNonNull

      public static <T> void requireAllNonNull(@NonNull String name, @NonNull Collection<T> values)
      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 is null, a NullPointerException is 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 validated
      values - the collection to validate
      Throws:
      NullPointerException - if the collection or any element is null
    • requireIsoCurrency

      public static String requireIsoCurrency(@NonNull String name, @NonNull String code)
      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 validated
      code - the currency code to validate
      Returns:
      the validated currency code in uppercase
      Throws:
      IllegalArgumentException - if the code is blank, or not three letters
      NullPointerException - if the code is null
    • 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 validated
      values - the currency codes to validate
      Returns:
      a new array with validated, normalized currency codes
      Throws:
      NullPointerException - if array or any element is null
      IllegalArgumentException - 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 validated
      values - 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 is null
    • requireNonNullOrBlank

      public static String requireNonNullOrBlank(String name, String value)
      Checks that the specified string is neither null nor blank.
      Parameters:
      name - a descriptive name for the parameter being validated
      value - the string value to validate
      Returns:
      value if it is not null and not blank
      Throws:
      NullPointerException - if value is null
      IllegalArgumentException - if value is blank
    • requireSupportedDate

      public static LocalDate requireSupportedDate(@NonNull String name, @NonNull LocalDate date)
      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 validated
      date - the date to validate
      Returns:
      the validated date
      Throws:
      IllegalArgumentException - if the date is earlier than the minimum supported date