edu.rice.cs.plt.debug
Class EventSequence<T>

java.lang.Object
  extended by edu.rice.cs.plt.iter.AbstractIterable<T>
      extended by edu.rice.cs.plt.debug.EventSequence<T>
All Implemented Interfaces:
SizedIterable<T>, Iterable<T>

public class EventSequence<T>
extends AbstractIterable<T>
implements SizedIterable<T>

A sequence of "events" used to record and verify program behavior, especially when this behavior is effect-based. In typical usage, an instance is created as part of a stub which records events rather than performing normal actions. An "event" may be represented simply by a string, or by a more complex object. Given a stub, the driving code is then run, and afterwards the contents of the EventSequence is verified.

Concurrent access is supported.


Constructor Summary
EventSequence()
           
 
Method Summary
 void assertContents(Iterable<? extends T> expectedEvents)
          Assert that the given sequence of events, and only that sequence, was recorded (starting at the beginning).
 void assertContents(String message, Iterable<? extends T> expectedEvents)
          Assert that the given sequence of events, and only that sequence, was recorded (starting at the beginning).
 void assertContents(T... expectedEvents)
          Assert that the given sequence of events, and only that sequence, was recorded (starting at the beginning).
 void assertEmpty()
          Assert that the event sequence is empty.
 void assertEmpty(String message)
          Assert that the event sequence is empty.
 void assertOccurance(Iterable<? extends T> expectedEvents)
          Assert that each of the given events have been recorded.
 void assertOccurance(String message, Iterable<? extends T> expectedEvents)
          Assert that each of the given events have been recorded.
 void assertOccurance(T... expectedEvents)
          Assert that each of the given events have been recorded.
 void assertSequence(Iterable<? extends T> expectedEvents)
          Assert that the given sequence of events was recorded (starting at the beginning).
 void assertSequence(String message, Iterable<? extends T> expectedEvents)
          Assert that the given sequence of events was recorded (starting at the beginning).
 void assertSequence(T... expectedEvents)
          Assert that the given sequence of events was recorded (starting at the beginning).
 boolean hasFixedSize()
          true if this iterable is known to have a fixed size.
 boolean isEmpty()
          Whether the iterable does not contain any elements.
 boolean isInfinite()
          true if the iterable is known to have infinite size.
 boolean isStatic()
          true if this iterable is unchanging.
 Iterator<T> iterator()
           
 void record(Iterable<? extends T> events)
          Record a sequence of events.
 void record(T... events)
          Record a sequence of events.
 int size()
          Compute the number of elements in the iterable.
 int size(int bound)
          Compute the number of elements in the iterable, up to the given bound.
 
Methods inherited from class edu.rice.cs.plt.iter.AbstractIterable
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EventSequence

public EventSequence()
Method Detail

isEmpty

public boolean isEmpty()
Description copied from interface: SizedIterable
Whether the iterable does not contain any elements.

Specified by:
isEmpty in interface SizedIterable<T>

size

public int size()
Description copied from interface: SizedIterable
Compute the number of elements in the iterable. If the size is infinite or too large to be represented as an int, Integer.MAX_VALUE should be returned. Otherwise, next() may be safely invoked on the iterator exactly this number of times.

Specified by:
size in interface SizedIterable<T>

size

public int size(int bound)
Description copied from interface: SizedIterable
Compute the number of elements in the iterable, up to the given bound. If the size is infinite or greater than bound, bound is returned.

Specified by:
size in interface SizedIterable<T>
Parameters:
bound - Maximum result. Assumed to be nonnegative.

isInfinite

public boolean isInfinite()
Description copied from interface: SizedIterable
true if the iterable is known to have infinite size. If true, an iterator over the iterable in its current state will never return false from hasNext().

Specified by:
isInfinite in interface SizedIterable<T>

hasFixedSize

public boolean hasFixedSize()
Description copied from interface: SizedIterable
true if this iterable is known to have a fixed size. This is the case if the iterable is immutable, or if changes can only replace values, not remove or add them. An infinite iterable may be fixed if it is guaranteed to never become finite.

Specified by:
hasFixedSize in interface SizedIterable<T>

isStatic

public boolean isStatic()
Description copied from interface: SizedIterable
true if this iterable is unchanging. This implies that hasFixedSize() is true, and that iterator() will always return the same (either == or equal() and immutable) elements in the same order. ("Immutable" here means that equals() invocations are consistent over time -- if two objects are equal, they will never become inequal, and vice versa.)

Specified by:
isStatic in interface SizedIterable<T>

iterator

public Iterator<T> iterator()
Specified by:
iterator in interface Iterable<T>

record

public void record(T... events)
Record a sequence of events. The entire sequence is recorded atomically.


record

public void record(Iterable<? extends T> events)
Record a sequence of events. The entire sequence is recorded atomically.


assertEmpty

public void assertEmpty()
Assert that the event sequence is empty. If not, throw an AssertionError describing the first unexpected event.


assertEmpty

public void assertEmpty(String message)
Assert that the event sequence is empty. If not, throw an AssertionError with the given message.


assertOccurance

public void assertOccurance(T... expectedEvents)
Assert that each of the given events have been recorded. Remove all events that do appear. If any do not, throw an AssertionError describing the first missing event. All events are removed atomically.


assertOccurance

public void assertOccurance(Iterable<? extends T> expectedEvents)
Assert that each of the given events have been recorded. Remove all events that do appear. If any do not, throw an AssertionError describing the first missing event. All events are removed atomically.


assertOccurance

public void assertOccurance(String message,
                            Iterable<? extends T> expectedEvents)
Assert that each of the given events have been recorded. Remove all events that do appear. If any do not, throw an AssertionError with the given message. All events are removed atomically.


assertSequence

public void assertSequence(T... expectedEvents)
Assert that the given sequence of events was recorded (starting at the beginning). Remove the matching subsequence. If there is a mismatch, throw an AssertionError describing it. All events are removed atomically.


assertSequence

public void assertSequence(Iterable<? extends T> expectedEvents)
Assert that the given sequence of events was recorded (starting at the beginning). Remove the matching subsequence. If there is a mismatch, throw an AssertionError describing it. All events are removed atomically.


assertSequence

public void assertSequence(String message,
                           Iterable<? extends T> expectedEvents)
Assert that the given sequence of events was recorded (starting at the beginning). Remove the matching subsequence. If there is a mismatch, throw an AssertionError with the given message. All events are removed atomically.


assertContents

public void assertContents(T... expectedEvents)
Assert that the given sequence of events, and only that sequence, was recorded (starting at the beginning). Remove the matching subsequence. If there is a mismatch, throw an AssertionError describing it. All events are removed atomically.


assertContents

public void assertContents(Iterable<? extends T> expectedEvents)
Assert that the given sequence of events, and only that sequence, was recorded (starting at the beginning). Remove the matching subsequence. If there is a mismatch, throw an AssertionError describing it. All events are removed atomically.


assertContents

public void assertContents(String message,
                           Iterable<? extends T> expectedEvents)
Assert that the given sequence of events, and only that sequence, was recorded (starting at the beginning). Remove the matching subsequence. If there is a mismatch, throw an AssertionError with the given message. All events are removed atomically.