public class OrderedTreeSetCalendar extends Calendar
TreeSet
to keep the events in order.
Each time an event is posted, an associated Entry object is created. Entry objects are comarable by time, priority and ID. The ID is an artificial attribute which discriminates two entries with the same time and priority. This
The data structure used in this class requires only two objects to be created
for each event that is placed in the calendar (TreeSetCalendar.Entry
and TreeMap.Entry
). SimpleOrderedCalendar
, for comparison,
requires two additional objects (LinkedList
and
LinkedList.Entry
).
The complexity of the
postEvent(CalendarCallback, CalendarCallback, PointInTime, int)
and
EventToken.cancel()
methods is log(n), where n is the number of
events in the calendar.
CALENDAR, concurrentEvents, eventsWithSameTimeStat, systemTime
Constructor and Description |
---|
OrderedTreeSetCalendar() |
Modifier and Type | Method and Description |
---|---|
void |
cancelAllEvents()
Cancel all events which are currently posted.
|
boolean |
isEventAvailable()
Return true if there are events in the calendar.
|
PointInTime |
peekNextEventTime()
Returns the time stamp of the next event in the calendar without removing
it.
|
EventToken |
postEvent(CalendarCallback process,
CalendarCallback cancel,
PointInTime eventTime,
int eventPriority)
Creates a new entry in the calendar.
|
void |
processNextEvent()
Gets the next event on the schedule and calls its onExecute method.
|
getInstance, getSystemTime, hasInstance, postEvent, setInstance, setSameTimeEventStatistic
public EventToken postEvent(CalendarCallback process, CalendarCallback cancel, PointInTime eventTime, int eventPriority)
Calendar
postEvent
in class Calendar
process
- Function to call when the event is processed. May be null.cancel
- Function to call when the event is cancelled. May be null.eventTime
- Time at which to call the onExecute
function. Must
be later or equal than the current system time returned by
Calendar.getSystemTime()
.eventPriority
- Key used for sorting to break ties for two entries with the same
eventTime
.public void cancelAllEvents()
Calendar
cancelAllEvents
in class Calendar
public boolean isEventAvailable()
Calendar
isEventAvailable
in class Calendar
public PointInTime peekNextEventTime()
Calendar
peekNextEventTime
in class Calendar
public void processNextEvent()
Calendar
processNextEvent
in class Calendar