- 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classContractCondition.Builder<T>Builds instances of typeContractCondition.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> ContractCondition.Builder<T>builder()Creates a builder forContractCondition.static <T> ContractCondition<T>copyOf(ContractConditionType<T> instance)Creates an immutable copy of aContractConditionTypevalue.Function<T,String>describer()booleanequals(Object another)This instance is equal to all instances ofContractConditionthat have equal attribute values.inthashCode()Computes a hash code from attributes:predicate,describer.static <T> ContractCondition<T>of(Predicate<T> predicate, Function<T,String> describer)Construct a new immutableContractConditioninstance.Predicate<T>predicate()StringtoString()Prints the immutable valueContractConditionwith attribute values.ContractCondition<T>withDescriber(Function<T,String> value)Copy the current immutable object by setting a value for thedescriberattribute.ContractCondition<T>withPredicate(Predicate<T> value)Copy the current immutable object by setting a value for thepredicateattribute.
-
-
-
Method Detail
-
predicate
public Predicate<T> predicate()
- Specified by:
predicatein interfaceContractConditionType<T>- Returns:
- A predicate that must evaluate to
truefor the contract to hold
-
describer
public Function<T,String> describer()
- Specified by:
describerin interfaceContractConditionType<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 thepredicateattribute. A shallow reference equality check is used to prevent copying of the same value by returningthis.- Parameters:
value- A new value for predicate- Returns:
- A modified copy of the
thisobject
-
withDescriber
public final ContractCondition<T> withDescriber(Function<T,String> value)
Copy the current immutable object by setting a value for thedescriberattribute. A shallow reference equality check is used to prevent copying of the same value by returningthis.- Parameters:
value- A new value for describer- Returns:
- A modified copy of the
thisobject
-
equals
public boolean equals(Object another)
This instance is equal to all instances ofContractConditionthat have equal attribute values.
-
hashCode
public int hashCode()
Computes a hash code from attributes:predicate,describer.
-
toString
public String toString()
Prints the immutable valueContractConditionwith attribute values.
-
of
public static <T> ContractCondition<T> of(Predicate<T> predicate, Function<T,String> describer)
Construct a new immutableContractConditioninstance.- Parameters:
predicate- The value for thepredicateattributedescriber- The value for thedescriberattribute- Returns:
- An immutable ContractCondition instance
-
copyOf
public static <T> ContractCondition<T> copyOf(ContractConditionType<T> instance)
Creates an immutable copy of aContractConditionTypevalue. 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 forContractCondition.- Type Parameters:
T- generic parameter T- Returns:
- A new ContractCondition builder
-
-