Back to index

wims  3.65+svn20090927
Classes | Public Member Functions | Private Attributes
fr.ove.utils.Queue Class Reference

A queue. More...

Inheritance diagram for fr.ove.utils.Queue:
Inheritance graph
[legend]
Collaboration diagram for fr.ove.utils.Queue:
Collaboration graph
[legend]

List of all members.

Classes

class  QueueEnumerator

Public Member Functions

 Queue ()
 The Constructor.
void enqueue (Object element)
 Adds the specified element to the queue.
Object dequeue ()
 Removes the first element added into the queue.
Object peek ()
 Returns the first element added into the queue.
boolean isEmpty ()
 Checks if the queue is empty.
void clear ()
 Clears the queue.
Enumeration elements ()
 Returns an.
Object[] getElements ()
 Returns an array of the elements contained in the queue.
String toString ()
 Returns a string representation of the queue.

Private Attributes

LinkedElement head
 The head of the queue.
LinkedElement tail
 The tail of the queue.
int nbElements
 The number of elements.

Detailed Description

A queue.

Author:
2000 DIRAT Laurent
Version:
1.0 28/06/2000

Definition at line 19 of file Queue.java.


Constructor & Destructor Documentation

The Constructor.

Definition at line 38 of file Queue.java.

                   {
        head = tail = null;
        nbElements = 0;
    }

Member Function Documentation

void fr.ove.utils.Queue.clear ( ) [inline]

Clears the queue.

Implements fr.ove.utils.Queueable.

Definition at line 103 of file Queue.java.

                        {
        head = tail = null;
        nbElements = 0;
    }
Object fr.ove.utils.Queue.dequeue ( ) [inline]

Removes the first element added into the queue.

Returns the element removed. null if the queue is empty.

Implements fr.ove.utils.Queueable.

Definition at line 63 of file Queue.java.

                            {
        Object element = null;
        
        if (nbElements != 0) {
            LinkedElement dequeued = head;
            element = dequeued.getElement();
            head = dequeued.getPrevious();
            dequeued.remove();
            
            if (nbElements == 1)
                head = tail = null;
                
            nbElements--;
        }
        
        return element;
    }

Here is the call graph for this function:

Enumeration fr.ove.utils.Queue.elements ( ) [inline]

Returns an.

See also:
Enumeration of the elements in the queue.

Implements fr.ove.utils.Queueable.

Definition at line 111 of file Queue.java.

                                  {
        synchronized (this) {
            return (Enumeration) new QueueEnumerator(this);
        }
    }

Here is the caller graph for this function:

void fr.ove.utils.Queue.enqueue ( Object  element) [inline]

Adds the specified element to the queue.

Implements fr.ove.utils.Queueable.

Definition at line 46 of file Queue.java.

                                        {
        LinkedElement newElement = new LinkedElement(element);
        if (nbElements == 0)
            head = tail = newElement;
        else {
            newElement.setNext(tail);
            tail.setPrevious(newElement);
            tail = newElement;
        }
        
        nbElements++;
    }

Here is the call graph for this function:

Object [] fr.ove.utils.Queue.getElements ( ) [inline]

Returns an array of the elements contained in the queue.


If the queue is empty, returns null.

Definition at line 122 of file Queue.java.

                                  {
        Object elements[] = null;
        
        if (nbElements != 0) {
            elements = new Object[nbElements];
            
            LinkedElement ptr = tail;
            int index = 0;
            while (ptr != null) {
                elements[index++] = ptr.getElement();
                ptr = ptr.getNext();
            }
        }
        
        return elements;
    }

Here is the call graph for this function:

Checks if the queue is empty.

Returns true if the queue is empty. false otherwise.

Implements fr.ove.utils.Queueable.

Definition at line 96 of file Queue.java.

                             {
        return (nbElements == 0);
    }
Object fr.ove.utils.Queue.peek ( ) [inline]

Returns the first element added into the queue.

null if the queue is empty

Implements fr.ove.utils.Queueable.

Definition at line 85 of file Queue.java.

                         {
        if (nbElements != 0)
            return head.getElement();
        else 
            return null;
    }

Here is the call graph for this function:

String fr.ove.utils.Queue.toString ( ) [inline]

Returns a string representation of the queue.

Definition at line 142 of file Queue.java.

                             {
        String string = "";
        LinkedElement ptr = tail;
        
        while (ptr != null) {
            string += " " + ptr.toString();
            ptr = ptr.getNext();
        }
        
        return string + " ";
    }

Here is the call graph for this function:


Member Data Documentation

The head of the queue.

Definition at line 23 of file Queue.java.

The number of elements.

Definition at line 33 of file Queue.java.

The tail of the queue.

Definition at line 28 of file Queue.java.


The documentation for this class was generated from the following file: