Package org.apache.groovy.contracts

# Class ViolationTracker

java.lang.Object
org.apache.groovy.contracts.ViolationTracker

public class ViolationTracker extends Object

A violation tracker is used to keep a list of pre-, post-condition or class-invariant violations in chronological order. This is necessary to evaluate all parts of a pre- or postcondition, and still being able to rethrow assertion errors.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final ThreadLocal<ViolationTracker>`
  `INSTANCE`
  Stores the tracker bound to the current thread while a contract is being evaluated.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ViolationTracker()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static void`
  `deinit()`
  Removes the tracker associated with the current thread.
  `AssertionViolation`
  `first()`
  Returns the earliest recorded violation.
  `boolean`
  `hasViolations()`
  Indicates whether this tracker currently contains any violations.
  `static void`
  `init()`
  Installs a fresh tracker for the current thread.
  `AssertionViolation`
  `last()`
  Returns the most recently recorded violation.
  `static void`
  `rethrowFirst()`
  Rethrows the earliest recorded violation for the current thread.
  `static void`
  `rethrowLast()`
  Rethrows the most recently recorded violation for the current thread.
  `void`
  `track(AssertionViolation assertionViolation)`
  Records a newly observed assertion violation in encounter order.
  `static boolean`
  `violationsOccurred()`
  Indicates whether the current thread has recorded at least one violation.

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

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

- ## Field Details

  - ### INSTANCE

    public static final ThreadLocal<ViolationTracker> INSTANCE
    Stores the tracker bound to the current thread while a contract is being evaluated.

- ## Constructor Details

  - ### ViolationTracker

    public ViolationTracker()

- ## Method Details

  - ### init

    public static void init()
    Installs a fresh tracker for the current thread.

  - ### deinit

    public static void deinit()
    Removes the tracker associated with the current thread.

  - ### violationsOccurred

    public static boolean violationsOccurred()
    Indicates whether the current thread has recorded at least one violation.
    Returns:
      `true` if a violation has been tracked for the current thread

  - ### rethrowFirst

    public static void rethrowFirst()
    Rethrows the earliest recorded violation for the current thread.

  - ### rethrowLast

    public static void rethrowLast()
    Rethrows the most recently recorded violation for the current thread.

  - ### track

    public void track(AssertionViolation assertionViolation)
    Records a newly observed assertion violation in encounter order.
    Parameters:
      `assertionViolation` - the violation to store

  - ### hasViolations

    public boolean hasViolations()
    Indicates whether this tracker currently contains any violations.
    Returns:
      `true` if at least one violation has been recorded

  - ### first

    public AssertionViolation first()
    Returns the earliest recorded violation.
    Returns:
      the first violation in encounter order

  - ### last

    public AssertionViolation last()
    Returns the most recently recorded violation.
    Returns:
      the last violation in encounter order