Class ContractUtils


  • public abstract class ContractUtils
    extends Object
    Utils to simplify the formulation of properties in contracts.
    • 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.
    • Method Detail

      • implies

        @Deprecated
        public static boolean implies​(boolean antecedent,
                                      boolean consequent)
        Deprecated.
        this method does not (obviously) short-circuit the consequent. Use implies(boolean, BooleanSupplier) instead.
        Represents boolean implication.
        Parameters:
        antecedent - the antecedent of the implication.
        consequent - the consequent of the implication.
        Returns:
        true iff 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:
        true iff 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:
        true iff 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:
        true iff 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:
        true iff argument holds for every integer between lower (included) and upper excluded.
      • 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 over E.
        Returns:
        true iff argument holds for every element in the collection.
      • 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:
        true iff argument holds for at least one integer between lower (included) and upper excluded.
      • 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 over E.
        Returns:
        true iff argument holds for at least one element in the collection.
      • 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 over E.
        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:
        true iff the collection is sorted.