Class Preconditions
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckPrecondition(boolean condition, String message) A specialized version ofcheckPrecondition(Object, boolean, Function)that does not mention an input value.static voidcheckPrecondition(boolean condition, Supplier<String> message) A specialized version ofcheckPrecondition(Object, boolean, Function)that does not mention an input value.static <T> TcheckPrecondition(T value, boolean condition, Function<T, String> describer) Evaluate the givenpredicateusingvalueas input.static <T> TcheckPrecondition(T value, ContractConditionType<T> condition) Evaluate the givenpredicateusingvalueas input.static <T> TcheckPrecondition(T value, Predicate<T> predicate, Function<T, String> describer) Evaluate the givenpredicateusingvalueas input.static doublecheckPreconditionD(double value, boolean condition, DoubleFunction<String> describer) Adoublespecialized version ofcheckPrecondition(Object, boolean, Function)static doublecheckPreconditionD(double value, ContractDoubleConditionType condition) Adoublespecialized version ofcheckPrecondition(Object, ContractConditionType).static doublecheckPreconditionD(double value, DoublePredicate predicate, DoubleFunction<String> describer) Adoublespecialized version ofcheckPrecondition(Object, Predicate, Function)static intcheckPreconditionI(int value, boolean condition, IntFunction<String> describer) Anintspecialized version ofcheckPrecondition(Object, boolean, Function).static intcheckPreconditionI(int value, ContractIntConditionType condition) Anintspecialized version ofcheckPrecondition(Object, ContractConditionType).static intcheckPreconditionI(int value, IntPredicate predicate, IntFunction<String> describer) Anintspecialized version ofcheckPrecondition(Object, ContractConditionType).static longcheckPreconditionL(long value, boolean condition, LongFunction<String> describer) Alongspecialized version ofcheckPrecondition(Object, Predicate, Function)static longcheckPreconditionL(long value, ContractLongConditionType condition) Alongspecialized version ofcheckPrecondition(Object, ContractConditionType).static longcheckPreconditionL(long value, LongPredicate predicate, LongFunction<String> describer) Alongspecialized version ofcheckPrecondition(Object, Predicate, Function)static <T> TcheckPreconditions(T value, ContractConditionType<T>... conditions) Evaluate all of the givenconditionsusingvalueas input.static doublecheckPreconditionsD(double value, ContractDoubleConditionType... conditions) Adoublespecialized version ofcheckPreconditions(Object, ContractConditionType[])static intcheckPreconditionsI(int value, ContractIntConditionType... conditions) Anintspecialized version ofcheckPreconditions(Object, ContractConditionType[])static longcheckPreconditionsL(long value, ContractLongConditionType... conditions) Alongspecialized version ofcheckPreconditions(Object, ContractConditionType[])static voidcheckPreconditionV(boolean condition, String format, Object... objects) A version ofcheckPrecondition(boolean, String)that constructs a description message from the given format string and arguments.static <T> TcheckPreconditionV(T value, boolean condition, String format, Object... objects) A version ofcheckPrecondition(boolean, String)that constructs a description message from the given format string and arguments.
-
Method Details
-
checkPreconditions
@SafeVarargs public static <T> T checkPreconditions(T value, ContractConditionType<T>... conditions) throws PreconditionViolationException Evaluate all of the given
conditionsusingvalueas input.All of the conditions are evaluated and the function throws
PreconditionViolationExceptionif any of the conditions are false, or raise an exception that is not of typeError. Exceptions of typeErrorare propagated immediately, without any further contract checking.- Type Parameters:
T- The type of values- Parameters:
value- The valueconditions- The set of conditions- Returns:
- value
- Throws:
PreconditionViolationException- If any of the conditions are false
-
checkPreconditionsI
public static int checkPreconditionsI(int value, ContractIntConditionType... conditions) throws PreconditionViolationException Anintspecialized version ofcheckPreconditions(Object, ContractConditionType[])- Parameters:
value- The valueconditions- The conditions the value must obey- Returns:
- value
- Throws:
PreconditionViolationException- If any of the conditions are false
-
checkPreconditionsL
public static long checkPreconditionsL(long value, ContractLongConditionType... conditions) throws PreconditionViolationException Alongspecialized version ofcheckPreconditions(Object, ContractConditionType[])- Parameters:
value- The valueconditions- The conditions the value must obey- Returns:
- value
- Throws:
PreconditionViolationException- If any of the conditions are false
-
checkPreconditionsD
public static double checkPreconditionsD(double value, ContractDoubleConditionType... conditions) throws PreconditionViolationException Adoublespecialized version ofcheckPreconditions(Object, ContractConditionType[])- Parameters:
value- The valueconditions- The conditions the value must obey- Returns:
- value
- Throws:
PreconditionViolationException- If any of the conditions are false
-
checkPrecondition
public static <T> T checkPrecondition(T value, ContractConditionType<T> condition) throws PreconditionViolationException Evaluate the given
predicateusingvalueas input.The function throws
PreconditionViolationExceptionif the predicate is false.- Type Parameters:
T- The type of values- Parameters:
value- The valuecondition- The predicate- Returns:
- value
- Throws:
PreconditionViolationException- If the predicate is false
-
checkPrecondition
public static <T> T checkPrecondition(T value, Predicate<T> predicate, Function<T, String> describer) Evaluate the given
predicateusingvalueas input.The function throws
PreconditionViolationExceptionif the predicate is false.- Type Parameters:
T- The type of values- Parameters:
value- The valuepredicate- The predicatedescriber- A describer for the predicate- Returns:
- value
- Throws:
PreconditionViolationException- If the predicate is false
-
checkPrecondition
Evaluate the given
predicateusingvalueas input.The function throws
PreconditionViolationExceptionif the predicate is false.- Type Parameters:
T- The type of values- Parameters:
value- The valuecondition- The predicatedescriber- A describer for the predicate- Returns:
- value
- Throws:
PreconditionViolationException- If the predicate is false
-
checkPrecondition
public static void checkPrecondition(boolean condition, String message) throws PreconditionViolationException A specialized version ofcheckPrecondition(Object, boolean, Function)that does not mention an input value.- Parameters:
condition- The predicatemessage- The predicate description- Throws:
PreconditionViolationException- Iffpredicate == false
-
checkPrecondition
public static void checkPrecondition(boolean condition, Supplier<String> message) throws PreconditionViolationException A specialized version ofcheckPrecondition(Object, boolean, Function)that does not mention an input value.- Parameters:
condition- The predicatemessage- The predicate description supplier- Throws:
PreconditionViolationException- Iffpredicate == false
-
checkPreconditionV
public static <T> T checkPreconditionV(T value, boolean condition, String format, Object... objects) A version of
checkPrecondition(boolean, String)that constructs a description message from the given format string and arguments.Note that the use of variadic arguments may entail allocating memory on virtual machines that fail to eliminate the allocations with escape analysis.
- Type Parameters:
T- The precise type of values- Parameters:
value- The valuecondition- The predicateformat- The format stringobjects- The format string arguments- Returns:
value- Since:
- 1.1.0
-
checkPreconditionV
A version of
checkPrecondition(boolean, String)that constructs a description message from the given format string and arguments.Note that the use of variadic arguments may entail allocating memory on virtual machines that fail to eliminate the allocations with escape analysis.
- Parameters:
condition- The predicateformat- The format stringobjects- The format string arguments- Since:
- 1.1.0
-
checkPreconditionI
public static int checkPreconditionI(int value, ContractIntConditionType condition) throws PreconditionViolationException Anintspecialized version ofcheckPrecondition(Object, ContractConditionType).- Parameters:
value- The valuecondition- The predicate- Returns:
- value
- Throws:
PreconditionViolationException- If the predicate is false
-
checkPreconditionI
public static int checkPreconditionI(int value, IntPredicate predicate, IntFunction<String> describer) Anintspecialized version ofcheckPrecondition(Object, ContractConditionType).- Parameters:
value- The valuepredicate- The predicatedescriber- The describer for the predicate- Returns:
- value
- Throws:
PreconditionViolationException- If the predicate is false
-
checkPreconditionI
Anintspecialized version ofcheckPrecondition(Object, boolean, Function).- Parameters:
value- The valuecondition- The predicatedescriber- The describer for the predicate- Returns:
- value
- Throws:
PreconditionViolationException- If the predicate is false
-
checkPreconditionL
public static long checkPreconditionL(long value, ContractLongConditionType condition) throws PreconditionViolationException Alongspecialized version ofcheckPrecondition(Object, ContractConditionType).- Parameters:
value- The valuecondition- The predicate- Returns:
- value
- Throws:
PreconditionViolationException- If the predicate is false
-
checkPreconditionL
public static long checkPreconditionL(long value, LongPredicate predicate, LongFunction<String> describer) Alongspecialized version ofcheckPrecondition(Object, Predicate, Function)- Parameters:
value- The valuepredicate- The predicatedescriber- The describer of the predicate- Returns:
- value
- Throws:
PreconditionViolationException- If the predicate is false
-
checkPreconditionL
public static long checkPreconditionL(long value, boolean condition, LongFunction<String> describer) Alongspecialized version ofcheckPrecondition(Object, Predicate, Function)- Parameters:
condition- The predicatevalue- The valuedescriber- The describer of the predicate- Returns:
- value
- Throws:
PreconditionViolationException- If the predicate is false
-
checkPreconditionD
public static double checkPreconditionD(double value, ContractDoubleConditionType condition) throws PreconditionViolationException Adoublespecialized version ofcheckPrecondition(Object, ContractConditionType).- Parameters:
value- The valuecondition- The predicate- Returns:
- value
- Throws:
PreconditionViolationException- If the predicate is false
-
checkPreconditionD
public static double checkPreconditionD(double value, DoublePredicate predicate, DoubleFunction<String> describer) Adoublespecialized version ofcheckPrecondition(Object, Predicate, Function)- Parameters:
value- The valuepredicate- The predicatedescriber- The describer of the predicate- Returns:
- value
- Throws:
PreconditionViolationException- If the predicate is false
-
checkPreconditionD
public static double checkPreconditionD(double value, boolean condition, DoubleFunction<String> describer) Adoublespecialized version ofcheckPrecondition(Object, boolean, Function)- Parameters:
value- The valuecondition- The predicatedescriber- The describer of the predicate- Returns:
- value
- Throws:
PreconditionViolationException- If the predicate is false
-