Package org.conscrypt

Class Preconditions


  • final class Preconditions
    extends java.lang.Object
    Static convenience methods that help a method or constructor check whether it was invoked correctly (that is, whether its preconditions were met).
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Preconditions()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.lang.String badPositionIndex​(int index, int size, java.lang.String desc)  
      private static java.lang.String badPositionIndexes​(int start, int end, int size)  
      (package private) static void checkArgument​(boolean condition, java.lang.String errorMessage)
      Ensures the truth of an expression involving one or more parameters to the calling method.
      (package private) static void checkArgument​(boolean condition, java.lang.String errorMessageTemplate, java.lang.Object arg)
      Ensures the truth of an expression involving one or more parameters to the calling method.
      (package private) static <T> T checkNotNull​(T reference, java.lang.String errorMessage)
      Ensures that an object reference passed as a parameter to the calling method is not null.
      (package private) static void checkPositionIndexes​(int start, int end, int size)
      Ensures that start and end specify a valid positions in an array, list or string of size size, and are in order.
      • Methods inherited from class java.lang.Object

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

      • Preconditions

        private Preconditions()
    • Method Detail

      • checkNotNull

        static <T> T checkNotNull​(T reference,
                                  java.lang.String errorMessage)
        Ensures that an object reference passed as a parameter to the calling method is not null.
        Parameters:
        reference - an object reference
        errorMessage - the exception message to use if the check fails.
        Returns:
        the non-null reference that was validated
        Throws:
        java.lang.NullPointerException - if reference is null
      • checkArgument

        static void checkArgument​(boolean condition,
                                  java.lang.String errorMessage)
        Ensures the truth of an expression involving one or more parameters to the calling method.
        Parameters:
        condition - to condition to be tested
        errorMessage - the exception message to use if the check fails.
        Throws:
        java.lang.IllegalArgumentException - if the condition is false
      • checkArgument

        static void checkArgument​(boolean condition,
                                  java.lang.String errorMessageTemplate,
                                  java.lang.Object arg)
        Ensures the truth of an expression involving one or more parameters to the calling method.
        Parameters:
        condition - to condition to be tested
        errorMessageTemplate - the format string to be passed to String.format(String, Object...)
        arg - the format argument to be passed to String.format(String, Object...)
        Throws:
        java.lang.IllegalArgumentException - if the condition is false
      • checkPositionIndexes

        static void checkPositionIndexes​(int start,
                                         int end,
                                         int size)
        Ensures that start and end specify a valid positions in an array, list or string of size size, and are in order. A position index may range from zero to size, inclusive.
        Parameters:
        start - a user-supplied index identifying a starting position in an array, list or string
        end - a user-supplied index identifying a ending position in an array, list or string
        size - the size of that array, list or string
        Throws:
        java.lang.IndexOutOfBoundsException - if either index is negative or is greater than size, or if end is less than start
        java.lang.IllegalArgumentException - if size is negative
      • badPositionIndexes

        private static java.lang.String badPositionIndexes​(int start,
                                                           int end,
                                                           int size)
      • badPositionIndex

        private static java.lang.String badPositionIndex​(int index,
                                                         int size,
                                                         java.lang.String desc)