Package ch.usi.si.codelounge.jsicko
Class ContractUtils
- java.lang.Object
-
- ch.usi.si.codelounge.jsicko.ContractUtils
-
public abstract class ContractUtils extends Object
Utils to simplify the formulation of properties in contracts.
-
-
Field Summary
Fields Modifier and Type Field Description static BinaryOperator<Boolean>iffLogical Equality as a binary operator.static BinaryOperator<Boolean>impliesImplication as a binary operator.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <E> longcount(Collection<E> collection, Predicate<E> argument)Counts the elements of a collection that satisfy a given predicate.static <E> booleanexists(Collection<E> collection, Predicate<E> argument)Represents an existential qualification over the elements of a collection.static booleanexistsInt(int lower, int upper, IntPredicate argument)Represents an existential qualification over a finite set (i.e., a range) of integers.static <E> booleanforAll(Collection<E> collection, Predicate<E> argument)Represents a universal qualification over the elements of a collection.static booleanforAllInts(int lower, int upper, IntPredicate argument)Represents a universal qualification over a finite set (i.e., a range) of integers.static booleaniff(boolean a, boolean b)Represents logical equality (if and only if), also called biconditional.static booleanimplies(boolean antecedent, boolean consequent)Deprecated.this method does not (obviously) short-circuit the consequent.static booleanimplies(boolean antecedent, BooleanSupplier consequent)Represents boolean implication.static booleanimplies(boolean antecedent, BooleanSupplier consequent, BooleanSupplier elseCondition)Represents a boolean implication with an else condition.static <T extends Comparable<? super T>>
booleanisSorted(Collection<T> returns)Checks if a given collection is sorted.
-
-
-
Field Detail
-
implies
public static BinaryOperator<Boolean> implies
Implication as a binary operator. If you use this implies operator, note that the consequent is always pre-evaluated before the implication itself.
-
iff
public static BinaryOperator<Boolean> iff
Logical Equality as a binary operator.
-
-
Method Detail
-
implies
@Deprecated public static boolean implies(boolean antecedent, boolean consequent)
Deprecated.this method does not (obviously) short-circuit the consequent. Useimplies(boolean, BooleanSupplier)instead.Represents boolean implication.- Parameters:
antecedent- the antecedent of the implication.consequent- the consequent of the implication.- Returns:
trueiff antecedent implies consequent.
-
implies
public static boolean implies(boolean antecedent, BooleanSupplier consequent)Represents boolean implication.- Parameters:
antecedent- the antecedent of the implication.consequent- the consequent of the implication.- Returns:
trueiff antecedent implies consequent.
-
implies
public static boolean implies(boolean antecedent, BooleanSupplier consequent, BooleanSupplier elseCondition)Represents a boolean implication with an else condition. This utility method is used when you need to express a pair of implications where the antecedent of the second is the negation of the antecedent of the first, thus representing a logic if-then-else.- Parameters:
antecedent- the antecedent of the implication.consequent- the consequent of the implication.elseCondition- the consequent when considering the negated antecedent.- Returns:
trueiff antecedent implies consequent and !antecedent implies elseCondition.
-
iff
public static boolean iff(boolean a, boolean b)Represents logical equality (if and only if), also called biconditional.- Parameters:
a- the first argument of the equality.b- the second argument of the equality.- Returns:
trueiff antecedent is equal to consequent.
-
forAllInts
public static boolean forAllInts(int lower, int upper, IntPredicate argument)Represents a universal qualification over a finite set (i.e., a range) of integers.- Parameters:
lower- the lower bound of the set.upper- the upper (excluded) bound of the integer set.argument- an integer predicate as the argument of the quantification.- Returns:
trueiffargumentholds for every integer betweenlower(included) andupperexcluded.
-
forAll
public static <E> boolean forAll(Collection<E> collection, Predicate<E> argument)
Represents a universal qualification over the elements of a collection.- Type Parameters:
E- the type of the elements in the collection.- Parameters:
collection- A collection of elements.argument- a predicate overE.- Returns:
trueiffargumentholds for every element in thecollection.
-
existsInt
public static boolean existsInt(int lower, int upper, IntPredicate argument)Represents an existential qualification over a finite set (i.e., a range) of integers.- Parameters:
lower- the lower bound of the set.upper- the upper (excluded) bound of the integer set.argument- an integer predicate as the argument of the quantification.- Returns:
trueiffargumentholds for at least one integer betweenlower(included) andupperexcluded.
-
exists
public static <E> boolean exists(Collection<E> collection, Predicate<E> argument)
Represents an existential qualification over the elements of a collection.- Type Parameters:
E- the type of the elements in the collection.- Parameters:
collection- A collection of elements.argument- a predicate overE.- Returns:
trueiffargumentholds for at least one element in thecollection.
-
count
public static <E> long count(Collection<E> collection, Predicate<E> argument)
Counts the elements of a collection that satisfy a given predicate.- Type Parameters:
E- the type of the elements in the collection.- Parameters:
collection- A collection of elements.argument- a predicate overE.- Returns:
- the number of elements in the collection that satisfy the argument.
-
isSorted
public static <T extends Comparable<? super T>> boolean isSorted(Collection<T> returns)
Checks if a given collection is sorted.- Type Parameters:
T- The type of the collection, must be comparable.- Parameters:
returns- the collection to be checked.- Returns:
trueiff the collection is sorted.
-
-