Package net.sourceforge.pmd.util
Class AssertionUtil
- java.lang.Object
-
- net.sourceforge.pmd.util.AssertionUtil
-
public final class AssertionUtil extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
assertValidJavaBinaryName(CharSequence name)
static void
assertValidJavaBinaryNameNoArray(CharSequence name)
static void
assertValidStringRange(CharSequence string, int startInclusive, int endExclusive)
LikevalidateStringRange(CharSequence, int, int)
but eliminated at runtime if running without assertions.static @NonNull ContextedAssertionError
contexted(AssertionError e)
static @NonNull org.apache.commons.lang3.exception.ContextedRuntimeException
contexted(RuntimeException e)
static @NonNull ContextedStackOverflowError
contexted(StackOverflowError e)
static boolean
isJavaIdentifier(CharSequence name)
Returns true if the charsequence is a valid java identifier.static boolean
isValidJavaPackageName(CharSequence name)
static RuntimeException
mustBe(String name, Object value, String condition)
static <E extends RuntimeException>
EmustBe(String name, Object value, String condition, Function<String,E> exceptionMaker)
static void
requireContainsNoNullValue(String name, Collection<?> c)
static int
requireIndexNonNegative(String name, int value)
static int
requireInExclusiveRange(String name, int value, int minValue, int maxValue)
static int
requireInInclusiveRange(String name, int value, int minValue, int maxValue)
static int
requireInNonNegativeRange(String name, int value, int maxValue)
static int
requireInPositiveRange(String name, int value, int maxValue)
static int
requireInRange(String name, int value, int minValue, int maxValue, boolean inclusive)
static int
requireNonNegative(String name, int value)
static void
requireNotEmpty(String name, Collection<?> c)
static int
requireOver1(String name, int value)
static <T> @NonNull T
requireParamNotNull(String paramName, T obj)
static @NonNull AssertionError
shouldNotReachHere(String message)
static @NonNull AssertionError
shouldNotReachHere(String message, Throwable cause)
static void
validateState(boolean condition, String failed)
ThrowsIllegalStateException
if the condition is false.static void
validateStringRange(CharSequence string, int startInclusive, int endExclusive)
-
-
-
Method Detail
-
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)
ThrowsIllegalStateException
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)
LikevalidateStringRange(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
- Ifvalue < 0
-
requireIndexNonNegative
public static int requireIndexNonNegative(String name, int value)
- Throws:
IndexOutOfBoundsException
- Ifvalue < 0
-
requireInNonNegativeRange
public static int requireInNonNegativeRange(String name, int value, int maxValue)
- Throws:
IndexOutOfBoundsException
- Ifvalue < 0 || value >= maxValue
-
requireInPositiveRange
public static int requireInPositiveRange(String name, int value, int maxValue)
- Throws:
IndexOutOfBoundsException
- Ifvalue < 1 || value >= maxValue
-
requireInInclusiveRange
public static int requireInInclusiveRange(String name, int value, int minValue, int maxValue)
- Throws:
IndexOutOfBoundsException
- Ifvalue < minValue || value > maxValue
-
requireInExclusiveRange
public static int requireInExclusiveRange(String name, int value, int minValue, int maxValue)
- Throws:
IndexOutOfBoundsException
- Ifvalue < 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)
-
-