xxl.collections
Interface Queue

All Known Implementing Classes:
AbstractQueue

public abstract interface Queue
extends PeekIterator

This interface adds queue-like access to an object.


Field Summary
static Function FACTORY_METHOD
          A factory method to create a default Queue.
 
Method Summary
 void clear()
          Removes all elements form the Queue.
 void close()
          Releases resources needed to access data.
 boolean hasNext()
          Returns true if the iteration has more elements.
 void insert(java.lang.Object object)
          Appends an object to the end of the queue.
 void insertAll(java.util.Iterator objects)
          Appends all objects of the specified iterator to the end of the queue.
 java.lang.Object next()
          Returns the next element in the iteration.
 java.lang.Object peek()
          Shows the next element in the iteration without removing it.
 java.lang.Object replace(java.lang.Object object)
          Inserts a given object and returns this.next().
 java.util.Iterator replaceAll(java.util.Iterator objects)
          Inserts a given Iterator of objects and returns an Iterator wrapping calls to this.next().
 int size()
          Returns the size of the Queue.
 boolean supportsPeek()
          Returns true if the peek operation is supported by this PeekIterator.
 
Methods inherited from interface xxl.cursors.PeekIterator
remove
 

Field Detail

FACTORY_METHOD

public static final Function FACTORY_METHOD
A factory method to create a default Queue. Each implementation of Queue should have a field FACTORY_METHOD which is a factory method that implements three variants of invoke()
Method Detail

insert

public void insert(java.lang.Object object)
Appends an object to the end of the queue.
Parameters:
object - object to be appended to the queue

insertAll

public void insertAll(java.util.Iterator objects)
Appends all objects of the specified iterator to the end of the queue. This means that the following code should be executed:
while(objects.hasNext()){
insert(objects.next());
}
We did not include this code, because Java does not support multiple inheritance. Note, that this method is implemented in AbstractQueue. IMPORTANT: This method is not named insertAll(Iterator) for the follwing reason: consider that you have a Queue whose entries are Iterators. A call to insert would result in a call to insert(Iterator) and all the elements of the Iterator would be inserted into the Queue, which would not be what you wanted and is a very nasty bug.
Parameters:
objects - iterator of objects

hasNext

public boolean hasNext()
Returns true if the iteration has more elements.
Specified by:
hasNext in interface PeekIterator
Returns:
true if the iterator has more elements.

peek

public java.lang.Object peek()
                      throws java.util.NoSuchElementException
Shows the next element in the iteration without removing it.
Specified by:
peek in interface PeekIterator
Returns:
the next element in the iteration
Throws:
java.util.NoSuchElementException - iteration has no more elements
java.lang.UnsupportedOperationException - if the peek operation is not supported by this PeekIterator

next

public java.lang.Object next()
                      throws java.util.NoSuchElementException
Returns the next element in the iteration.
Specified by:
next in interface PeekIterator
Returns:
the next element in the iteration
Throws:
java.util.NoSuchElementException - iteration has no more elements

replace

public java.lang.Object replace(java.lang.Object object)
                         throws java.util.NoSuchElementException
Inserts a given object and returns this.next().

replaceAll

public java.util.Iterator replaceAll(java.util.Iterator objects)
                              throws java.util.NoSuchElementException
Inserts a given Iterator of objects and returns an Iterator wrapping calls to this.next(). (lazy evaluation)

size

public int size()
Returns the size of the Queue.

supportsPeek

public boolean supportsPeek()
Returns true if the peek operation is supported by this PeekIterator.
Specified by:
supportsPeek in interface PeekIterator
Returns:
true if the peek operation is supported by this PeekIterator

clear

public void clear()
Removes all elements form the Queue.

close

public void close()
Releases resources needed to access data.