Class Validators

java.lang.Object
io.github.mfvanek.pg.model.validation.Validators

public final class Validators extends Object
Utility class providing various validation methods. This class cannot be instantiated.
  • Method Details

    • valueIsPositive

      public static long valueIsPositive(long argumentValue, @Nonnull String argumentName)
      Ensures the given value is positive.
      Parameters:
      argumentValue - the value to check
      argumentName - the name of the argument being checked
      Returns:
      the provided value if it is positive
      Throws:
      IllegalArgumentException - if the value is not positive
    • tableNameNotBlank

      @Nonnull public static String tableNameNotBlank(@Nonnull String tableName)
      Ensures the provided table name is not blank.
      Parameters:
      tableName - the table name to check
      Returns:
      the provided table name if it is not blank
      Throws:
      IllegalArgumentException - if the table name is blank
    • indexNameNotBlank

      @Nonnull public static String indexNameNotBlank(@Nonnull String indexName)
      Ensures the provided index name is not blank.
      Parameters:
      indexName - the index name to check
      Returns:
      the provided index name if it is not blank
      Throws:
      IllegalArgumentException - if the index name is blank
    • notBlank

      @Nonnull public static String notBlank(@Nonnull String argumentValue, @Nonnull String argumentName)
      Ensures the provided string argument is not blank.
      Parameters:
      argumentValue - the string argument to check
      argumentName - the name of the argument being checked
      Returns:
      the provided string argument if it is not blank
      Throws:
      IllegalArgumentException - if the argument is blank
    • sizeNotNegative

      public static long sizeNotNegative(long sizeInBytes, @Nonnull String argumentName)
      Ensures the given size is not negative.
      Parameters:
      sizeInBytes - the size to check
      argumentName - the name of the argument being checked
      Returns:
      the provided size if it is not negative
      Throws:
      IllegalArgumentException - if the size is negative
    • countNotNegative

      public static long countNotNegative(long count, @Nonnull String argumentName)
      Ensures the given count is not negative.
      Parameters:
      count - the count to check
      argumentName - the name of the argument being checked
      Returns:
      the provided count if it is not negative
      Throws:
      IllegalArgumentException - if the count is negative
    • argumentNotNegative

      public static int argumentNotNegative(int argumentValue, @Nonnull String argumentName)
      Ensures the given integer value is not negative.
      Parameters:
      argumentValue - the value to check
      argumentName - the name of the argument being checked
      Returns:
      the provided value if it is not negative
      Throws:
      IllegalArgumentException - if the value is negative
    • validateThatTableIsTheSame

      public static void validateThatTableIsTheSame(@Nonnull String expectedTableName, @Nonnull List<? extends TableNameAware> rows)
      Validates that all rows have the same table name as the expected table name.
      Parameters:
      expectedTableName - the expected table name
      rows - the rows to check
      Throws:
      IllegalArgumentException - if any row has a different table name
    • validateThatTableIsTheSame

      public static <T extends TableNameAware & DbObject> void validateThatTableIsTheSame(@Nonnull List<T> rows)
      Validates that all rows have the same table name.
      Type Parameters:
      T - the type of the list elements
      Parameters:
      rows - the rows to check
    • validateThatNotEmpty

      public static <T> void validateThatNotEmpty(@Nonnull List<T> columnsInConstraint)
      Ensures the provided list is not empty.
      Type Parameters:
      T - the type of the list elements
      Parameters:
      columnsInConstraint - the list to check
      Throws:
      IllegalArgumentException - if the list is empty
    • validPercent

      public static double validPercent(double percentValue, @Nonnull String argumentName)
      Ensures the given percent value is between 0.0 and 100.0 inclusive.
      Parameters:
      percentValue - the percent value to check
      argumentName - the name of the argument being checked
      Returns:
      the provided percent value if it is valid
      Throws:
      IllegalArgumentException - if the percent value is outside the valid range