public final class TimeWindow extends Object implements Iterable
It is assumed that the timestamp passed to the add method is ascending. The window is backed by a collection reflecting the timestamp order rather then any sorted map or linked hash map for performance reasons.
Constructor and Description |
---|
TimeWindow(boolean isSupportRemoveStream)
Ctor.
|
Modifier and Type | Method and Description |
---|---|
void |
add(long timestamp,
EventBean bean)
Adds event to the time window for the specified timestamp.
|
void |
adjust(long delta)
Adjust expiry dates.
|
ArrayDeque<EventBean> |
expireEvents(long expireBefore)
Return and remove events in time-slots earlier (less) then the timestamp passed in,
returning the list of events expired.
|
Long |
getOldestTimestamp()
Returns the oldest timestamp in the collection if there is at least one entry,
else it returns null if the window is empty.
|
Map<EventBean,TimeWindowPair> |
getReverseIndex()
Returns the reverse index, for testing purposes.
|
ArrayDeque<TimeWindowPair> |
getWindow() |
boolean |
isEmpty()
Returns true if the window is currently empty.
|
Iterator<EventBean> |
iterator()
Returns event iterator.
|
void |
remove(EventBean theEvent)
Removes the event from the window, if remove stream handling is enabled.
|
void |
setReverseIndex(Map<EventBean,TimeWindowPair> reverseIndex) |
void |
setWindow(ArrayDeque<TimeWindowPair> window,
int size) |
void |
visitView(ViewDataVisitor viewDataVisitor,
DataWindowViewFactory viewFactory) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public TimeWindow(boolean isSupportRemoveStream)
isSupportRemoveStream
- true to indicate the time window should support effective removal of events
in the window based on the remove stream events received, or false to not accomodate removal at allpublic void adjust(long delta)
delta
- delta to adjust forpublic final void add(long timestamp, EventBean bean)
timestamp
- - the time slot for the eventbean
- - event to addpublic final void remove(EventBean theEvent)
theEvent
- to removepublic final ArrayDeque<EventBean> expireEvents(long expireBefore)
expireBefore
- is the timestamp from which on to keep events in the windowpublic final Long getOldestTimestamp()
public final boolean isEmpty()
public Map<EventBean,TimeWindowPair> getReverseIndex()
public ArrayDeque<TimeWindowPair> getWindow()
public void setWindow(ArrayDeque<TimeWindowPair> window, int size)
public void setReverseIndex(Map<EventBean,TimeWindowPair> reverseIndex)
public void visitView(ViewDataVisitor viewDataVisitor, DataWindowViewFactory viewFactory)