Package com.io7m.jaffirm.core
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 java.lang.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.java.util.function.Function<T,java.lang.String>describer()booleanequals(java.lang.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(java.util.function.Predicate<T> predicate, java.util.function.Function<T,java.lang.String> describer)Construct a new immutableContractConditioninstance.java.util.function.Predicate<T>predicate()java.lang.StringtoString()Prints the immutable valueContractConditionwith attribute values.ContractCondition<T>withDescriber(java.util.function.Function<T,java.lang.String> value)Copy the current immutable object by setting a value for thedescriberattribute.ContractCondition<T>withPredicate(java.util.function.Predicate<T> value)Copy the current immutable object by setting a value for thepredicateattribute.
-
-
-
Method Detail
-
predicate
public java.util.function.Predicate<T> predicate()
- Specified by:
predicatein interfaceContractConditionType<T>- Returns:
- A predicate that must evaluate to
truefor the contract to hold
-
describer
public java.util.function.Function<T,java.lang.String> describer()
- Specified by:
describerin interfaceContractConditionType<T>- Returns:
- A function that returns a textual description of the predicate
-
withPredicate
public final ContractCondition<T> withPredicate(java.util.function.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(java.util.function.Function<T,java.lang.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(java.lang.Object another)
This instance is equal to all instances ofContractConditionthat have equal attribute values.- Overrides:
equalsin classjava.lang.Object- Returns:
trueifthisis equal toanotherinstance
-
hashCode
public int hashCode()
Computes a hash code from attributes:predicate,describer.- Overrides:
hashCodein classjava.lang.Object- Returns:
- hashCode value
-
toString
public java.lang.String toString()
Prints the immutable valueContractConditionwith attribute values.- Overrides:
toStringin classjava.lang.Object- Returns:
- A string representation of the value
-
of
public static <T> ContractCondition<T> of(java.util.function.Predicate<T> predicate, java.util.function.Function<T,java.lang.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
-
-