Package org.apache.groovy.contracts
Class ViolationTracker
java.lang.Object
org.apache.groovy.contracts.ViolationTracker
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
FieldsModifier and TypeFieldDescriptionstatic final ThreadLocal<ViolationTracker>Stores the tracker bound to the current thread while a contract is being evaluated. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voiddeinit()Removes the tracker associated with the current thread.first()Returns the earliest recorded violation.booleanIndicates whether this tracker currently contains any violations.static voidinit()Installs a fresh tracker for the current thread.last()Returns the most recently recorded violation.static voidRethrows the earliest recorded violation for the current thread.static voidRethrows the most recently recorded violation for the current thread.voidtrack(AssertionViolation assertionViolation) Records a newly observed assertion violation in encounter order.static booleanIndicates whether the current thread has recorded at least one violation.
-
Field Details
-
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:
trueif 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
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:
trueif at least one violation has been recorded
-
first
Returns the earliest recorded violation.- Returns:
- the first violation in encounter order
-
last
Returns the most recently recorded violation.- Returns:
- the last violation in encounter order
-