Class EventQueue

java.lang.Object
  extended by EventQueue

public class EventQueue
extends Object

EventQueue It's called an event "queue," but it's not really. Instead, it's a list (could be an array, could be a linked list) that always keeps its elements in time sorted order. When you get the nextEvent, you KNOW that it's the one with the lowest time in the EventQueue

Author:
Mark Guzdial, Barb Ericson

Constructor Summary
EventQueue()
          No argument constructor
 
Method Summary
 void add(SimEvent myEvent)
          Add the event.
 boolean empty()
          Check if the queue is empty
 void insertInOrder(SimEvent thisEvent)
          Add the new element into the linked list of elements, assuming that it's already in order.
 SimEvent peek()
          see the first element but don't remove it
 SimEvent pop()
          remove the top element from the queue and return it.
 int size()
          Return the number of elements in the queue
 void sort()
          Sort the events in the linked list using an insertion sort
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EventQueue

public EventQueue()
No argument constructor

Method Detail

add

public void add(SimEvent myEvent)
Add the event. The Queue MUST remain in order, from lowest time to highest.

Parameters:
myEvent - the event to add

peek

public SimEvent peek()
see the first element but don't remove it

Returns:
the first element in the queue

pop

public SimEvent pop()
remove the top element from the queue and return it.

Returns:
the top element

size

public int size()
Return the number of elements in the queue

Returns:
the number of elements in the queue

empty

public boolean empty()
Check if the queue is empty

Returns:
true if empty else false

insertInOrder

public void insertInOrder(SimEvent thisEvent)
Add the new element into the linked list of elements, assuming that it's already in order.

Parameters:
thisEvent - the one to add

sort

public void sort()
Sort the events in the linked list using an insertion sort