Package: org.apache.groovy.contracts

## [Java] Class ViolationTracker

- 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
    Modifiers | Name | Description
    --- | --- | ---
    `static ThreadLocal<ViolationTracker>` | `INSTANCE` | Stores the tracker bound to the current thread while a contract is being evaluated.

  - ### Methods Summary

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

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### public static final ThreadLocal<ViolationTracker> INSTANCE

      Stores the tracker bound to the current thread while a contract is being evaluated.

  - ### Method Detail

    - #### @GroovyABI(since = "4.0.0")
      public static void deinit()

      Removes the tracker associated with the current thread.

    - #### @GroovyABI(since = "4.0.0")
      public AssertionViolation first()

      Returns the earliest recorded violation.

      Returns:
        the first violation in encounter order

    - #### @GroovyABI(since = "4.0.0")
      public boolean hasViolations()

      Indicates whether this tracker currently contains any violations.

      Returns:
        `true` if at least one violation has been recorded

    - #### @GroovyABI(since = "4.0.0")
      public static void init()

      Installs a fresh tracker for the current thread.

    - #### @GroovyABI(since = "4.0.0")
      public AssertionViolation last()

      Returns the most recently recorded violation.

      Returns:
        the last violation in encounter order

    - #### @GroovyABI(since = "4.0.0")
      public static void rethrowFirst()

      Rethrows the earliest recorded violation for the current thread.

    - #### @GroovyABI(since = "4.0.0")
      public static void rethrowLast()

      Rethrows the most recently recorded violation for the current thread.

    - #### @GroovyABI(since = "4.0.0")
      public void track(AssertionViolation assertionViolation)

      Records a newly observed assertion violation in encounter order.

      Parameters:
        `assertionViolation` - the violation to store

    - #### @GroovyABI(since = "4.0.0")
      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