Class ContractCondition<T>

java.lang.Object
com.io7m.jaffirm.core.ContractCondition<T>
Type Parameters:
T - The type of input values
All Implemented Interfaces:
ContractConditionType<T>

public final class ContractCondition<T> extends Object implements ContractConditionType<T>
An individual predicate in a contract.
  • Method Details

    • predicate

      public Predicate<T> predicate()
      Specified by:
      predicate in interface ContractConditionType<T>
      Returns:
      A predicate that must evaluate to true for the contract to hold
    • describer

      public Function<T,String> describer()
      Specified by:
      describer in interface ContractConditionType<T>
      Returns:
      A function that returns a textual description of the predicate
    • withPredicate

      public final ContractCondition<T> withPredicate(Predicate<T> value)
      Copy the current immutable object by setting a value for the predicate attribute. A shallow reference equality check is used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for predicate
      Returns:
      A modified copy of the this object
    • withDescriber

      public final ContractCondition<T> withDescriber(Function<T,String> value)
      Copy the current immutable object by setting a value for the describer attribute. A shallow reference equality check is used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for describer
      Returns:
      A modified copy of the this object
    • equals

      public boolean equals(Object another)
      This instance is equal to all instances of ContractCondition that have equal attribute values.
      Overrides:
      equals in class Object
      Returns:
      true if this is equal to another instance
    • hashCode

      public int hashCode()
      Computes a hash code from attributes: predicate, describer.
      Overrides:
      hashCode in class Object
      Returns:
      hashCode value
    • toString

      public String toString()
      Prints the immutable value ContractCondition with attribute values.
      Overrides:
      toString in class Object
      Returns:
      A string representation of the value
    • of

      public static <T> ContractCondition<T> of(Predicate<T> predicate, Function<T,String> describer)
      Construct a new immutable ContractCondition instance.
      Parameters:
      predicate - The value for the predicate attribute
      describer - The value for the describer attribute
      Returns:
      An immutable ContractCondition instance
    • copyOf

      public static <T> ContractCondition<T> copyOf(ContractConditionType<T> instance)
      Creates an immutable copy of a ContractConditionType value. Uses accessors to get values to initialize the new immutable instance. If an instance is already immutable, it is returned as is.
      Type Parameters:
      T - generic parameter T
      Parameters:
      instance - The instance to copy
      Returns:
      A copied immutable ContractCondition instance
    • builder

      public static <T> ContractCondition.Builder<T> builder()
      Creates a builder for ContractCondition.
      Type Parameters:
      T - generic parameter T
      Returns:
      A new ContractCondition builder