cz.zcu.fav.kiv.jsim
Class JSimLink

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

public class JSimLink
extends java.lang.Object

The JSimLink class is an equivalent of Simula's and C-Sim's LINK. It is supposed to encapsulate user data inserted into a queue (JSimHead). You can use the JSimLink class in two different ways:

  1. You can use it directly "as is" as a wrapper of your data. You just create a new JSimLink and give your data as a parameter to the constructor.
  2. You can subclass JSimLink and add new fields to the new class. In this case, you must ensure that the methods getData() and getDataType() return meaningful values. And you must create your own constructor, of course.

Since:
J-Sim version 0.1.0 (since J-Sim version 0.0.2 as JSimQueueItem)
Version:
J-Sim version 0.6.0
Author:
Jarda KAČER

Field Summary
private  java.lang.Object data
          The wrapped data.
protected  java.lang.String dataType
          The class name of the wrapped data.
private  double enterTime
          The simulation time that this link entered its current queue.
private static java.util.logging.Logger logger
          Common logger for all instances of this class.
private  JSimHead myQueue
          The queue that this link is currently inserted in.
private  JSimLink next
          Reference to the next link in the queue.
private  JSimLink previous
          Reference to the previous link in the queue.
 
Constructor Summary
JSimLink()
          Creates a new JSimLink object (a queue item) containing no data.
JSimLink(java.lang.Object object)
          Creates a new JSimLink object (a queue item) containing user data.
 
Method Summary
 void follow(JSimLink otherLink)
          Inserts the link into a queue after another link.
 java.lang.Object getData()
          Returns data wrapped by this link.
 java.lang.String getDataType()
          Returns the type of data wrapped by this link.
 double getEnterTime()
          Returns the simulation time when this link was inserted into its current queue.
 JSimLink getNext()
          Returns the next link in the queue.
 JSimLink getPrevious()
          Returns the previous link in the queue.
 JSimHead getQueue()
          Returns the queue that this link is currently inserted in.
 void into(JSimHead queue)
          Inserts the item into a queue.
 void out()
          Removes the link from its queue.
 void precede(JSimLink otherLink)
          Inserts the item into a queue before another item.
protected  void setNext(JSimLink nextLink)
          Sets the next item in the queue.
protected  void setPrevious(JSimLink previousLink)
          Sets the previous link in the queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static final java.util.logging.Logger logger
Common logger for all instances of this class. By default, all logging information goes to a file. Only severe events go to the console, in addition to a file.


myQueue

private JSimHead myQueue
The queue that this link is currently inserted in.


data

private final java.lang.Object data
The wrapped data. If you subclass JSimLink and use the constructor without parameters, this field will always be null! You will have to overwrite the getData() method if you don't plan to use it in a special way.


dataType

protected final java.lang.String dataType
The class name of the wrapped data. If you subclass JSimLink and use the constructor without parameters, this field will not have a meaningful value. You will have to overwrite the getDataType() method.


enterTime

private double enterTime
The simulation time that this link entered its current queue.


next

private JSimLink next
Reference to the next link in the queue. For performance purposes, J-Sim uses real bidirectional list, as you know it from C. Using container classes (such as ArrayList or LinkedList) leads to complexity O(n) of getNext(), getPrevious(), follow(), and precede(), which is unacceptable. This implementation ensures complexity O(1) of all operations.


previous

private JSimLink previous
Reference to the previous link in the queue. For performance purposes, J-Sim uses real bidirectional list, as you know it from C. Using container classes (such as ArrayList or LinkedList) leads to complexity O(n) of getNext(), getPrevious(), follow(), and precede(), which is unacceptable. This implementation ensures complexity O(1) of all operations.

Constructor Detail

JSimLink

public JSimLink(java.lang.Object object)
Creates a new JSimLink object (a queue item) containing user data. When this constructor version is used, JSimLink acts as a "wrapper" of your data.

Parameters:
object - The data that the queue item will contain.

JSimLink

public JSimLink()
Creates a new JSimLink object (a queue item) containing no data. Use this constructor in a subclass of JSimLink where you will supply your own data and methods.

Method Detail

into

public final void into(JSimHead queue)
                throws JSimSecurityException
Inserts the item into a queue. The link must not be inserted in any queue.

Parameters:
queue - The queue the item is to be inserted to.
Throws:
JSimSecurityException - This exception is thrown out when the item is already inserted in a queue.

follow

public final void follow(JSimLink otherLink)
                  throws JSimSecurityException
Inserts the link into a queue after another link. The link being inserted must not be in a queue while the other one must be inserted in a queue.

Parameters:
otherLink - The link that will be followed by this link.
Throws:
JSimSecurityException - This exception is thrown out if the link is already inserted in a queue or the other link is null or not inserted in any queue.

precede

public final void precede(JSimLink otherLink)
                   throws JSimSecurityException
Inserts the item into a queue before another item. The link being inserted must not be in a queue while the other one must be inserted in a queue.

Parameters:
otherLink - The link that will be preceded by this item.
Throws:
JSimSecurityException - This exception is thrown out if the link is already inserted in a queue or the other link is null or not inserted in any queue.

out

public final void out()
               throws JSimSecurityException
Removes the link from its queue. The link must be inserted in a queue.

Throws:
JSimSecurityException - This exception is thrown out if the link is not inserted in a queue.

getQueue

public final JSimHead getQueue()
Returns the queue that this link is currently inserted in.

Returns:
The queue this link is inserted in, null if it is not inserted in any queue.

getEnterTime

public final double getEnterTime()
Returns the simulation time when this link was inserted into its current queue.

Returns:
The simulation time when this link was inserted into its current queue.

getData

public java.lang.Object getData()
Returns data wrapped by this link. The data is immutable. Remember that you are responsible for proper redefinition of this method if you subclass JSimLink!

Returns:
The data wrapped by this link.

getDataType

public java.lang.String getDataType()
Returns the type of data wrapped by this link. Since the data itself is immutable, so is the data type. Remember that you are responsible for proper redefinition of this method if you subclass JSimLink!

Returns:
The type of data wrapped by this link.

getNext

public final JSimLink getNext()
                       throws JSimSecurityException
Returns the next link in the queue. This link must be inserted in a queue.

Returns:
The next link in the queue.
Throws:
JSimSecurityException - This exception is thrown out if the link is not inserted in a queue.

getPrevious

public final JSimLink getPrevious()
                           throws JSimSecurityException
Returns the previous link in the queue. This link must be inserted in a queue.

Returns:
The previous link in the queue.
Throws:
JSimSecurityException - This exception is thrown out if the link is not inserted in a queue.

setNext

protected final void setNext(JSimLink nextLink)
Sets the next item in the queue. This method is called by other links. You should never use this method.

Parameters:
nextLink - The link that will follow this one.

setPrevious

protected final void setPrevious(JSimLink previousLink)
Sets the previous link in the queue. This method is called by other links. You should never use this method.

Parameters:
previousLink - The link that will precede this one.


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