cz.zcu.fav.kiv.jsim
Class JSimCalendar

java.lang.Object
  extended by cz.zcu.fav.kiv.jsim.JSimCalendar

public class JSimCalendar
extends java.lang.Object

The JSimCalendar class holds information about all scheduled events within a J-Sim simulation. It contains a list of JSimCalendarEvent elements, ordered by their simulation time. J-Sim simulations use this class to schedule processes and to get information about a process which should be run during the next simulation step. You should never need to create an instance of this class.

Since:
J-Sim version 0.0.1
Version:
J-Sim version 0.6.0
Author:
Jarda KAČER

Field Summary
private  java.util.LinkedList<JSimCalendarEvent> eventList
          This list holds all events of the calendar.
static double NEVER
          Constant signalling that there is no process scheduled.
static JSimProcess NOBODY
          Constant signalling that there is no process scheduled.
 
Constructor Summary
JSimCalendar()
          Creates a new empty calendar.
 
Method Summary
 void addEntry(double absTime, JSimProcess process)
          Adds a new event with the specified time and the specified process to the calendar.
 void addWholeEvent(JSimCalendarEvent calendarEvent)
          Adds the specified event to the calendar.
 int deleteEntries(JSimProcess process, boolean all)
          Deletes one or all events of a process from the calendar.
 JSimProcess getFirstProcess()
          Returns the first scheduled process.
 double getFirstProcessTime()
          Returns the time of the event being at the head of the calendar.
 boolean isEmpty()
          Says whether the calendar is empty.
 void jump()
          Deletes the event at the head of the calendar and sets the head to the event which follows the current head.
 java.lang.String toString()
          Returns a string representation of the calendar.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NOBODY

public static final JSimProcess NOBODY
Constant signalling that there is no process scheduled.


NEVER

public static final double NEVER
Constant signalling that there is no process scheduled.

See Also:
Constant Field Values

eventList

private java.util.LinkedList<JSimCalendarEvent> eventList
This list holds all events of the calendar. Events are always kept ordered, because the list is sorted after every insertion.

Constructor Detail

JSimCalendar

public JSimCalendar()
Creates a new empty calendar.

Method Detail

addEntry

public void addEntry(double absTime,
                     JSimProcess process)
              throws JSimInvalidParametersException
Adds a new event with the specified time and the specified process to the calendar.

Parameters:
absTime - The absolute simulation time of the event.
process - The process to be later activated.
Throws:
JSimInvalidParametersException - This exception is thrown out if the absolute simulation time is negative or the process is not specified (null).

addWholeEvent

public void addWholeEvent(JSimCalendarEvent calendarEvent)
                   throws JSimInvalidParametersException
Adds the specified event to the calendar. This is useful when you already have an event (from outside) and want to add it to the calendar.

Parameters:
calendarEvent - The event to be added to the calendar.
Throws:
JSimInvalidParametersException - This exception is thrown out if the absolute simulation time is negative or the process is not specified (null).

deleteEntries

public int deleteEntries(JSimProcess process,
                         boolean all)
                  throws JSimInvalidParametersException
Deletes one or all events of a process from the calendar. The rest of J-Sim assures that a process will not have more than one event in the calendar so the second atribute is more or less useless.

Parameters:
process - The process whose event(s) are to be deleted.
all - A flag saying that not only one but all events of the given process should be deleted.
Returns:
The number of events deleted.
Throws:
JSimInvalidParametersException - This exception is thrown out if the process is not specified (null).

getFirstProcess

public JSimProcess getFirstProcess()
Returns the first scheduled process. Its calendar event is at the head of the event list because it is always sorted.

Returns:
The first scheduled process or NOBODY if the calendar is empty.

getFirstProcessTime

public double getFirstProcessTime()
Returns the time of the event being at the head of the calendar.

Returns:
The time of the event being at the head of the calendar or NEVER if the calendar is empty.

jump

public void jump()
Deletes the event at the head of the calendar and sets the head to the event which follows the current head.


isEmpty

public boolean isEmpty()
Says whether the calendar is empty. The calendar is empty if it contains no events.

Returns:
True if it is empty, false otherwise.

toString

public java.lang.String toString()
Returns a string representation of the calendar.

Overrides:
toString in class java.lang.Object
Returns:
A string representation of the calendar.


Copyright © 2000-2006 University of West Bohemia. Licensed under the Academic Free License v. 2.1. Build date 20060812.