- java.lang.Object
-
- com.io7m.jaffirm.core.Invariants
-
public final class Invariants extends Object
Functions to check invariants.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcheckInvariant(boolean condition, String message)A specialized version ofcheckInvariant(Object, boolean, Function)that does not mention an input value.static voidcheckInvariant(boolean condition, Supplier<String> message)A specialized version ofcheckInvariant(Object, boolean, Function)that does not mention an input value.static <T> TcheckInvariant(T value, boolean condition, Function<T,String> describer)Evaluate the givenpredicateusingvalueas input.static <T> TcheckInvariant(T value, ContractConditionType<T> condition)Evaluate the givenpredicateusingvalueas input.static <T> TcheckInvariant(T value, Predicate<T> predicate, Function<T,String> describer)Evaluate the givenpredicateusingvalueas input.static doublecheckInvariantD(double value, boolean condition, DoubleFunction<String> describer)Adoublespecialized version ofcheckInvariant(Object, boolean, Function)static doublecheckInvariantD(double value, ContractDoubleConditionType condition)Adoublespecialized version ofcheckInvariant(Object, ContractConditionType).static doublecheckInvariantD(double value, DoublePredicate predicate, DoubleFunction<String> describer)Adoublespecialized version ofcheckInvariant(Object, Predicate, Function)static intcheckInvariantI(int value, boolean condition, IntFunction<String> describer)Anintspecialized version ofcheckInvariant(Object, boolean, Function).static intcheckInvariantI(int value, ContractIntConditionType condition)Anintspecialized version ofcheckInvariant(Object, ContractConditionType).static intcheckInvariantI(int value, IntPredicate predicate, IntFunction<String> describer)Anintspecialized version ofcheckInvariant(Object, ContractConditionType).static longcheckInvariantL(long value, boolean condition, LongFunction<String> describer)Alongspecialized version ofcheckInvariant(Object, Predicate, Function)static longcheckInvariantL(long value, ContractLongConditionType condition)Alongspecialized version ofcheckInvariant(Object, ContractConditionType).static longcheckInvariantL(long value, LongPredicate predicate, LongFunction<String> describer)Alongspecialized version ofcheckInvariant(Object, Predicate, Function)static <T> TcheckInvariants(T value, ContractConditionType<T>... conditions)Evaluate all of the givenconditionsusingvalueas input.static doublecheckInvariantsD(double value, ContractDoubleConditionType... conditions)Adoublespecialized version ofcheckInvariants(Object, ContractConditionType[])static intcheckInvariantsI(int value, ContractIntConditionType... conditions)Anintspecialized version ofcheckInvariants(Object, ContractConditionType[])static longcheckInvariantsL(long value, ContractLongConditionType... conditions)Alongspecialized version ofcheckInvariants(Object, ContractConditionType[])static voidcheckInvariantV(boolean condition, String format, Object... objects)A version ofcheckInvariant(boolean, String)that constructs a description message from the given format string and arguments.static <T> TcheckInvariantV(T value, boolean condition, String format, Object... objects)A version ofcheckInvariant(boolean, String)that constructs a description message from the given format string and arguments.
-
-
-
Method Detail
-
checkInvariants
@SafeVarargs public static <T> T checkInvariants(T value, ContractConditionType<T>... conditions) throws InvariantViolationException
Evaluate all of the given
conditionsusingvalueas input.All of the conditions are evaluated and the function throws
InvariantViolationExceptionif 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:
InvariantViolationException- If any of the conditions are false
-
checkInvariantsI
public static int checkInvariantsI(int value, ContractIntConditionType... conditions) throws InvariantViolationExceptionAnintspecialized version ofcheckInvariants(Object, ContractConditionType[])- Parameters:
value- The valueconditions- The conditions the value must obey- Returns:
- value
- Throws:
InvariantViolationException- If any of the conditions are false
-
checkInvariantsL
public static long checkInvariantsL(long value, ContractLongConditionType... conditions) throws InvariantViolationExceptionAlongspecialized version ofcheckInvariants(Object, ContractConditionType[])- Parameters:
value- The valueconditions- The conditions the value must obey- Returns:
- value
- Throws:
InvariantViolationException- If any of the conditions are false
-
checkInvariantsD
public static double checkInvariantsD(double value, ContractDoubleConditionType... conditions) throws InvariantViolationExceptionAdoublespecialized version ofcheckInvariants(Object, ContractConditionType[])- Parameters:
value- The valueconditions- The conditions the value must obey- Returns:
- value
- Throws:
InvariantViolationException- If any of the conditions are false
-
checkInvariant
public static <T> T checkInvariant(T value, ContractConditionType<T> condition) throws InvariantViolationExceptionEvaluate the given
predicateusingvalueas input.The function throws
InvariantViolationExceptionif the predicate is false.- Type Parameters:
T- The type of values- Parameters:
value- The valuecondition- The predicate- Returns:
- value
- Throws:
InvariantViolationException- If the predicate is false
-
checkInvariant
public static <T> T checkInvariant(T value, Predicate<T> predicate, Function<T,String> describer)Evaluate the given
predicateusingvalueas input.The function throws
InvariantViolationExceptionif 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:
InvariantViolationException- If the predicate is false
-
checkInvariant
public static <T> T checkInvariant(T value, boolean condition, Function<T,String> describer)Evaluate the given
predicateusingvalueas input.The function throws
InvariantViolationExceptionif 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:
InvariantViolationException- If the predicate is false
-
checkInvariant
public static void checkInvariant(boolean condition, String message) throws InvariantViolationExceptionA specialized version ofcheckInvariant(Object, boolean, Function)that does not mention an input value.- Parameters:
condition- The predicatemessage- The predicate description- Throws:
InvariantViolationException- Iffpredicate == false
-
checkInvariant
public static void checkInvariant(boolean condition, Supplier<String> message) throws InvariantViolationExceptionA specialized version ofcheckInvariant(Object, boolean, Function)that does not mention an input value.- Parameters:
condition- The predicatemessage- The predicate description supplier- Throws:
InvariantViolationException- Iffpredicate == false
-
checkInvariantV
public static <T> T checkInvariantV(T value, boolean condition, String format, Object... objects)A version of
checkInvariant(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
-
checkInvariantV
public static void checkInvariantV(boolean condition, String format, Object... objects)A version of
checkInvariant(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
-
checkInvariantI
public static int checkInvariantI(int value, ContractIntConditionType condition) throws InvariantViolationExceptionAnintspecialized version ofcheckInvariant(Object, ContractConditionType).- Parameters:
value- The valuecondition- The predicate- Returns:
- value
- Throws:
InvariantViolationException- If the predicate is false
-
checkInvariantI
public static int checkInvariantI(int value, IntPredicate predicate, IntFunction<String> describer)Anintspecialized version ofcheckInvariant(Object, ContractConditionType).- Parameters:
value- The valuepredicate- The predicatedescriber- The describer for the predicate- Returns:
- value
- Throws:
InvariantViolationException- If the predicate is false
-
checkInvariantI
public static int checkInvariantI(int value, boolean condition, IntFunction<String> describer)Anintspecialized version ofcheckInvariant(Object, boolean, Function).- Parameters:
value- The valuecondition- The predicatedescriber- The describer for the predicate- Returns:
- value
- Throws:
InvariantViolationException- If the predicate is false
-
checkInvariantL
public static long checkInvariantL(long value, ContractLongConditionType condition) throws InvariantViolationExceptionAlongspecialized version ofcheckInvariant(Object, ContractConditionType).- Parameters:
value- The valuecondition- The predicate- Returns:
- value
- Throws:
InvariantViolationException- If the predicate is false
-
checkInvariantL
public static long checkInvariantL(long value, LongPredicate predicate, LongFunction<String> describer)Alongspecialized version ofcheckInvariant(Object, Predicate, Function)- Parameters:
value- The valuepredicate- The predicatedescriber- The describer of the predicate- Returns:
- value
- Throws:
InvariantViolationException- If the predicate is false
-
checkInvariantL
public static long checkInvariantL(long value, boolean condition, LongFunction<String> describer)Alongspecialized version ofcheckInvariant(Object, Predicate, Function)- Parameters:
condition- The predicatevalue- The valuedescriber- The describer of the predicate- Returns:
- value
- Throws:
InvariantViolationException- If the predicate is false
-
checkInvariantD
public static double checkInvariantD(double value, ContractDoubleConditionType condition) throws InvariantViolationExceptionAdoublespecialized version ofcheckInvariant(Object, ContractConditionType).- Parameters:
value- The valuecondition- The predicate- Returns:
- value
- Throws:
InvariantViolationException- If the predicate is false
-
checkInvariantD
public static double checkInvariantD(double value, DoublePredicate predicate, DoubleFunction<String> describer)Adoublespecialized version ofcheckInvariant(Object, Predicate, Function)- Parameters:
value- The valuepredicate- The predicatedescriber- The describer of the predicate- Returns:
- value
- Throws:
InvariantViolationException- If the predicate is false
-
checkInvariantD
public static double checkInvariantD(double value, boolean condition, DoubleFunction<String> describer)Adoublespecialized version ofcheckInvariant(Object, boolean, Function)- Parameters:
value- The valuecondition- The predicatedescriber- The describer of the predicate- Returns:
- value
- Throws:
InvariantViolationException- If the predicate is false
-
-