Package org.atlanmod.commons
Class Preconditions
- java.lang.Object
-
- org.atlanmod.commons.Preconditions
-
@ParametersAreNonnullByDefault public final class Preconditions extends Object
Static convenience methods that help a method or constructor check whether it was invoked correctly (whether its preconditions have been met). These methods generally accept abooleanexpression which is expected to betrue(or in the case ofcheckNotNull, an object reference which is expected to be non-null). Whenfalse(ornull) is passed instead, thePreconditionsmethod throws an unchecked exception, which helps the calling method communicate to its caller that that caller has made a mistake. Warning: The goal of this class is to improve readability of code, but in some circumstances this may come at a significant performance cost. Remember that parameter values for message construction must all be computed eagerly, and autoboxing and varargs array creation may happen as well, even when the precondition check then succeeds (as it should almost always do in production). In some circumstances these wasted CPU cycles and allocations can add up to a real problem.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPreconditions.PreconditionError
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static voidcheckArgument(boolean expression)Deprecated.As of release 1.1, replaced byGuards.checkArgument(boolean)static voidcheckArgument(boolean expression, String message)Deprecated.As of release 1.1, replaced byGuards.checkArgument(boolean, String)static voidcheckArgument(boolean expression, String pattern, Object... args)Deprecated.As of release 1.1, replaced byGuards.checkArgument(boolean, String, Object...)static intcheckElementIndex(int index, int size)Deprecated.As of release 1.1, replaced byGuards.checkElementIndex(int, int)static <T> TcheckEqualTo(T value, T other)Deprecated.As of release 1.1, replaced byGuards.checkEqualTo(Object, Object)static <T> TcheckEqualTo(T value, T other, String message)Deprecated.As of release 1.1, replaced byGuards.checkEqualTo(Object, Object, String)static <T> TcheckEqualTo(T value, T other, String pattern, Object... args)Deprecated.As of release 1.1, replaced byGuards.checkEqualTo(Object, Object, String, Object...)static <C extends Comparable<C>>
CcheckGreaterThan(C value, C lowerBoundExclusive)Deprecated.As of release 1.1, replaced byGuards.checkGreaterThan(Comparable, Comparable)static <C extends Comparable<C>>
CcheckGreaterThan(C value, C lowerBoundExclusive, String message)Deprecated.As of release 1.1, replaced byGuards.checkGreaterThan(Comparable, Comparable, String)static <C extends Comparable<C>>
CcheckGreaterThan(C value, C lowerBoundExclusive, String pattern, Object... args)Deprecated.As of release 1.1, replaced byGuards.checkGreaterThan(Comparable, Comparable, String)static <C extends Comparable<C>>
CcheckGreaterThanOrEqualTo(C value, C lowerBoundInclusive)Deprecated.As of release 1.1, replaced byGuards.checkGreaterThanOrEqualTo(Comparable, Comparable)static <C extends Comparable<C>>
CcheckGreaterThanOrEqualTo(C value, C lowerBoundInclusive, String message)Deprecated.As of release 1.1, replaced byGuards.checkGreaterThanOrEqualTo(Comparable, Comparable, String)static <C extends Comparable<C>>
CcheckGreaterThanOrEqualTo(C value, C lowerBoundInclusive, String pattern, Object... args)Deprecated.As of release 1.1, replaced byGuards.checkGreaterThanOrEqualTo(Comparable, Comparable, String, Object...)static <T> TcheckInstanceOf(T reference, Class<?> type)Deprecated.As of release 1.1, replaced byGuards.checkInstanceOf(Object, Class)static <T> TcheckInstanceOf(T reference, Class<?> type, String message)Deprecated.As of release 1.1, replaced byGuards.checkInstanceOf(Object, Class, String)static <T> TcheckInstanceOf(T reference, Class<?> type, String pattern, Object... args)Deprecated.As of release 1.1, replaced byGuards.checkInstanceOf(Object, Class, String, Object...)static <C extends Comparable<C>>
CcheckLessThan(C value, C upperBoundExclusive)Deprecated.As of release 1.1, replaced byGuards.checkLessThan(Comparable, Comparable)static <C extends Comparable<C>>
CcheckLessThan(C value, C upperBoundExclusive, String message)Deprecated.As of release 1.1, replaced byGuards.checkLessThan(Comparable, Comparable, String)static <C extends Comparable<C>>
CcheckLessThan(C value, C upperBoundExclusive, String pattern, Object... args)Deprecated.As of release 1.1, replaced byGuards.checkLessThan(Comparable, Comparable, String, Object...)static <C extends Comparable<C>>
CcheckLessThanOrEqualTo(C value, C upperBoundInclusive)Deprecated.As of release 1.1, replaced byGuards.checkLessThanOrEqualTo(Comparable, Comparable)static <C extends Comparable<C>>
CcheckLessThanOrEqualTo(C value, C upperBoundInclusive, String message)Deprecated.As of release 1.1, replaced byGuards.checkLessThanOrEqualTo(Comparable, Comparable)static <C extends Comparable<C>>
CcheckLessThanOrEqualTo(C value, C upperBoundInclusive, String pattern, Object... args)Deprecated.As of release 1.1, replaced byGuards.checkLessThanOrEqualTo(Comparable, Comparable, String, Object...)static <C extends Collection<? extends T>,T>
CcheckNotContainsNull(C collection)Deprecated.As of release 1.1, replaced byGuards.checkNotContainsNull(Collection)static <C extends Collection<? extends T>,T>
CcheckNotContainsNull(C collection, String message)Deprecated.As of release 1.1, replaced byGuards.checkNotContainsNull(Collection, String)static <C extends Collection<? extends T>,T>
CcheckNotContainsNull(C collection, String pattern, Object... args)Deprecated.As of release 1.1, replaced byGuards.checkNotContainsNull(Collection, String, Object...)static <T> TcheckNotNull(T reference)Deprecated.As of release 1.1, replaced byGuards.checkNotNull(Object)static <T> TcheckNotNull(T reference, String message)Deprecated.As of release 1.1, replaced byGuards.checkNotNull(Object, String)static <T> TcheckNotNull(T reference, String pattern, Object... args)Deprecated.As of release 1.1, replaced byGuards.checkNotNull(Object, String, Object...)static intcheckPositionIndex(int index, int size)Deprecated.As of release 1.1, replaced byGuards.checkPositionIndex(int, int)static voidcheckState(boolean expression)Deprecated.As of release 1.1, replaced byGuards.checkState(boolean)static voidcheckState(boolean expression, String message)Deprecated.As of release 1.1, replaced byGuards.checkState(boolean, String)static voidcheckState(boolean expression, String pattern, Object... args)Deprecated.As of release 1.1, replaced byGuards.checkState(boolean, String, Object...)static BooleanPredicaterequireThat(boolean expression)static IntPredicaterequireThat(int expression)static ObjectPredicate<ObjectPredicate,Object>requireThat(Object expression)static StringPredicaterequireThat(String expression)
-
-
-
Method Detail
-
checkArgument
@Deprecated public static void checkArgument(boolean expression)
Deprecated.As of release 1.1, replaced byGuards.checkArgument(boolean)
-
checkArgument
@Deprecated public static void checkArgument(boolean expression, String message)
Deprecated.As of release 1.1, replaced byGuards.checkArgument(boolean, String)
-
checkArgument
@Deprecated public static void checkArgument(boolean expression, String pattern, Object... args)
Deprecated.As of release 1.1, replaced byGuards.checkArgument(boolean, String, Object...)
-
checkState
@Deprecated public static void checkState(boolean expression)
Deprecated.As of release 1.1, replaced byGuards.checkState(boolean)
-
checkState
@Deprecated public static void checkState(boolean expression, String message)
Deprecated.As of release 1.1, replaced byGuards.checkState(boolean, String)
-
checkState
@Deprecated public static void checkState(boolean expression, String pattern, Object... args)
Deprecated.As of release 1.1, replaced byGuards.checkState(boolean, String, Object...)
-
checkNotNull
@Deprecated public static <T> T checkNotNull(@Nullable T reference)
Deprecated.As of release 1.1, replaced byGuards.checkNotNull(Object)
-
checkNotNull
@Deprecated public static <T> T checkNotNull(@Nullable T reference, String message)
Deprecated.As of release 1.1, replaced byGuards.checkNotNull(Object, String)
-
checkNotNull
@Deprecated public static <T> T checkNotNull(@Nullable T reference, String pattern, Object... args)
Deprecated.As of release 1.1, replaced byGuards.checkNotNull(Object, String, Object...)
-
checkNotContainsNull
@Deprecated public static <C extends Collection<? extends T>,T> C checkNotContainsNull(C collection)
Deprecated.As of release 1.1, replaced byGuards.checkNotContainsNull(Collection)
-
checkNotContainsNull
@Deprecated public static <C extends Collection<? extends T>,T> C checkNotContainsNull(C collection, String message)
Deprecated.As of release 1.1, replaced byGuards.checkNotContainsNull(Collection, String)
-
checkNotContainsNull
@Deprecated public static <C extends Collection<? extends T>,T> C checkNotContainsNull(C collection, String pattern, Object... args)
Deprecated.As of release 1.1, replaced byGuards.checkNotContainsNull(Collection, String, Object...)
-
checkInstanceOf
@Deprecated public static <T> T checkInstanceOf(T reference, Class<?> type)
Deprecated.As of release 1.1, replaced byGuards.checkInstanceOf(Object, Class)
-
checkInstanceOf
@Deprecated public static <T> T checkInstanceOf(T reference, Class<?> type, String message)
Deprecated.As of release 1.1, replaced byGuards.checkInstanceOf(Object, Class, String)
-
checkInstanceOf
@Deprecated public static <T> T checkInstanceOf(T reference, Class<?> type, String pattern, Object... args)
Deprecated.As of release 1.1, replaced byGuards.checkInstanceOf(Object, Class, String, Object...)
-
checkEqualTo
@Deprecated public static <T> T checkEqualTo(@Nullable T value, @Nullable T other)
Deprecated.As of release 1.1, replaced byGuards.checkEqualTo(Object, Object)
-
checkEqualTo
@Deprecated public static <T> T checkEqualTo(@Nullable T value, @Nullable T other, String message)
Deprecated.As of release 1.1, replaced byGuards.checkEqualTo(Object, Object, String)
-
checkEqualTo
@Deprecated public static <T> T checkEqualTo(@Nullable T value, @Nullable T other, String pattern, Object... args)
Deprecated.As of release 1.1, replaced byGuards.checkEqualTo(Object, Object, String, Object...)
-
checkGreaterThan
@Deprecated public static <C extends Comparable<C>> C checkGreaterThan(C value, C lowerBoundExclusive)
Deprecated.As of release 1.1, replaced byGuards.checkGreaterThan(Comparable, Comparable)
-
checkGreaterThan
@Deprecated public static <C extends Comparable<C>> C checkGreaterThan(C value, C lowerBoundExclusive, String message)
Deprecated.As of release 1.1, replaced byGuards.checkGreaterThan(Comparable, Comparable, String)
-
checkGreaterThan
@Deprecated public static <C extends Comparable<C>> C checkGreaterThan(C value, C lowerBoundExclusive, String pattern, Object... args)
Deprecated.As of release 1.1, replaced byGuards.checkGreaterThan(Comparable, Comparable, String)
-
checkGreaterThanOrEqualTo
@Deprecated public static <C extends Comparable<C>> C checkGreaterThanOrEqualTo(C value, C lowerBoundInclusive)
Deprecated.As of release 1.1, replaced byGuards.checkGreaterThanOrEqualTo(Comparable, Comparable)
-
checkGreaterThanOrEqualTo
@Deprecated public static <C extends Comparable<C>> C checkGreaterThanOrEqualTo(C value, C lowerBoundInclusive, String message)
Deprecated.As of release 1.1, replaced byGuards.checkGreaterThanOrEqualTo(Comparable, Comparable, String)
-
checkGreaterThanOrEqualTo
@Deprecated public static <C extends Comparable<C>> C checkGreaterThanOrEqualTo(C value, C lowerBoundInclusive, String pattern, Object... args)
Deprecated.As of release 1.1, replaced byGuards.checkGreaterThanOrEqualTo(Comparable, Comparable, String, Object...)
-
checkLessThan
@Deprecated public static <C extends Comparable<C>> C checkLessThan(C value, C upperBoundExclusive)
Deprecated.As of release 1.1, replaced byGuards.checkLessThan(Comparable, Comparable)
-
checkLessThan
@Deprecated public static <C extends Comparable<C>> C checkLessThan(C value, C upperBoundExclusive, String message)
Deprecated.As of release 1.1, replaced byGuards.checkLessThan(Comparable, Comparable, String)
-
checkLessThan
@Deprecated public static <C extends Comparable<C>> C checkLessThan(C value, C upperBoundExclusive, String pattern, Object... args)
Deprecated.As of release 1.1, replaced byGuards.checkLessThan(Comparable, Comparable, String, Object...)
-
checkLessThanOrEqualTo
@Deprecated public static <C extends Comparable<C>> C checkLessThanOrEqualTo(C value, C upperBoundInclusive)
Deprecated.As of release 1.1, replaced byGuards.checkLessThanOrEqualTo(Comparable, Comparable)
-
checkLessThanOrEqualTo
@Deprecated public static <C extends Comparable<C>> C checkLessThanOrEqualTo(C value, C upperBoundInclusive, String message)
Deprecated.As of release 1.1, replaced byGuards.checkLessThanOrEqualTo(Comparable, Comparable)
-
checkLessThanOrEqualTo
@Deprecated public static <C extends Comparable<C>> C checkLessThanOrEqualTo(C value, C upperBoundInclusive, String pattern, Object... args)
Deprecated.As of release 1.1, replaced byGuards.checkLessThanOrEqualTo(Comparable, Comparable, String, Object...)
-
checkElementIndex
@Deprecated public static int checkElementIndex(@Nonnegative int index, @Nonnegative int size)
Deprecated.As of release 1.1, replaced byGuards.checkElementIndex(int, int)
-
checkPositionIndex
@Deprecated public static int checkPositionIndex(@Nonnegative int index, @Nonnegative int size)
Deprecated.As of release 1.1, replaced byGuards.checkPositionIndex(int, int)
-
requireThat
public static IntPredicate requireThat(int expression)
-
requireThat
public static BooleanPredicate requireThat(boolean expression)
-
requireThat
public static StringPredicate requireThat(String expression)
-
requireThat
public static ObjectPredicate<ObjectPredicate,Object> requireThat(Object expression)
-
-