Package org.apache.groovy.contracts.domain

# Class Contract

java.lang.Object
org.apache.groovy.contracts.domain.Contract

public class Contract extends Object

Represents a contract between a supplier and a customer of a class.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Contract(ClassNode classNode)`
  Creates a contract model for the supplied class.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `ClassInvariant`
  `classInvariant()`
  Returns the current class invariant.
  `ClassNode`
  `classNode()`
  Returns the class represented by this contract.
  `boolean`
  `hasDefaultClassInvariant()`
  Indicates whether the contract still uses the shared default class invariant.
  `AssertionMap<Postcondition>`
  `postconditions()`
  Returns the postconditions indexed by method.
  `AssertionMap<Precondition>`
  `preconditions()`
  Returns the preconditions indexed by method.
  `void`
  `setClassInvariant(ClassInvariant classInvariant)`
  Replaces the class invariant associated with this contract.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### Contract

    public Contract(ClassNode classNode)
    Creates a contract model for the supplied class.
    Parameters:
      `classNode` - the class described by this contract

- ## Method Details

  - ### classNode

    public ClassNode classNode()
    Returns the class represented by this contract.
    Returns:
      the contracted class node

  - ### setClassInvariant

    public void setClassInvariant(ClassInvariant classInvariant)
    Replaces the class invariant associated with this contract.
    Parameters:
      `classInvariant` - the invariant to store

  - ### preconditions

    public AssertionMap<Precondition> preconditions()
    Returns the preconditions indexed by method.
    Returns:
      the precondition map

  - ### postconditions

    public AssertionMap<Postcondition> postconditions()
    Returns the postconditions indexed by method.
    Returns:
      the postcondition map

  - ### hasDefaultClassInvariant

    public boolean hasDefaultClassInvariant()
    Indicates whether the contract still uses the shared default class invariant.
    Returns:
      `true` if no custom class invariant has been set

  - ### classInvariant

    public ClassInvariant classInvariant()
    Returns the current class invariant.
    Returns:
      the configured class invariant