gnu.iou
Class queue

java.lang.Object
  |
  +--gnu.iou.queue
All Implemented Interfaces:
java.lang.Cloneable, java.util.Enumeration

public class queue
extends java.lang.Object
implements java.util.Enumeration, java.lang.Cloneable

A linked- list queue (or stack).

Author:
John Pritchard (john@syntelos.org)

Inner Class Summary
static class queue.Enqueued
          List node can be subclassed, eg, for a soft queue.
 
Field Summary
static java.lang.Class DefaultEnqueuedClass
           
protected  java.lang.Class q_t
          Queue type set by `this()' constructor and replaceable by subclasses' constructors.
 
Constructor Summary
queue()
          Create a new FIFO queue (not LIFO stack).
queue(boolean use_stack)
           
 
Method Summary
 void clear()
           
 queue cloneQueue()
           
 boolean contains(java.lang.Object obj)
           
 queue copy()
          Clone without depth of queue -- with only the top element of the queue/ stack.
 java.util.Enumeration elements()
           
 boolean equals(java.lang.Object ano)
           
 boolean hasMoreElements()
          Returns true if the enumeration contains more elements; false if its empty.
 boolean isEmpty(java.lang.Object usr)
           
 boolean isNotEmpty(java.lang.Object usr)
           
 lck locker()
           
 java.lang.Object nextElement()
          Returns the next element of the enumeration.
 java.lang.Object peek(java.lang.Object usr)
          Look at the next "pop" element without popping it (removing it) from the queue/stack.
 java.lang.Object pop(java.lang.Object usr)
          Return and remove the next element from the queue or stack.
 java.lang.String popall_String(java.lang.Object usr)
          Pop all elements into a string.
 java.lang.String popall_String(java.lang.Object usr, char sep)
          Pop all elements into a string.
 void push(java.lang.Object usr, java.lang.Object o)
          User interface for stack or queue "push", depending on constructor.
 void push(java.lang.Object usr, java.lang.Object o, boolean use_stack_fifo)
          User interface for stack or queue, depending on constructor, with override option for FIFO or LIFO behavior in stack or queue.
 java.lang.Object remove(java.lang.Object usr, java.lang.Object obj)
           
 boolean size_gt_1()
          Size greater than one.
 int size(java.lang.Object usr)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DefaultEnqueuedClass

public static final java.lang.Class DefaultEnqueuedClass

q_t

protected java.lang.Class q_t
Queue type set by `this()' constructor and replaceable by subclasses' constructors.
Constructor Detail

queue

public queue()
Create a new FIFO queue (not LIFO stack).

queue

public queue(boolean use_stack)
Parameters:
use_stack - If true, this is a stack (LIFO), otherwise it's a queue (FIFO).
Method Detail

locker

public lck locker()

clear

public void clear()

contains

public boolean contains(java.lang.Object obj)

push

public void push(java.lang.Object usr,
                 java.lang.Object o)
User interface for stack or queue "push", depending on constructor.
Parameters:
usr - The queue user is the object with a field for the queue. For `lck.LckDesc'. For example, locks used by the `Context' or its fields use the `Context' (instance) object for their `usr'.
o - Object for queue/stack
See Also:
lck.LckDesc(java.lang.Object, java.lang.String)

push

public void push(java.lang.Object usr,
                 java.lang.Object o,
                 boolean use_stack_fifo)
User interface for stack or queue, depending on constructor, with override option for FIFO or LIFO behavior in stack or queue.

This interface should be used only when needing to change the behavior of the stack or queue, for exampe using an enumeration or queue with a "pushback" of the last popped element. Otherwise use the regular `push(Object)' method.

Parameters:
usr - The queue user is the object with a field for the queue. For `lck.LckDesc'. For example, locks used by the `Context' or its fields use the `Context' (instance) object for their `usr'.
o - Object to push
use_stack_fifo - If true uses stack behavior (FIFO), otherwise false uses queue behavior (LIFO).
See Also:
lck.LckDesc(java.lang.Object, java.lang.String)

peek

public java.lang.Object peek(java.lang.Object usr)
Look at the next "pop" element without popping it (removing it) from the queue/stack.
Parameters:
usr - The queue user is the object with a field for the queue. For `lck.LckDesc'. For example, locks used by the `Context' or its fields use the `Context' (instance) object for their `usr'.
See Also:
lck.LckDesc(java.lang.Object, java.lang.String)

pop

public java.lang.Object pop(java.lang.Object usr)
Return and remove the next element from the queue or stack.
Parameters:
usr - The queue user is the object with a field for the queue. For `lck.LckDesc'. For example, locks used by the `Context' or its fields use the `Context' (instance) object for their `usr'.
See Also:
lck.LckDesc(java.lang.Object, java.lang.String)

isEmpty

public boolean isEmpty(java.lang.Object usr)

isNotEmpty

public boolean isNotEmpty(java.lang.Object usr)

size

public int size(java.lang.Object usr)
Parameters:
usr - The queue user is the object with a field for the queue. For `lck.LckDesc'. For example, locks used by the `Context' or its fields use the `Context' (instance) object for their `usr'.
See Also:
lck.LckDesc(java.lang.Object, java.lang.String)

remove

public java.lang.Object remove(java.lang.Object usr,
                               java.lang.Object obj)
Parameters:
usr - The queue user is the object with a field for the queue. For `lck.LckDesc'. For example, locks used by the `Context' or its fields use the `Context' (instance) object for their `usr'.
obj - Target to remove
Returns:
Target when found and removed, otherwise null.
See Also:
lck.LckDesc(java.lang.Object, java.lang.String)

size_gt_1

public boolean size_gt_1()
Size greater than one.

This can be used for maintaining a default element at the bottom of the stack without counting the whole stack.

If a peek reveals the default element, and the stack size is not greater than one, then the stack position is at this bottom default element which would not be popped.

A `queue' subclass should redefine this `Enqueued' optimized method for its requirements.


popall_String

public java.lang.String popall_String(java.lang.Object usr)
Pop all elements into a string. Concatenate all enqueued elements into a string, each separated by a space (0x20).

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object ano)
Overrides:
equals in class java.lang.Object

cloneQueue

public queue cloneQueue()

copy

public queue copy()
Clone without depth of queue -- with only the top element of the queue/ stack.

popall_String

public java.lang.String popall_String(java.lang.Object usr,
                                      char sep)
Pop all elements into a string. Concatenate all enqueued elements into a string, each separated by the argument character. Uses the java Object 'toString' method.

hasMoreElements

public boolean hasMoreElements()
Returns true if the enumeration contains more elements; false if its empty.
Specified by:
hasMoreElements in interface java.util.Enumeration
See Also:
Enumeration

nextElement

public java.lang.Object nextElement()
Returns the next element of the enumeration. Calls to this method will enumerate successive elements.
Specified by:
nextElement in interface java.util.Enumeration
Throws:
java.util.NoSuchElementException - If no more elements exist.
See Also:
Enumeration

elements

public java.util.Enumeration elements()