Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

desmoj
Class EventVector  view EventVector download EventVector.java

java.lang.Object
  extended bydesmoj.EventList
      extended bydesmoj.EventVector

public class EventVector
extends EventList

Implementation of the interface EventList using a java.util.Vector as a container for the EventNotes. Using Vector as a container has the advantage of using tested and thread-safe code. Being based on an array it allows inserting new entries faster using binary search for the right position, which would not be possible on containers based on linked lists. The obvious disadvantage is the slow speed of execution of the thread-safe code of the Vector.

Version:
DESMO-J, Ver. 1.5 copyright (c) 2001 licensed under GNU GPL

Field Summary
private  java.util.Vector eVector
          The vector container used to store the EventNotes.
 
Constructor Summary
(package private) EventVector()
          Constructs an empty event-list with a default size of 100 for the underlying vector.
 
Method Summary
(package private)  EventNote createEventNote(Entity who, Event what, SimTime when)
          Creates a new eventnote with the initial values given as parameters.
(package private)  EventNote firstNote()
          Returns the first eventnote in the event-list.
(package private)  void insert(EventNote newNote)
          Inserts the new eventnote preserving the temporal order of the eventnotes contained in the event-list.
(package private)  void insertAfter(EventNote where, EventNote newNote)
          Inserts a new eventnote after another eventnote specified.
(package private)  void insertAsFirst(EventNote newNote)
          Inserts the given eventnote at the first position in the event-list.
(package private)  void insertAsLast(EventNote newNote)
          Inserts an eventnote at the last position in the event-list.
(package private)  void insertBefore(EventNote where, EventNote newNote)
          Inserts a new eventnote before another eventnote specified.
(package private)  boolean isEmpty()
          Tests if there are any scheduled events contained in the event-list.
(package private)  EventNote lastNote()
          Returns the last eventnote in the event-list.
(package private)  EventNote nextNote(EventNote origin)
          Returns the next eventnote in the event-list relative to the given eventnote.
(package private)  EventNote prevNote(EventNote origin)
          Returns the previous eventnote in the event-list relative to the given eventnote.
(package private)  void remove(EventNote note)
          Removes the given eventnote from the event-list.
(package private)  void removeFirst()
          Removes the first eventnote from the event-list.
 java.lang.String toString()
          Returns a string representing the entries of this vector in a row.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

eVector

private java.util.Vector eVector
The vector container used to store the EventNotes.

Constructor Detail

EventVector

EventVector()
Constructs an empty event-list with a default size of 100 for the underlying vector. The standard initial size of a vector is 10, requiring the size to be doubled when element nnumber 11 is added. This duplication of the allovated memory takes some time. To reduce the amount of duplications necessary, the vector is created with an initial size of 100 to improve performance by avoiding 4 cycles of doubling Vector's capacity. Choosing a larger initial number would not significantly fasten processing speeds but waste otherwise unused memory, depending on the behaviour of the model simulated.

Method Detail

createEventNote

EventNote createEventNote(Entity who,
                          Event what,
                          SimTime when)
Creates a new eventnote with the initial values given as parameters. This resembles the factory method design pattern described in [Gamm95] p. 107. This design pattern is used to ensure that always the appropriate implementation of eventnotes is used together with an individual implementation of an event-list. EventVector does not need any special implementation of eventnotes and thus simply passes the construction through to the default implementation of eventnote.

Specified by:
createEventNote in class EventList

firstNote

EventNote firstNote()
Returns the first eventnote in the event-list. It is the eventnote with the lowest (nearest) associated point of simulation time of all eventnotes contained in the evnet-list. Note that the eventnote is not removed from the event-list.

Specified by:
firstNote in class EventList

insert

void insert(EventNote newNote)
Inserts the new eventnote preserving the temporal order of the eventnotes contained in the event-list. It uses binary search to determine the position where to insert the new eventnote to increase performance.

Specified by:
insert in class EventList

insertAfter

void insertAfter(EventNote where,
                 EventNote newNote)
Inserts a new eventnote after another eventnote specified. Note that to keep the temporal order of the event-list, the scheduled time will be set to the same time as the referred "afterNote". Note also, that afterNote must be contained in the event-list. If the referred "where" is not contained in the event-list, there is no chance to determine the time that the new note is intended to be scheduled at. Thus the new eventnote will not be inserted and a EventNotScheduledException will be thrown, stopping the simulation.

Specified by:
insertAfter in class EventList

insertAsFirst

void insertAsFirst(EventNote newNote)
Inserts the given eventnote at the first position in the event-list. The event encapsulated in that eventnote will probably be the next event to be processed by the scheduler (unless some other calls to this method are made before). Note that the time of the new eventnote is set to the actual simulation time.

Specified by:
insertAsFirst in class EventList

insertAsLast

void insertAsLast(EventNote newNote)
Inserts an eventnote at the last position in the event-list. Also adapts the new eventnote's scheduled point of time to the same time as the last elment in the event-list. Time is not changed, if the event-list is empty.

Specified by:
insertAsLast in class EventList

insertBefore

void insertBefore(EventNote where,
                  EventNote newNote)
Inserts a new eventnote before another eventnote specified. Note that this could disturb the temporal order of the event-list. So this method should only be used carefully. Note also, that eventnote 'where' must be contained in the event-list or otherwise an exception will be thrown.

Specified by:
insertBefore in class EventList

isEmpty

boolean isEmpty()
Tests if there are any scheduled events contained in the event-list. If the event-list happens to be empty during the run of a simulation, this is a criterium to stop the simulation, since no further action is scheduled.

Specified by:
isEmpty in class EventList

lastNote

EventNote lastNote()
Returns the last eventnote in the event-list. If the event-list is empty, null will be returned.

Specified by:
lastNote in class EventList

nextNote

EventNote nextNote(EventNote origin)
Returns the next eventnote in the event-list relative to the given eventnote. If the given eventnote is not contained in the event-list or happens to be the last eventnote in the event-list, null will be returned.

Specified by:
nextNote in class EventList

prevNote

EventNote prevNote(EventNote origin)
Returns the previous eventnote in the event-list relative to the given eventnote. If the given eventnote is not contained in the event-list or happens to be the first eventnote in the event-list, null will be returned.

Specified by:
prevNote in class EventList

remove

void remove(EventNote note)
Removes the given eventnote from the event-list.

Specified by:
remove in class EventList

removeFirst

void removeFirst()
Removes the first eventnote from the event-list. Does nothing if the event-list is already empty.

Specified by:
removeFirst in class EventList

toString

public java.lang.String toString()
Returns a string representing the entries of this vector in a row. The resulting string includes all eventnotes in ascending order as they are placed inside the event vector.