Class AssertionUtil

java.lang.Object
net.sourceforge.pmd.util.AssertionUtil

public final class AssertionUtil extends Object
  • Method Details

    • isAssertEnabled

      public static boolean isAssertEnabled()
      Return true if the VM runs with assertions enabled.
    • requireContainsNoNullValue

      public static void requireContainsNoNullValue(String name, Collection<?> c)
      Throws:
      NullPointerException - if any item is null
    • requireNotEmpty

      public static void requireNotEmpty(String name, Collection<?> c)
      Throws:
      IllegalArgumentException - if empty
    • isValidJavaPackageName

      public static boolean isValidJavaPackageName(CharSequence name)
    • assertValidJavaBinaryName

      public static void assertValidJavaBinaryName(CharSequence name)
      Throws:
      IllegalArgumentException - if the name is not a binary name
    • assertValidJavaBinaryNameNoArray

      public static void assertValidJavaBinaryNameNoArray(CharSequence name)
      Throws:
      IllegalArgumentException - if the name is not a binary name
    • validateState

      public static void validateState(boolean condition, String failed)
      Throws IllegalStateException if the condition is false.
    • validateStringRange

      public static void validateStringRange(CharSequence string, int startInclusive, int endExclusive)
      Throws:
      IllegalArgumentException - if [startInclusive,endExclusive[ is not a valid substring range for the given string
    • assertValidStringRange

      public static void assertValidStringRange(CharSequence string, int startInclusive, int endExclusive)
      Like validateStringRange(CharSequence, int, int) but eliminated at runtime if running without assertions.
    • isJavaIdentifier

      public static boolean isJavaIdentifier(CharSequence name)
      Returns true if the charsequence is a valid java identifier.
      Parameters:
      name - Name (non-null)
      Throws:
      NullPointerException - If the name is null
    • requireOver1

      public static int requireOver1(String name, int value)
    • requireNonNegative

      public static int requireNonNegative(String name, int value)
      Throws:
      IllegalArgumentException - If value < 0
    • requireIndexNonNegative

      public static int requireIndexNonNegative(String name, int value)
      Throws:
      IndexOutOfBoundsException - If value < 0
    • requireInNonNegativeRange

      public static int requireInNonNegativeRange(String name, int value, int maxValue)
      Throws:
      IndexOutOfBoundsException - If value < 0 || value >= maxValue
    • requireInPositiveRange

      public static int requireInPositiveRange(String name, int value, int maxValue)
      Throws:
      IndexOutOfBoundsException - If value < 1 || value >= maxValue
    • requireInInclusiveRange

      public static int requireInInclusiveRange(String name, int value, int minValue, int maxValue)
      Throws:
      IndexOutOfBoundsException - If value < minValue || value > maxValue
    • requireInExclusiveRange

      public static int requireInExclusiveRange(String name, int value, int minValue, int maxValue)
      Throws:
      IndexOutOfBoundsException - If value < minValue || value > maxValue
    • requireInRange

      public static int requireInRange(String name, int value, int minValue, int maxValue, boolean inclusive)
    • mustBe

      public static RuntimeException mustBe(String name, Object value, String condition)
    • mustBe

      public static <E extends RuntimeException> E mustBe(String name, Object value, String condition, Function<String,E> exceptionMaker)
    • requireParamNotNull

      public static <T> @NonNull T requireParamNotNull(String paramName, T obj)
    • shouldNotReachHere

      public static @NonNull AssertionError shouldNotReachHere(String message)
    • shouldNotReachHere

      public static @NonNull AssertionError shouldNotReachHere(String message, Throwable cause)
    • contexted

      public static @NonNull ContextedAssertionError contexted(AssertionError e)
    • contexted

      public static @NonNull ContextedStackOverflowError contexted(StackOverflowError e)
    • contexted

      public static @NonNull org.apache.commons.lang3.exception.ContextedRuntimeException contexted(RuntimeException e)