Package ons

Class EventScheduler

java.lang.Object
ons.EventScheduler

public class EventScheduler
extends java.lang.Object
The simulator's timeline is not defined by time itself, but by events. Therefore, if there are no events, there is nothing to simulate. The EventScheduler takes the given events and sorts them on a queue, based on their "time" attribute. When the simulation begins, the events are pulled out of the queue one by one.
  • Constructor Summary

    Constructors 
    Constructor Description
    EventScheduler()
    Creates a new eventQueue with the initial capacity of 100 elements and uses a new EventSort as the comparator for sorting.
  • Method Summary

    Modifier and Type Method Description
    boolean addEvent​(Event event)
    Adds a given event to the eventQueue.
    int numEvents()
    Retrieves the number of events in eventQueue.
    Event popEvent()
    Retrieves and removes the first event from the eventQueue.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • EventScheduler

      public EventScheduler()
      Creates a new eventQueue with the initial capacity of 100 elements and uses a new EventSort as the comparator for sorting.
  • Method Details

    • addEvent

      public boolean addEvent​(Event event)
      Adds a given event to the eventQueue.
      Parameters:
      event - will be added to the eventQueue
      Returns:
      boolean true if the eventQueue changed after calling this method; false if duplicates are not permitted and the event is already in the queue
    • popEvent

      public Event popEvent()
      Retrieves and removes the first event from the eventQueue.
      Returns:
      the first event of the queue, or null if it has no events
    • numEvents

      public int numEvents()
      Retrieves the number of events in eventQueue. If the there are more than Integer.MAX_VALUE events, returns Integer.MAX_VALUE.
      Returns:
      number of events in eventQueue