Class Preconditions


  • public class Preconditions
    extends java.lang.Object
    Simple methods similar to Precondition class. Avoid importing full library.
    • Constructor Summary

      Constructors 
      Constructor Description
      Preconditions()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void checkArgument​(boolean check, java.lang.String valueName)
      Checks that the argument is valid, based in a check boolean condition.
      static java.lang.String checkNotEmpty​(java.lang.String value, java.lang.String valueName)
      Checks that the String is not null and not empty
      static <T> T checkNotNull​(T value, java.lang.String valueName)
      Checks that the argument is not null.
      static int gt0​(int value, java.lang.String valueName)
      Checks that the integer argument is positive.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Preconditions

        public Preconditions()
    • Method Detail

      • checkNotNull

        public static <T> T checkNotNull​(T value,
                                         java.lang.String valueName)
                                  throws java.lang.IllegalArgumentException
        Checks that the argument is not null.
        Type Parameters:
        T - The type of the value
        Parameters:
        value - The value to be checked
        valueName - The name of the value that is checked in the method
        Returns:
        The same value passed as argument
        Throws:
        java.lang.IllegalArgumentException - If value is null
      • checkNotEmpty

        public static java.lang.String checkNotEmpty​(java.lang.String value,
                                                     java.lang.String valueName)
                                              throws java.lang.IllegalArgumentException
        Checks that the String is not null and not empty
        Parameters:
        value - The String to check
        valueName - The name of the value that is checked in the method
        Returns:
        The same String passed as argument
        Throws:
        java.lang.IllegalArgumentException - If value is null or empty
      • checkArgument

        public static void checkArgument​(boolean check,
                                         java.lang.String valueName)
                                  throws java.lang.IllegalArgumentException
        Checks that the argument is valid, based in a check boolean condition.
        Parameters:
        check - The boolean check
        valueName - The name of the value that is checked in the method
        Throws:
        java.lang.IllegalArgumentException
      • gt0

        public static int gt0​(int value,
                              java.lang.String valueName)
                       throws java.lang.IllegalArgumentException
        Checks that the integer argument is positive.
        Parameters:
        value - The value to be checked
        valueName - The name of the value that is checked in the method
        Returns:
        The same value passed as argument
        Throws:
        java.lang.IllegalArgumentException - If value is null