xxl.cursors
Class Grouper

java.lang.Object
  |
  +--xxl.cursors.Grouper

public class Grouper
extends java.lang.Object
implements Cursor

A Grouper partitions input data into groups (lazy evaluation). A binary Function is used to compare the actual with the last element. If the Function returns true a new group starts. A call to next() returns a Cursor pointing to the next group.


Field Summary
protected  Cursor cursor
          The Cursor to be wrapped.
protected  Function function
          The Function used to compare two elements.
protected  int groupSize
          The actual size of the group.
protected  boolean hasPeeked
           
protected  java.lang.Object prePrevious
          The Object seen before the actual Object.
protected  java.lang.Object previous
          The Object seen before the actual Object.
protected  boolean updatePossible
           
 
Constructor Summary
Grouper(Cursor cursor, Function function)
          Creates a new Grouper.
Grouper(java.util.Iterator iterator, Function function)
          Creates a new Grouper.
Grouper(PeekIterator peekIterator, Function function)
          Creates a new Grouper.
 
Method Summary
 void close()
          Closes the Cursor.
 boolean hasNext()
          Returns true if the iteration has more elements.
 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.
 void remove()
          Removes from the underlying collection the last element returned by the iterator (optional operation).
 void reset()
          Resets the Cursor to its initial state.
 boolean supportsPeek()
          Returns true if the peek operation is supported by this PeekIterator (Always returns false).
 void update(java.lang.Object object)
          Replaces the object that was returned by the last call to next() or peek().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cursor

protected Cursor cursor
The Cursor to be wrapped.

function

protected Function function
The Function used to compare two elements.

previous

protected java.lang.Object previous
The Object seen before the actual Object.

prePrevious

protected java.lang.Object prePrevious
The Object seen before the actual Object.

groupSize

protected int groupSize
The actual size of the group.

hasPeeked

protected boolean hasPeeked

updatePossible

protected boolean updatePossible
Constructor Detail

Grouper

public Grouper(Cursor cursor,
               Function function)
Creates a new Grouper.
Parameters:
cursor - the Cursor to be wrapped
function - the Function used to compare two elements

Grouper

public Grouper(java.util.Iterator iterator,
               Function function)
Creates a new Grouper.
Parameters:
iterator - the iterator to be wrapped
function - the Function used to compare two elements

Grouper

public Grouper(PeekIterator peekIterator,
               Function function)
Creates a new Grouper.
Parameters:
peekIterator - the PeekIterator to be wrapped
function - the Function used to compare two elements
Method Detail

close

public void close()
Closes the Cursor. Signals the cursor to cleanup resources, close files, etc. After a call to close() calls to methods like next() or peek() are not guarantied to yield proper results.
Specified by:
close in interface Cursor

hasNext

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

next

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

peek

public java.lang.Object peek()
                      throws java.lang.UnsupportedOperationException
Shows the next element in the iteration without removing it.
Specified by:
peek in interface Cursor
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.

remove

public void remove()
            throws java.lang.UnsupportedOperationException
Removes from the underlying collection the last element returned by the iterator (optional operation).
Specified by:
remove in interface Cursor
Throws:
java.lang.IllegalStateException - if the next method has not yet been called, or the remove method has already been called after the last call to the next method.
java.lang.UnsupportedOperationException - if the remove operation is not supported by this PeekIterator.

reset

public void reset()
           throws java.lang.UnsupportedOperationException
Resets the Cursor to its initial state.
Specified by:
reset in interface Cursor

supportsPeek

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

update

public void update(java.lang.Object object)
            throws java.lang.UnsupportedOperationException
Replaces the object that was returned by the last call to next() or peek(). This operation must not be called after a call to hasNext(). It should foow a call to next() or peek().
Specified by:
update in interface Cursor
Parameters:
object - the object that replaces the object returned by the last call to next() or peek()