|
|||||||||
| Home >> All >> org >> jdaemon >> util >> [ iterator overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.jdaemon.util.iterator
Class AggregatingIterator

java.lang.Objectorg.jdaemon.util.iterator.AggregatingIterator
- All Implemented Interfaces:
- java.util.Iterator
- public abstract class AggregatingIterator
- extends java.lang.Object
- implements java.util.Iterator
- extends java.lang.Object
Abstract class for generating aggregate data from a collection
To create a concrete subclass of AggregatingIterator
beginGroup should be implemented to return a 'zero' value for aggregate data
addToGroup should be implemented to add a value from the underlying collection to the aggregate
For example, if beginGroup returns new Integer(0), and the underlying collection contains instances of a an employee class with name, department, and salary fields, addToGroup() could be implemented to add the salary from an employee object to the total.
Then if the Comparator object given to the AggregatingIterator sorts by the department field only, the resulting iterator will iterate over the total salary for all employees each department. Objects returned by the iterator will be map entries, where the key is the first employee object in each department, and the value is the value is the total salary for that department.
| Field Summary | |
private java.util.Comparator |
comparator
|
private java.util.Iterator |
iterator
|
private java.util.Map.Entry |
next
|
| Constructor Summary | |
AggregatingIterator(java.util.Collection collection,
java.util.Comparator comparator,
boolean sorted)
Creates a new instance of AggregatingIterator |
|
AggregatingIterator(java.util.Iterator iterator,
java.util.Comparator comparator,
boolean sorted)
|
|
AggregatingIterator(java.util.Map map,
java.util.Comparator comparator,
boolean sorted)
|
|
| Method Summary | |
protected abstract java.lang.Object |
addToGroup(java.lang.Object group,
java.lang.Object value)
|
protected abstract java.lang.Object |
beginGroup()
|
boolean |
hasNext()
Tests whether there are elements remaining in the collection. |
private static java.util.Map |
makeMap(java.util.Iterator i,
java.util.Comparator comparator)
|
private static java.util.Map |
makeMap(java.util.Map old_map,
java.util.Comparator comparator)
|
private void |
moveNext()
|
java.lang.Object |
next()
Obtain the next element in the collection. |
void |
remove()
Remove from the underlying collection the last element returned by next (optional operation). |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
iterator
private java.util.Iterator iterator
comparator
private java.util.Comparator comparator
next
private java.util.Map.Entry next
| Constructor Detail |
AggregatingIterator
public AggregatingIterator(java.util.Collection collection, java.util.Comparator comparator, boolean sorted)
- Creates a new instance of AggregatingIterator
AggregatingIterator
public AggregatingIterator(java.util.Map map, java.util.Comparator comparator, boolean sorted)
AggregatingIterator
public AggregatingIterator(java.util.Iterator iterator, java.util.Comparator comparator, boolean sorted)
| Method Detail |
makeMap
private static java.util.Map makeMap(java.util.Iterator i, java.util.Comparator comparator)
makeMap
private static java.util.Map makeMap(java.util.Map old_map, java.util.Comparator comparator)
moveNext
private void moveNext()
hasNext
public boolean hasNext()
- Description copied from interface:
java.util.Iterator - Tests whether there are elements remaining in the collection. In other
words, calling
next()will not throw an exception.- Specified by:
hasNextin interfacejava.util.Iterator
next
public java.lang.Object next()
- Description copied from interface:
java.util.Iterator - Obtain the next element in the collection.
- Specified by:
nextin interfacejava.util.Iterator
beginGroup
protected abstract java.lang.Object beginGroup()
addToGroup
protected abstract java.lang.Object addToGroup(java.lang.Object group, java.lang.Object value)
remove
public void remove()
- Description copied from interface:
java.util.Iterator - Remove from the underlying collection the last element returned by next
(optional operation). This method can be called only once after each
call to
next(). It does not affect what will be returned by subsequent calls to next.- Specified by:
removein interfacejava.util.Iterator
|
|||||||||
| Home >> All >> org >> jdaemon >> util >> [ iterator overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
org.jdaemon.util.iterator.AggregatingIterator