Class Preconditions

java.lang.Object
dev.zemco.codegame.util.Preconditions

public final class Preconditions extends Object
Collection of utility functions for checking validity of arguments.
Author:
Erik Zemčík
  • Method Details

    • checkArgumentNotNull

      public static <T> T checkArgumentNotNull(T argument, String argumentName)
      Throws formatted IllegalArgumentException if argument is null.
      Type Parameters:
      T - argument type
      Parameters:
      argument - argument to check
      argumentName - name of the checked argument
      Returns:
      non-null instance passed to argument
      Throws:
      IllegalArgumentException - if argument is null
    • checkArgumentNotEmpty

      public static String checkArgumentNotEmpty(String argument, String argumentName)
      Throws formatted IllegalArgumentException if String argument is null or has no characters.
      Parameters:
      argument - argument to check
      argumentName - name of the checked argument
      Returns:
      instance passed to argument
      Throws:
      IllegalArgumentException - if argument is null or empty
    • checkArgumentNotEmpty

      public static <T extends Collection<?>> T checkArgumentNotEmpty(T argument, String argumentName)
      Throws formatted IllegalArgumentException if Collection argument is null or contains no elements.
      Type Parameters:
      T - collection argument type
      Parameters:
      argument - argument to check
      argumentName - name of the checked argument
      Returns:
      instance passed to argument
      Throws:
      IllegalArgumentException - if argument is null or empty
    • checkArgumentPositiveInteger

      public static int checkArgumentPositiveInteger(int argument, String argumentName)
      Throws formatted IllegalArgumentException if argument is less than 0.
      Parameters:
      argument - argument to check
      argumentName - name of the checked argument
      Returns:
      int passed to argument
      Throws:
      IllegalArgumentException - if argument is less than 0