Package net.sourceforge.pmd.util
Class AssertionUtil
java.lang.Object
net.sourceforge.pmd.util.AssertionUtil
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidstatic voidstatic voidassertValidStringRange(CharSequence string, int startInclusive, int endExclusive) LikevalidateStringRange(CharSequence, int, int)but eliminated at runtime if running without assertions.static @NonNull ContextedAssertionErrorstatic @NonNull org.apache.commons.lang3.exception.ContextedRuntimeExceptionstatic @NonNull ContextedStackOverflowErrorstatic booleanReturn true if the VM runs with assertions enabled.static booleanisJavaIdentifier(CharSequence name) Returns true if the charsequence is a valid java identifier.static booleanstatic RuntimeExceptionstatic <E extends RuntimeException>
Estatic voidrequireContainsNoNullValue(String name, Collection<?> c) static intrequireIndexNonNegative(String name, int value) static intrequireInExclusiveRange(String name, int value, int minValue, int maxValue) static intrequireInInclusiveRange(String name, int value, int minValue, int maxValue) static intrequireInNonNegativeRange(String name, int value, int maxValue) static intrequireInPositiveRange(String name, int value, int maxValue) static intrequireInRange(String name, int value, int minValue, int maxValue, boolean inclusive) static intrequireNonNegative(String name, int value) static voidrequireNotEmpty(String name, Collection<?> c) static intrequireOver1(String name, int value) static <T> @NonNull TrequireParamNotNull(String paramName, T obj) static @NonNull AssertionErrorshouldNotReachHere(String message) static @NonNull AssertionErrorshouldNotReachHere(String message, Throwable cause) static voidvalidateState(boolean condition, String failed) ThrowsIllegalStateExceptionif the condition is false.static voidvalidateStringRange(CharSequence string, int startInclusive, int endExclusive)
-
Method Details
-
isAssertEnabled
public static boolean isAssertEnabled()Return true if the VM runs with assertions enabled. -
requireContainsNoNullValue
- Throws:
NullPointerException- if any item is null
-
requireNotEmpty
- Throws:
IllegalArgumentException- if empty
-
isValidJavaPackageName
-
assertValidJavaBinaryName
- Throws:
IllegalArgumentException- if the name is not a binary name
-
assertValidJavaBinaryNameNoArray
- Throws:
IllegalArgumentException- if the name is not a binary name
-
validateState
ThrowsIllegalStateExceptionif the condition is false. -
validateStringRange
- 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) LikevalidateStringRange(CharSequence, int, int)but eliminated at runtime if running without assertions. -
isJavaIdentifier
Returns true if the charsequence is a valid java identifier.- Parameters:
name- Name (non-null)- Throws:
NullPointerException- If the name is null
-
requireOver1
-
requireNonNegative
- Throws:
IllegalArgumentException- Ifvalue < 0
-
requireIndexNonNegative
- Throws:
IndexOutOfBoundsException- Ifvalue < 0
-
requireInNonNegativeRange
- Throws:
IndexOutOfBoundsException- Ifvalue < 0 || value >= maxValue
-
requireInPositiveRange
- Throws:
IndexOutOfBoundsException- Ifvalue < 1 || value >= maxValue
-
requireInInclusiveRange
- Throws:
IndexOutOfBoundsException- Ifvalue < minValue || value > maxValue
-
requireInExclusiveRange
- Throws:
IndexOutOfBoundsException- Ifvalue < minValue || value > maxValue
-
requireInRange
public static int requireInRange(String name, int value, int minValue, int maxValue, boolean inclusive) -
mustBe
-
mustBe
-
requireParamNotNull
-
shouldNotReachHere
-
shouldNotReachHere
-
contexted
-
contexted
-
contexted
public static @NonNull org.apache.commons.lang3.exception.ContextedRuntimeException contexted(RuntimeException e)
-