Class Validations

java.lang.Object
de.zabuza.fastcdc4j.internal.util.Validations

public final class Validations
extends java.lang.Object
Utility class providing validation methods.
Author:
Daniel Tischner <zabuza.dev@gmail.com>
  • Method Summary

    Modifier and Type Method Description
    static void require​(boolean predicate, java.lang.String message)
    Throws IllegalArgumentException if the given predicate resolves to false.
    static <E extends java.lang.RuntimeException>
    void
    require​(boolean predicate, java.util.function.Function<? super java.lang.String,​E> exceptionSupplier, java.lang.String message)
    Throws the given exception if the predicate resolves to false.
    static <T> T require​(java.util.function.Predicate<? super T> predicate, T object, java.lang.String message)
    Throws IllegalArgumentException if the given predicate resolves to true.
    static <T,​ E extends java.lang.RuntimeException>
    T
    require​(java.util.function.Predicate<? super T> predicate, T object, java.util.function.Function<? super java.lang.String,​E> exceptionSupplier, java.lang.String message)
    Throws the given exception if the predicate resolves to false.
    static <E extends java.lang.RuntimeException>
    void
    requireNotThrow​(java.lang.Class<E> expectedException, java.lang.Runnable runnable, java.lang.String message)
    Throws IllegalArgumentException if the runnable throws the given expected exception.
    static int requirePositive​(int value, java.lang.String valueName)
    Throws IllegalArgumentException if the given value is not positive, i.e. when it is negative.
    static long requirePositive​(long value, java.lang.String valueName)
    Throws IllegalArgumentException if the given value is not positive, i.e. when it is negative.
    static int requirePositiveNonZero​(int value, java.lang.String valueName)
    Throws IllegalArgumentException if the given value is not positive or zero, i.e. when it is negative or zero.
    static long requirePositiveNonZero​(long value, java.lang.String valueName)
    Throws IllegalArgumentException if the given value is not positive or zero, i.e. when it is negative or zero.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • requirePositive

      public static long requirePositive​(long value, java.lang.String valueName)
      Throws IllegalArgumentException if the given value is not positive, i.e. when it is negative.
      Parameters:
      value - The value to test
      valueName - The name of the value, used to describe it in the exception reason, not null
      Returns:
      The given value for convenient chaining
    • requirePositiveNonZero

      public static long requirePositiveNonZero​(long value, java.lang.String valueName)
      Throws IllegalArgumentException if the given value is not positive or zero, i.e. when it is negative or zero.
      Parameters:
      value - The value to test
      valueName - The name of the value, used to describe it in the exception reason, not null
      Returns:
      The given value for convenient chaining
    • requirePositive

      public static int requirePositive​(int value, java.lang.String valueName)
      Throws IllegalArgumentException if the given value is not positive, i.e. when it is negative.
      Parameters:
      value - The value to test
      valueName - The name of the value, used to describe it in the exception reason, not null
      Returns:
      The given value for convenient chaining
    • requirePositiveNonZero

      public static int requirePositiveNonZero​(int value, java.lang.String valueName)
      Throws IllegalArgumentException if the given value is not positive or zero, i.e. when it is negative or zero.
      Parameters:
      value - The value to test
      valueName - The name of the value, used to describe it in the exception reason, not null
      Returns:
      The given value for convenient chaining
    • requireNotThrow

      public static <E extends java.lang.RuntimeException> void requireNotThrow​(java.lang.Class<E> expectedException, java.lang.Runnable runnable, java.lang.String message)
      Throws IllegalArgumentException if the runnable throws the given expected exception.
      Type Parameters:
      E - The type of the exception to expect
      Parameters:
      expectedException - The exception for which to throw if it happens, not null
      runnable - The runnable to execute, not null
      message - The message to provide in the exception as reason, not null
    • require

      public static <T> T require​(java.util.function.Predicate<? super T> predicate, T object, java.lang.String message)
      Throws IllegalArgumentException if the given predicate resolves to true.
      Type Parameters:
      T - The type of the object to test
      Parameters:
      predicate - The predicate to test, not null
      object - The object to test the predicate against
      message - The message to provide in the exception, not null
      Returns:
      The given value for convenient chaining
    • require

      public static void require​(boolean predicate, java.lang.String message)
      Throws IllegalArgumentException if the given predicate resolves to false.
      Parameters:
      predicate - The predicate to test
      message - The message to provide in the exception, not null
    • require

      public static <T,​ E extends java.lang.RuntimeException> T require​(java.util.function.Predicate<? super T> predicate, T object, java.util.function.Function<? super java.lang.String,​E> exceptionSupplier, java.lang.String message)
      Throws the given exception if the predicate resolves to false.
      Type Parameters:
      T - The type of the object to test
      E - The type of the exception to throw
      Parameters:
      predicate - The predicate to test, not null
      object - The object to test the predicate against
      exceptionSupplier - The supplier to use for getting the exception to throw, not null
      message - The message to provide in the exception, not null
      Returns:
      The given value for convenient chaining
    • require

      public static <E extends java.lang.RuntimeException> void require​(boolean predicate, java.util.function.Function<? super java.lang.String,​E> exceptionSupplier, java.lang.String message)
      Throws the given exception if the predicate resolves to false.
      Type Parameters:
      E - The type of the exception to throw
      Parameters:
      predicate - The predicate to test
      exceptionSupplier - The supplier to use for getting the exception to throw, not null
      message - The message to provide in the exception, not null