org.axonframework.domain
Class SimpleDomainEventStream

java.lang.Object
  extended by org.axonframework.domain.SimpleDomainEventStream
All Implemented Interfaces:
DomainEventStream

public class SimpleDomainEventStream
extends Object
implements DomainEventStream

Creates a DomainEventStream that streams the contents of a list.

Since:
0.1
Author:
Allard Buijze

Constructor Summary
SimpleDomainEventStream(Collection<? extends DomainEventMessage> events)
          Initialize the event stream using the given List of DomainEvent and aggregate identifier.
SimpleDomainEventStream(DomainEventMessage... events)
          Initialize the event stream using the given DomainEventMessages and aggregate identifier.
 
Method Summary
static DomainEventStream emptyStream()
          Creates an empty stream.
 boolean hasNext()
          Returns true if the stream has more events, meaning that a call to next() will not result in an exception.
 DomainEventMessage next()
          Returns the next events in the stream, if available.
 DomainEventMessage peek()
          Returns the next events in the stream, if available, without moving the pointer forward.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleDomainEventStream

public SimpleDomainEventStream(Collection<? extends DomainEventMessage> events)
Initialize the event stream using the given List of DomainEvent and aggregate identifier.

Parameters:
events - the list of domain events to stream
Throws:
IllegalArgumentException - if the given list is empty

SimpleDomainEventStream

public SimpleDomainEventStream(DomainEventMessage... events)
Initialize the event stream using the given DomainEventMessages and aggregate identifier. The aggregate identifier is initialized by reading it from the first event available. Therefore, you must provide at least one event.

Parameters:
events - the list of domain events to stream
Throws:
IllegalArgumentException - if no events are supplied
Method Detail

hasNext

public boolean hasNext()
Returns true if the stream has more events, meaning that a call to next() will not result in an exception. If a call to this method returns false, there is no guarantee about the result of a consecutive call to next()

Specified by:
hasNext in interface DomainEventStream
Returns:
true if the stream contains more events.

next

public DomainEventMessage next()
Returns the next events in the stream, if available. Use hasNext() to obtain a guarantee about the availability of any next event. Each call to next() will forward the pointer to the next event in the stream.

If the pointer has reached the end of the stream, the behavior of this method is undefined. It could either return null, or throw an exception, depending on the actual implementation. Use DomainEventStream.hasNext() to confirm the existence of elements after the current pointer.

Specified by:
next in interface DomainEventStream
Returns:
the next event in the stream.
Throws:
NoSuchElementException - when no items exist after the current pointer in the stream

peek

public DomainEventMessage peek()
Returns the next events in the stream, if available, without moving the pointer forward. Hence, a call to DomainEventStream.next() will return the same event as a call to peek(). Use hasNext() to obtain a guarantee about the availability of any next event.

If the pointer has reached the end of the stream, the behavior of this method is undefined. It could either return null, or throw an exception, depending on the actual implementation. Use DomainEventStream.hasNext() to confirm the existence of elements after the current pointer.

Specified by:
peek in interface DomainEventStream
Returns:
the next event in the stream.
Throws:
NoSuchElementException - when no items exist after the current pointer in the stream

emptyStream

public static DomainEventStream emptyStream()
Creates an empty stream. For performance reasons, this method always returns the same instance.

Returns:
en empty DomainEventStream


Copyright © 2010-2016. All Rights Reserved.