javatools.datatypes
Class ArrayQueue<T>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractQueue<T>
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
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 |
ArrayQueue
public ArrayQueue(T... initialData)
ArrayQueue
public ArrayQueue(java.util.Collection<T> initialData)
ArrayQueue
public ArrayQueue(int size)
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