Record Class ContractSpec
- Record Components:
preconditions- gates checked before execution (a false one throws)postconditions- gates checked after execution; may useresultandold(expr)invariants- gates checked before and after executionvalidate- master switch;falsedisables all enforcement (treat as documentation)strict- whenfalse, postcondition failures are logged rather than thrown (pre/invariants always throw)message- optional override for the violation message
@Contract Design-by-Contract
annotation (TNS-552) — the JEXL precondition / postcondition / invariant
gates enforced around an action by ContractValidator.
This is the builder-path counterpart of @Contract: an action
registered via RoleBuilder.addAction(ActionConfig) (which has no
reflective method to carry the annotation) attaches its contract through
ActionConfig.contract(). ContractValidator operates on this
record for both paths — the annotation path goes through
from(Contract) — so there is a single enforcement codepath.
Lives in com.tnsai.metadata (not com.tnsai.actions.contracts)
because ActionConfig references it and actions.contracts already
depends on metadata (ActionContract → ActionMetadata);
placing it the other way would create a package cycle.
Distinct from ContractConfig, which models the older
@ActionSpec.precondition + GOAP-effects mechanism (singular
expressions + planning effects), not the @Contract DBC gates.
- Since:
- 0.12.0 (TNS-637 phase 4)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classFluent builder for the programmatic path. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ContractSpec.Builderbuilder()final booleanIndicates whether some other object is "equal to" this one.static ContractSpecAdapts a@Contractannotation into aContractSpec.final inthashCode()Returns a hash code value for this object.Returns the value of theinvariantsrecord component.booleanisEmpty()True when there are no gates to enforce.message()Returns the value of themessagerecord component.Returns the value of thepostconditionsrecord component.Returns the value of thepreconditionsrecord component.booleanstrict()Returns the value of thestrictrecord component.final StringtoString()Returns a string representation of this record class.booleanvalidate()Returns the value of thevalidaterecord component.
-
Field Details
-
NONE
No contract — empty gates. Default for actions without one.
-
-
Constructor Details
-
ContractSpec
public ContractSpec(List<String> preconditions, List<String> postconditions, List<String> invariants, boolean validate, boolean strict, String message) Creates an instance of aContractSpecrecord class.- Parameters:
preconditions- the value for thepreconditionsrecord componentpostconditions- the value for thepostconditionsrecord componentinvariants- the value for theinvariantsrecord componentvalidate- the value for thevalidaterecord componentstrict- the value for thestrictrecord componentmessage- the value for themessagerecord component
-
-
Method Details
-
from
Adapts a@Contractannotation into aContractSpec. Anullannotation (no@Contracton the method) maps toNONE. -
isEmpty
public boolean isEmpty()True when there are no gates to enforce. -
builder
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
preconditions
Returns the value of thepreconditionsrecord component.- Returns:
- the value of the
preconditionsrecord component
-
postconditions
Returns the value of thepostconditionsrecord component.- Returns:
- the value of the
postconditionsrecord component
-
invariants
Returns the value of theinvariantsrecord component.- Returns:
- the value of the
invariantsrecord component
-
validate
public boolean validate()Returns the value of thevalidaterecord component.- Returns:
- the value of the
validaterecord component
-
strict
public boolean strict()Returns the value of thestrictrecord component.- Returns:
- the value of the
strictrecord component
-
message
Returns the value of themessagerecord component.- Returns:
- the value of the
messagerecord component
-