Package org.conscrypt

Class Preconditions

java.lang.Object
org.conscrypt.Preconditions

final class Preconditions extends 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
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private static String
    badPositionIndex(int index, int size, String desc)
     
    private static String
    badPositionIndexes(int start, int end, int size)
     
    (package private) static void
    checkArgument(boolean condition, String errorMessage)
    Ensures the truth of an expression involving one or more parameters to the calling method.
    (package private) static void
    checkArgument(boolean condition, String errorMessageTemplate, 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, 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 Details

    • Preconditions

      private Preconditions()
  • Method Details

    • checkNotNull

      static <T> T checkNotNull(T reference, 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:
      NullPointerException - if reference is null
    • checkArgument

      static void checkArgument(boolean condition, 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:
      IllegalArgumentException - if the condition is false
    • checkArgument

      static void checkArgument(boolean condition, String errorMessageTemplate, 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:
      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:
      IndexOutOfBoundsException - if either index is negative or is greater than size, or if end is less than start
      IllegalArgumentException - if size is negative
    • badPositionIndexes

      private static String badPositionIndexes(int start, int end, int size)
    • badPositionIndex

      private static String badPositionIndex(int index, int size, String desc)