org.primordion.xholon.base
Class Queue

java.lang.Object
  extended byorg.primordion.xholon.base.Xholon
      extended byorg.primordion.xholon.base.Queue
All Implemented Interfaces:
IQueue, IXholon
Direct Known Subclasses:
QueueStupidModel10, QueueStupidModel11, QueueStupidModel12, QueueStupidModel13, QueueStupidModel14, QueueStupidModel15, QueueStupidModel16, QueueStupidModel16nl, QueueStupidModel9

public class Queue
extends Xholon
implements IQueue

This is a generic Queue data structure that can be used to store references to any type of data. Items are added at one end of the Queue and taken off at the other end, which is why a Queue is called a First In First Out (FIFO) structure. WARNING: A Queue can fill up to maximum capacity, or it may become empty. Check the return value when calling the enqueue and dequeue functions to see if it is Q_FULL or null.

Since:
0.1 (Created on Jun 8, 2005)
Author:
Ken Webb

Field Summary
 
Fields inherited from class org.primordion.xholon.base.Xholon
DEFAULT_LEVEL, interaction, interactionsEnabled
 
Fields inherited from interface org.primordion.xholon.base.IQueue
Q_FULL, Q_OK
 
Fields inherited from interface org.primordion.xholon.base.IXholon
DEFAULT_SIZE_MSG_Q, NINCLUDE_PSC, NINCLUDE_PSx, NINCLUDE_PxC, NINCLUDE_Pxx, NINCLUDE_xSC, NINCLUDE_xSx, NINCLUDE_xxC, NINCLUDE_xxx
 
Constructor Summary
Queue(int numItems)
          Use this constructor.
 
Method Summary
 java.lang.Object dequeue()
          Take an object off the queue.
 int enqueue(java.lang.Object p_item)
          Add an object to the queue.
 java.util.Vector getItems()
          Get the internal item array.
 int getMaxSize()
          Get maximum number of items that can be in the queue.
 int getSize()
          Get number of items currently in the queue.
 void sendMessage(int signal, java.lang.Object data, IXholon sender)
          Send a ROOM/UML2 message to a receiving Xholon instance.
 void setMaxSize(int maxSize)
          Set the maximum number of items that can be in the queue, and allocate space for that many items.
 void shuffle()
          Randomize the order of the items in the queue.
 void sort()
          Sort the items in the queue.
 
Methods inherited from class org.primordion.xholon.base.Xholon
act, appendChild, appendChild, appendChild, cleanup, configure, configure, createStructure, decVal, decVal, depth, draw, getChildNodes, getFirstChild, getFirstSibling, getId, getLastChild, getLastSibling, getName, getNeighbors, getNextId, getNextSibling, getNthChild, getNthSibling, getNumChildren, getNumSiblings, getParentNode, getPort, getPreviousSibling, getRoleName, getRootNode, getSiblings, getSizeMessageQ, getUid, getVal_boolean, getVal_byte, getVal_char, getVal_double, getVal_float, getVal_int, getVal_long, getVal_Object, getVal_short, getVal_String, getVal, getXhc, getXhcId, getXhcName, getXhType, handleNodeSelection, hasAncestor, hasChildNodes, hasChildOrSiblingNodes, hasNextSibling, hasParentNode, height, incVal, incVal, initialize, initStatics, inOrderPrint, insertAfter, insertBefore, insertFirstChild, isActiveObject, isBound, isContainer, isExternal, isInternal, isLeaf, isPassiveObject, isRootNode, performActivity, performActivity, performBooleanActivity, performBooleanActivity, performDoubleActivity, performGuard, performVoidActivity, postAct, postConfigure, postOrderPrint, postReconfigure, preAct, preConfigure, preOrderPrint, preReconfigure, print, println, processMessageQ, processReceivedMessage, reconfigure, remove, removeChild, resetNextId, sendMessage, sendMessage, setAttributeVal, setFactory, setFirstChild, setId, setNextSibling, setParentChildLinks, setParentNode, setParentSiblingLinks, setPorts, setRoleName, setSizeMessageQ, setUid, setVal, setVal, setVal, setVal, setVal, setVal, setVal, setVal, setVal, setVal, setVariableValue, setXhc, swapNode, terminate, toString, treeSize, writeXml
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.primordion.xholon.base.IXholon
act, appendChild, appendChild, appendChild, cleanup, configure, configure, createStructure, decVal, decVal, depth, draw, getChildNodes, getFirstChild, getFirstSibling, getId, getLastChild, getLastSibling, getName, getNeighbors, getNextSibling, getNthChild, getNthSibling, getNumChildren, getNumSiblings, getParentNode, getPort, getPreviousSibling, getRoleName, getRootNode, getSiblings, getUid, getVal_boolean, getVal_byte, getVal_char, getVal_double, getVal_float, getVal_int, getVal_long, getVal_Object, getVal_short, getVal_String, getVal, getXhc, getXhcId, getXhcName, getXhType, handleNodeSelection, hasAncestor, hasChildNodes, hasChildOrSiblingNodes, hasNextSibling, hasParentNode, height, incVal, incVal, initialize, initStatics, inOrderPrint, insertAfter, insertBefore, insertFirstChild, isActiveObject, isBound, isContainer, isExternal, isInternal, isLeaf, isPassiveObject, isRootNode, performActivity, performActivity, performBooleanActivity, performBooleanActivity, performDoubleActivity, performGuard, performVoidActivity, postAct, postConfigure, postOrderPrint, postReconfigure, preAct, preConfigure, preOrderPrint, preReconfigure, print, println, processMessageQ, processReceivedMessage, reconfigure, remove, removeChild, sendMessage, sendMessage, setAttributeVal, setFirstChild, setId, setNextSibling, setParentChildLinks, setParentNode, setParentSiblingLinks, setPorts, setRoleName, setUid, setVal, setVal, setVal, setVal, setVal, setVal, setVal, setVal, setVal, setVal, setVariableValue, setXhc, swapNode, terminate, treeSize, writeXml
 

Constructor Detail

Queue

public Queue(int numItems)
Use this constructor.

Parameters:
numItems - Maximum number of items that can be in the queue.
Method Detail

enqueue

public int enqueue(java.lang.Object p_item)
Description copied from interface: IQueue
Add an object to the queue.

Specified by:
enqueue in interface IQueue
Parameters:
p_item - The object.
Returns:
Q_OK or Q_FULL

dequeue

public java.lang.Object dequeue()
Description copied from interface: IQueue
Take an object off the queue.

Specified by:
dequeue in interface IQueue
Returns:
An instance of Object, or null.

getSize

public int getSize()
Description copied from interface: IQueue
Get number of items currently in the queue.

Specified by:
getSize in interface IQueue
Returns:
Current queue size.

getMaxSize

public int getMaxSize()
Description copied from interface: IQueue
Get maximum number of items that can be in the queue.

Specified by:
getMaxSize in interface IQueue
Returns:
Maximum queue size.

setMaxSize

public void setMaxSize(int maxSize)
Description copied from interface: IQueue
Set the maximum number of items that can be in the queue, and allocate space for that many items. If there are already some items in the queue, then the method will atttempt to move all of them into the new internal data structure. If the new maxSize is less than the old maxSize, then some of the existing items may be lost.

Specified by:
setMaxSize in interface IQueue
Parameters:
maxSize - Maximum queue size.

shuffle

public void shuffle()
Description copied from interface: IQueue
Randomize the order of the items in the queue.

Specified by:
shuffle in interface IQueue

sort

public void sort()
Description copied from interface: IQueue
Sort the items in the queue. To use this capability, the Java class of the items in the queue must implement Comparable, with its "public int compareTo(Object o)" method.

Specified by:
sort in interface IQueue

sendMessage

public void sendMessage(int signal,
                        java.lang.Object data,
                        IXholon sender)
Description copied from interface: IXholon
Send a ROOM/UML2 message to a receiving Xholon instance.

Specified by:
sendMessage in interface IXholon
Overrides:
sendMessage in class Xholon

getItems

public java.util.Vector getItems()
Description copied from interface: IQueue
Get the internal item array. This should be used for debugging purposes only.

Specified by:
getItems in interface IQueue
Returns:
An array of Object items.