Class Postconditions
- java.lang.Object
-
- com.io7m.jaffirm.core.Postconditions
-
public final class Postconditions extends java.lang.ObjectFunctions to check postconditions.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcheckPostcondition(boolean condition, java.lang.String message)A specialized version ofcheckPostcondition(Object, boolean, Function)that does not mention an input value.static voidcheckPostcondition(boolean condition, java.util.function.Supplier<java.lang.String> message)A specialized version ofcheckPostcondition(Object, boolean, Function)that does not mention an input value.static <T> TcheckPostcondition(T value, boolean condition, java.util.function.Function<T,java.lang.String> describer)Evaluate the givenpredicateusingvalueas input.static <T> TcheckPostcondition(T value, ContractConditionType<T> condition)Evaluate the givenpredicateusingvalueas input.static <T> TcheckPostcondition(T value, java.util.function.Predicate<T> predicate, java.util.function.Function<T,java.lang.String> describer)Evaluate the givenpredicateusingvalueas input.static doublecheckPostconditionD(double value, boolean condition, java.util.function.DoubleFunction<java.lang.String> describer)Adoublespecialized version ofcheckPostcondition(Object, boolean, Function)static doublecheckPostconditionD(double value, ContractDoubleConditionType condition)Adoublespecialized version ofcheckPostcondition(Object, ContractConditionType).static doublecheckPostconditionD(double value, java.util.function.DoublePredicate predicate, java.util.function.DoubleFunction<java.lang.String> describer)Adoublespecialized version ofcheckPostcondition(Object, Predicate, Function)static intcheckPostconditionI(int value, boolean condition, java.util.function.IntFunction<java.lang.String> describer)Anintspecialized version ofcheckPostcondition(Object, boolean, Function).static intcheckPostconditionI(int value, ContractIntConditionType condition)Anintspecialized version ofcheckPostcondition(Object, ContractConditionType).static intcheckPostconditionI(int value, java.util.function.IntPredicate predicate, java.util.function.IntFunction<java.lang.String> describer)Anintspecialized version ofcheckPostcondition(Object, ContractConditionType).static longcheckPostconditionL(long value, boolean condition, java.util.function.LongFunction<java.lang.String> describer)Alongspecialized version ofcheckPostcondition(Object, Predicate, Function)static longcheckPostconditionL(long value, ContractLongConditionType condition)Alongspecialized version ofcheckPostcondition(Object, ContractConditionType).static longcheckPostconditionL(long value, java.util.function.LongPredicate predicate, java.util.function.LongFunction<java.lang.String> describer)Alongspecialized version ofcheckPostcondition(Object, Predicate, Function)static <T> TcheckPostconditions(T value, ContractConditionType<T>... conditions)Evaluate all of the givenconditionsusingvalueas input.static doublecheckPostconditionsD(double value, ContractDoubleConditionType... conditions)Adoublespecialized version ofcheckPostconditions(Object, ContractConditionType[])static intcheckPostconditionsI(int value, ContractIntConditionType... conditions)Anintspecialized version ofcheckPostconditions(Object, ContractConditionType[])static longcheckPostconditionsL(long value, ContractLongConditionType... conditions)Alongspecialized version ofcheckPostconditions(Object, ContractConditionType[])static voidcheckPostconditionV(boolean condition, java.lang.String format, java.lang.Object... objects)A version ofcheckPostcondition(boolean, String)that constructs a description message from the given format string and arguments.static <T> TcheckPostconditionV(T value, boolean condition, java.lang.String format, java.lang.Object... objects)A version ofcheckPostcondition(boolean, String)that constructs a description message from the given format string and arguments.
-
-
-
Method Detail
-
checkPostconditions
@SafeVarargs public static <T> T checkPostconditions(T value, ContractConditionType<T>... conditions) throws PostconditionViolationExceptionEvaluate all of the given
conditionsusingvalueas input.All of the conditions are evaluated and the function throws
PostconditionViolationExceptionif 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:
PostconditionViolationException- If any of the conditions are false
-
checkPostconditionsI
public static int checkPostconditionsI(int value, ContractIntConditionType... conditions) throws PostconditionViolationExceptionAnintspecialized version ofcheckPostconditions(Object, ContractConditionType[])- Parameters:
value- The valueconditions- The conditions the value must obey- Returns:
- value
- Throws:
PostconditionViolationException- If any of the conditions are false
-
checkPostconditionsL
public static long checkPostconditionsL(long value, ContractLongConditionType... conditions) throws PostconditionViolationExceptionAlongspecialized version ofcheckPostconditions(Object, ContractConditionType[])- Parameters:
value- The valueconditions- The conditions the value must obey- Returns:
- value
- Throws:
PostconditionViolationException- If any of the conditions are false
-
checkPostconditionsD
public static double checkPostconditionsD(double value, ContractDoubleConditionType... conditions) throws PostconditionViolationExceptionAdoublespecialized version ofcheckPostconditions(Object, ContractConditionType[])- Parameters:
value- The valueconditions- The conditions the value must obey- Returns:
- value
- Throws:
PostconditionViolationException- If any of the conditions are false
-
checkPostcondition
public static <T> T checkPostcondition(T value, ContractConditionType<T> condition) throws PostconditionViolationExceptionEvaluate the given
predicateusingvalueas input.The function throws
PostconditionViolationExceptionif the predicate is false.- Type Parameters:
T- The type of values- Parameters:
value- The valuecondition- The predicate- Returns:
- value
- Throws:
PostconditionViolationException- If the predicate is false
-
checkPostcondition
public static <T> T checkPostcondition(T value, java.util.function.Predicate<T> predicate, java.util.function.Function<T,java.lang.String> describer)Evaluate the given
predicateusingvalueas input.The function throws
PostconditionViolationExceptionif 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:
PostconditionViolationException- If the predicate is false
-
checkPostcondition
public static <T> T checkPostcondition(T value, boolean condition, java.util.function.Function<T,java.lang.String> describer)Evaluate the given
predicateusingvalueas input.The function throws
PostconditionViolationExceptionif 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:
PostconditionViolationException- If the predicate is false
-
checkPostcondition
public static void checkPostcondition(boolean condition, java.lang.String message) throws PostconditionViolationExceptionA specialized version ofcheckPostcondition(Object, boolean, Function)that does not mention an input value.- Parameters:
condition- The predicatemessage- The predicate description- Throws:
PostconditionViolationException- Iffpredicate == false
-
checkPostcondition
public static void checkPostcondition(boolean condition, java.util.function.Supplier<java.lang.String> message) throws PostconditionViolationExceptionA specialized version ofcheckPostcondition(Object, boolean, Function)that does not mention an input value.- Parameters:
condition- The predicatemessage- The predicate description supplier- Throws:
PostconditionViolationException- Iffpredicate == false
-
checkPostconditionV
public static <T> T checkPostconditionV(T value, boolean condition, java.lang.String format, java.lang.Object... objects)A version of
checkPostcondition(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
-
checkPostconditionV
public static void checkPostconditionV(boolean condition, java.lang.String format, java.lang.Object... objects)A version of
checkPostcondition(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
-
checkPostconditionI
public static int checkPostconditionI(int value, ContractIntConditionType condition) throws PostconditionViolationExceptionAnintspecialized version ofcheckPostcondition(Object, ContractConditionType).- Parameters:
value- The valuecondition- The predicate- Returns:
- value
- Throws:
PostconditionViolationException- If the predicate is false
-
checkPostconditionI
public static int checkPostconditionI(int value, java.util.function.IntPredicate predicate, java.util.function.IntFunction<java.lang.String> describer)Anintspecialized version ofcheckPostcondition(Object, ContractConditionType).- Parameters:
value- The valuepredicate- The predicatedescriber- The describer for the predicate- Returns:
- value
- Throws:
PostconditionViolationException- If the predicate is false
-
checkPostconditionI
public static int checkPostconditionI(int value, boolean condition, java.util.function.IntFunction<java.lang.String> describer)Anintspecialized version ofcheckPostcondition(Object, boolean, Function).- Parameters:
value- The valuecondition- The predicatedescriber- The describer for the predicate- Returns:
- value
- Throws:
PostconditionViolationException- If the predicate is false
-
checkPostconditionL
public static long checkPostconditionL(long value, ContractLongConditionType condition) throws PostconditionViolationExceptionAlongspecialized version ofcheckPostcondition(Object, ContractConditionType).- Parameters:
value- The valuecondition- The predicate- Returns:
- value
- Throws:
PostconditionViolationException- If the predicate is false
-
checkPostconditionL
public static long checkPostconditionL(long value, java.util.function.LongPredicate predicate, java.util.function.LongFunction<java.lang.String> describer)Alongspecialized version ofcheckPostcondition(Object, Predicate, Function)- Parameters:
value- The valuepredicate- The predicatedescriber- The describer of the predicate- Returns:
- value
- Throws:
PostconditionViolationException- If the predicate is false
-
checkPostconditionL
public static long checkPostconditionL(long value, boolean condition, java.util.function.LongFunction<java.lang.String> describer)Alongspecialized version ofcheckPostcondition(Object, Predicate, Function)- Parameters:
condition- The predicatevalue- The valuedescriber- The describer of the predicate- Returns:
- value
- Throws:
PostconditionViolationException- If the predicate is false
-
checkPostconditionD
public static double checkPostconditionD(double value, ContractDoubleConditionType condition) throws PostconditionViolationExceptionAdoublespecialized version ofcheckPostcondition(Object, ContractConditionType).- Parameters:
value- The valuecondition- The predicate- Returns:
- value
- Throws:
PostconditionViolationException- If the predicate is false
-
checkPostconditionD
public static double checkPostconditionD(double value, java.util.function.DoublePredicate predicate, java.util.function.DoubleFunction<java.lang.String> describer)Adoublespecialized version ofcheckPostcondition(Object, Predicate, Function)- Parameters:
value- The valuepredicate- The predicatedescriber- The describer of the predicate- Returns:
- value
- Throws:
PostconditionViolationException- If the predicate is false
-
checkPostconditionD
public static double checkPostconditionD(double value, boolean condition, java.util.function.DoubleFunction<java.lang.String> describer)Adoublespecialized version ofcheckPostcondition(Object, boolean, Function)- Parameters:
value- The valuecondition- The predicatedescriber- The describer of the predicate- Returns:
- value
- Throws:
PostconditionViolationException- If the predicate is false
-
-