simulator
Class EventQueue

java.lang.Object
  |
  +--java.util.Dictionary
        |
        +--java.util.Hashtable
              |
              +--simulator.EventQueue
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map, java.io.Serializable

public class EventQueue
extends java.util.Hashtable

Module: simulator

Copyright: UMASS - MASL 1998

Version:
$Revision: 1.13 $
Author:
Bryan Horling (bhorling@cs.umass.edu)

Description: The event "queue" is actually a hashtable of vectors, where each vector in the table is a collection of the events which will terminate, or take effect, during that descrete time interval. A hashtable was used to store these objects to facilitate a (possibly) sparse and dynamic temporally ordered range of objects.

See Also:
Serialized Form

Inner classes inherited from class java.util.Map
java.util.Map.Entry
 
Method Summary
 void addEvent(Event e)
          Adds an event to the correct slot
 boolean delayEvent(Event e, int d)
          Delays the start execution time of an event.
 boolean extendEvent(Event e, int d)
          Extends the execution time of an event.
 java.util.Vector fetchTimeSlot(int slotNum)
          Fetches the time slot event vector, deleting from the table afterwards
 Event findEvent(long id)
          Finds an event in the queue by its id number.
 int findOldestTimeSlot()
          Finds the oldest time slot in the queue
 java.awt.Container getDisplay()
          Returns the display
static EventQueue getQueue()
          Returns the global event queue
 java.util.Vector getTimeSlot(int slotNum)
          Gets the time slot event vector
 boolean hasTimeSlot(int slotNum)
          Used to tell if a time slot exists or not.
 void init()
          Inits the queue
 boolean removeEvent(Event e)
          Removes an element from the table
 void removeTimeSlot(int slotNum)
          Removes a time slot
 void setDisplay(int slotNum)
          Sets the display for a particular time slot
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, remove, size, toString, values
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

getQueue

public static EventQueue getQueue()
Returns the global event queue
Returns:
The event queue

init

public void init()
Inits the queue
Returns:
The event queue

addEvent

public void addEvent(Event e)
Adds an event to the correct slot
Parameters:
e - The element to add

removeEvent

public boolean removeEvent(Event e)
Removes an element from the table
Parameters:
e - The element to remove
Returns:
true if the event was removed, false otherwise

findEvent

public Event findEvent(long id)
Finds an event in the queue by its id number. This may be obtained from any time during its execution.
Parameters:
id - The id number to search for
Returns:
The event, or null if none found

extendEvent

public boolean extendEvent(Event e,
                           int d)
Extends the execution time of an event. Note this does no time referene checking (so it will let you "extend" an event which has already completed, if it has not already been removed).
Parameters:
e - The element to remove
d - The time to extend it by
Returns:
true if the event was extended, false otherwise

delayEvent

public boolean delayEvent(Event e,
                          int d)
Delays the start execution time of an event. Note this does no time referene checking (so it will let you "delay" an event which has already started, which you probably don't want).
Parameters:
e - The element to remove
d - The time to extend it by
Returns:
true if the event was delayed, false otherwise

findOldestTimeSlot

public int findOldestTimeSlot()
Finds the oldest time slot in the queue
Returns:
The slot number of this slot

hasTimeSlot

public boolean hasTimeSlot(int slotNum)
Used to tell if a time slot exists or not. A non existant time slot has either already occurred or never had events added to it
Returns:
true if the time slot exists

getTimeSlot

public java.util.Vector getTimeSlot(int slotNum)
Gets the time slot event vector
Parameters:
slotNum - The slot to get
Returns:
The slot

fetchTimeSlot

public java.util.Vector fetchTimeSlot(int slotNum)
Fetches the time slot event vector, deleting from the table afterwards
Parameters:
slotNum - The slot to fetch
Returns:
The slot

removeTimeSlot

public void removeTimeSlot(int slotNum)
Removes a time slot
Parameters:
slotNum - The slot to remove

getDisplay

public java.awt.Container getDisplay()
Returns the display
Returns:
A panel

setDisplay

public void setDisplay(int slotNum)
Sets the display for a particular time slot
Returns:
A panel displaying the time slot