Class ParameterValidationUtility

java.lang.Object
de.bcxp.challenge.common.utility.ParameterValidationUtility

public final class ParameterValidationUtility extends Object

Utility class providing methods to check method parameters for validity. Used instead of Objects.requireNonNull() for logging purposes, and to throw more fitting exceptions than NullPointerException.

  • Field Details

  • Constructor Details

    • ParameterValidationUtility

      private ParameterValidationUtility()
      This is a utility class which provides only static methods, therefore it shouldn't be instantiated.
  • Method Details

    • validateString

      public static void validateString(String string, org.apache.logging.log4j.Logger logger, String logMessage, String exceptionMessage) throws IllegalArgumentException
      Validates that the provided string is non-null and not empty or blank.
      Parameters:
      string - the string to validate
      logger - the logger to use for warnings
      logMessage - the message to log if validation fails
      exceptionMessage - the message to include in the thrown exception.
      Throws:
      IllegalArgumentException - if the string is null or empty
    • nullCheck

      public static void nullCheck(Object o, org.apache.logging.log4j.Logger logger, String logMessage, String exceptionMessage)
      Validates that the provided object reference is not null.

      If the object is null, this method logs a warning message using the provided Logger and then throws an IllegalArgumentException with the specified exception message.

      Parameters:
      o - the object reference to validate
      logger - the logger to use for warnings
      logMessage - the message to log if validation fails
      exceptionMessage - the message to include in the thrown exception.
      Throws:
      IllegalArgumentException - if o is null
    • validateDocument

      public static void validateDocument(Document document, org.apache.logging.log4j.Logger logger, String logMessage, String exceptionMessage) throws IllegalArgumentException
      Validates that the provided document and it's entries are non-null.
      Parameters:
      document - The Document to validate
      logger - the logger to use for warnings
      logMessage - the message to log if validation fails
      exceptionMessage - the message to include in the thrown exception
      Throws:
      IllegalArgumentException
    • validateEntries

      public static void validateEntries(Collection<? extends DocumentEntry> entries, boolean allowEmpty, org.apache.logging.log4j.Logger logger, String logMessage, String exceptionMessage) throws IllegalArgumentException, NoSuchElementException, IllegalStateException

      Validates that the provided Collection of DocumentEntry objects contents are non-null.

      Parameters:
      entries - the entries to validate
      allowEmpty - Flag to set true if the entries can be empty, false otherwise
      logger - the logger to use for warnings
      logMessage - the message to log if validation fails
      exceptionMessage - the message to include in the thrown exception
      Throws:
      IllegalArgumentException - if the list is null or empty
      NoSuchElementException
      IllegalStateException
    • validateNumericTupleDocumentEntries

      public static void validateNumericTupleDocumentEntries(List<DocumentEntry> entries, org.apache.logging.log4j.Logger logger) throws IllegalArgumentException
      Checks if the list of DocumentEntry entries from a Document all implement the IEntryWithComparableNumericTuple interface and are all of the same concrete type.
      Parameters:
      entries - DocumentEntry objects contained in a Document
      logger - Logger to log possible error messages to
      Throws:
      IllegalArgumentException
    • validateLoggerAndMessages

      private static void validateLoggerAndMessages(org.apache.logging.log4j.Logger logger, String logMessage, String exceptionMessage)
      Validates that the provided Logger and message strings are not null.

      If any of the parameters are null, the method logs a warning using the given Logger (if not null) and throws an IllegalArgumentException.

      Parameters:
      logger - the Logger instance to validate; must not be null.
      logMessage - the log message string to validate; must not be null.
      exceptionMessage - the exception message string to validate; must not be null.
      Throws:
      IllegalArgumentException - if any parameter is null.