javatools.datatypes
Class ArrayQueue<T>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractQueue<T>
          extended by javatools.datatypes.ArrayQueue<T>
All Implemented Interfaces:
java.lang.Iterable<T>, java.util.Collection<T>, java.util.Queue<T>

public class ArrayQueue<T>
extends java.util.AbstractQueue<T>

This class is part of the Java Tools (see http://mpii.de/yago-naga/javatools). It is licensed under the Creative Commons Attribution License (see http://creativecommons.org/licenses/by/3.0) by the YAGO-NAGA team (see http://mpii.de/yago-naga). This class implements a simple queue. The queue is not blocking (i.e. it will accept as many elements as you give it). It is more efficient than a LinkedList.
Example:

    // Create a queue with some initial elements
    Queue<Integer> a=new ArrayQueue<Integer>(1,2,3,4,5,6,7,8);
    int counter=9;
    // Always add one new element and poll two
    while(a.size()!=0) {
      a.offer(counter++);
      D.p(a.poll());
      D.p(a.poll());      
    }
    -->
        1,2,3,...,14


Constructor Summary
ArrayQueue(java.util.Collection<T> initialData)
           
ArrayQueue(int size)
           
ArrayQueue(T... initialData)
           
 
Method Summary
 java.util.Iterator<T> iterator()
           
static void main(java.lang.String[] args)
          Test routine
 boolean offer(T o)
           
 T peek()
           
 T poll()
           
 int size()
           
 
Methods inherited from class java.util.AbstractQueue
add, addAll, clear, element, remove
 
Methods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
contains, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Constructor Detail

ArrayQueue

public ArrayQueue(T... initialData)

ArrayQueue

public ArrayQueue(java.util.Collection<T> initialData)

ArrayQueue

public ArrayQueue(int size)
Method Detail

iterator

public java.util.Iterator<T> iterator()
Specified by:
iterator in interface java.lang.Iterable<T>
Specified by:
iterator in interface java.util.Collection<T>
Specified by:
iterator in class java.util.AbstractCollection<T>

size

public int size()
Specified by:
size in interface java.util.Collection<T>
Specified by:
size in class java.util.AbstractCollection<T>

offer

public boolean offer(T o)

peek

public T peek()

poll

public T poll()

main

public static void main(java.lang.String[] args)
Test routine