de.unibi.techfak.misc
Class Queue

java.lang.Object
  extended by de.unibi.techfak.misc.Queue

public class Queue
extends java.lang.Object

A queue structure built through a LinkedList.


Field Summary
private  java.util.LinkedList fStack
          The queue is represented via this list.
 
Constructor Summary
Queue()
          Constructs an empty queue.
 
Method Summary
 java.lang.Object element()
          Retrieves, but does not remove, the head of this queue.
 boolean isEmpty()
           
 java.util.ListIterator iterator(int index)
           
 boolean offer(java.lang.Object elem)
          Inserts the specified element into this queue, if possible.
 java.lang.Object peek()
          Retrieves, but does not remove, the head of this queue, returning null, if this queue is empty.
 java.lang.Object poll()
          Retrieves and removes the head of this queue, or null if this queue is empty.
 java.lang.Object remove()
          Retrieves and removes the head of this queue.
 int size()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fStack

private final java.util.LinkedList fStack
The queue is represented via this list.

Constructor Detail

Queue

public Queue()
Constructs an empty queue.

Method Detail

element

public java.lang.Object element()
                         throws java.util.NoSuchElementException
Retrieves, but does not remove, the head of this queue. This method throws an exception in case of an empty queue.

Returns:
The head of this queue.
Throws:
java.util.NoSuchElementException

peek

public java.lang.Object peek()
Retrieves, but does not remove, the head of this queue, returning null, if this queue is empty.

Returns:
The head of this queue or null.

offer

public boolean offer(java.lang.Object elem)
Inserts the specified element into this queue, if possible.

Parameters:
elem - The element to insert into the queue.
Returns:
true in case of success, false otherwise.

poll

public java.lang.Object poll()
Retrieves and removes the head of this queue, or null if this queue is empty.

Returns:
The former head of the queue or null.

remove

public java.lang.Object remove()
                        throws java.util.NoSuchElementException
Retrieves and removes the head of this queue.

Returns:
The former head of the queue.
Throws:
java.util.NoSuchElementException - If the queue is empty.

isEmpty

public boolean isEmpty()
Returns:
true or false, respectively, whether the queue is empty or not.

size

public int size()
Returns:
The number of elements in this queue

iterator

public java.util.ListIterator iterator(int index)
                                throws java.lang.IndexOutOfBoundsException
Parameters:
index - The start in the iterator.
Returns:
A ListIterator starting with the given index.
Throws:
java.lang.IndexOutOfBoundsException