jasi.sim.basic.event
Class Calendar

java.lang.Object
  extended by jasi.sim.basic.event.Calendar
All Implemented Interfaces:
java.io.Serializable

public final class Calendar
extends java.lang.Object
implements java.io.Serializable

The event calendar. The calendar provides guaranteed log(n) time cost for the basic operations (push, pop, contains and remove). Algorithms are adaptations of those in Cormen, Leiserson, and Rivest's Introduction to Algorithms.

See Also:
Serialized Form

Constructor Summary
Calendar()
          Constructor of calendar, where the current start time of this calendar will be zero.
Calendar(Time time)
          Constructor of a calendar.
 
Method Summary
 void addCalendarListener(CalendarListener listener)
          Add an listener for state changes of this calendar.
 void clear()
          Remove all events from this calendar.
 boolean contains(Event event)
          Check, if this calendar contains a certain event.
 void deleteEventsEarlierThan(Time time)
          Delete all events with an time earlier than a given time.
 Event find(Id id)
          Find an event by its id in the calendar.
 Time getCurrentTime()
          Get the current time of this calendar, that is given by the event time of the last event, which had been removed (popped) from this calendar.
 java.util.Collection<Event> getEventSet()
          Retrieve an unmodifiable collection of all events in this calendar.
 void importEvent(Event event)
          Add or push an event unchecked to this calendar.
 boolean isEmpty()
          Check, if this calendar has no events.
 Event pop()
          Pop the next event waiting from this calendar.
 void push(Event event)
          Add or push an event to this calendar.
 Time readNextEventTime()
          Get the event time of next event in this calendar.
 boolean remove(Event event)
          Remove an event from this calendar.
 void removeCalendarListener(CalendarListener listener)
          Remove an listener for state changes of this calendar.
 void setCurrentTime(Time time)
          Set, i.e. increase, the time of this calendar.
 int size()
          Get number of events in this calendar.
 java.lang.String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Calendar

public Calendar(Time time)
Constructor of a calendar.

Parameters:
time - The current start time of this calendar.

Calendar

public Calendar()
Constructor of calendar, where the current start time of this calendar will be zero.

Method Detail

importEvent

public void importEvent(Event event)
Add or push an event unchecked to this calendar.

Parameters:
event - The event to be pushed.
Throws:
EventAlreadyPushedException - The event has already been pushed to an calendar.

push

public void push(Event event)
          throws EventToEarlyException,
                 EventAlreadyPushedException
Add or push an event to this calendar.

Parameters:
event - The event to be pushed.
Throws:
EventToEarlyException - The event's time is smaller (earlier) than the current time.
EventAlreadyPushedException - The event has already been pushed to an calendar.

pop

public Event pop()
          throws EmptyCalendarException,
                 EventAlreadyPoppedException,
                 EventNotPushedException
Pop the next event waiting from this calendar. The popped event will be executed by its event listeners.

Returns:
The next event.
Throws:
EmptyCalendarException - No events in calendar.
EventAlreadyPoppedException - This event has already been popped from a calendar.
EventNotPushedException - This event has not been pushed to a calendar.

find

public Event find(Id id)
Find an event by its id in the calendar.

Parameters:
id - The event's id.
Returns:
The found event or null;

remove

public boolean remove(Event event)
Remove an event from this calendar.

Parameters:
event - The event.
Returns:
True, if the element was removed.

clear

public void clear()
Remove all events from this calendar.


contains

public boolean contains(Event event)
Check, if this calendar contains a certain event.

Parameters:
event - That event
Returns:
True if this collection contains that event.

isEmpty

public boolean isEmpty()
Check, if this calendar has no events.

Returns:
True if this collection contains no events.

size

public int size()
Get number of events in this calendar.

Returns:
The number of events.

readNextEventTime

public Time readNextEventTime()
Get the event time of next event in this calendar.

Returns:
The current time or never, if no events are currently in this calendar.

deleteEventsEarlierThan

public void deleteEventsEarlierThan(Time time)
Delete all events with an time earlier than a given time.

Parameters:
time - The given reference time.

toString

public java.lang.String toString()
Returns a string representation of this object.

Overrides:
toString in class java.lang.Object
Returns:
The string.

getCurrentTime

public Time getCurrentTime()
Get the current time of this calendar, that is given by the event time of the last event, which had been removed (popped) from this calendar.

Returns:
The current time.

setCurrentTime

public void setCurrentTime(Time time)
Set, i.e. increase, the time of this calendar. It is garanteed that the requested time is never greater than the time of this calendar's next event.

Parameters:
time - The requested time.

getEventSet

public java.util.Collection<Event> getEventSet()
Retrieve an unmodifiable collection of all events in this calendar.

Returns:
The collection of events in the calendar.

addCalendarListener

public void addCalendarListener(CalendarListener listener)
Add an listener for state changes of this calendar.

Parameters:
listener - The listener.

removeCalendarListener

public void removeCalendarListener(CalendarListener listener)
Remove an listener for state changes of this calendar.

Parameters:
listener - The listener.