|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.xshare.base.iterator.SortingIterator
Sorts the elements of a given Collection
or
Iterator
according to a users specification.
In many situations you have to process the elements of a
collection or elements provided by an iterator in a specific
order - but the source of the elements provides them not in
the order you need. This class helps you to process the elements
of the source in the order you need by specifing a custom
Comparator
.
You have a presorted list with users and you want to print a list with all of them sorted by name.
private LinkedList usersSortedByAge; private printUsersSortedByName(Iterator source) { SortingIterator si = new SortingIterator(source, getComparatorForByName()); while (userItr.hasNext()) { System.out.println("User: " + userItr.next()); } }
remove()
is not supported since this class
plays only the role of a proxy.
RangeIterator
,
ReverseIterator
,
Comparator
Constructor Summary | |
SortingIterator(java.util.Collection pCollection,
java.util.Comparator pCustomComparator)
|
|
SortingIterator(java.util.Iterator pSourceIterator,
java.util.Comparator pCustomComparator)
|
Method Summary | |
boolean |
hasNext()
Checks if the sorted iteration has more elements to return or not. |
java.lang.Object |
next()
Returns the next element according to the internal sorting of the maintained elements. |
void |
remove()
This method is not supported since this class is only a proxy for a underlying collection with an different representation of its elements. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public SortingIterator(java.util.Iterator pSourceIterator, java.util.Comparator pCustomComparator)
public SortingIterator(java.util.Collection pCollection, java.util.Comparator pCustomComparator)
Method Detail |
public void remove()
remove
in interface java.util.Iterator
java.lang.UnsupportedOperationException
- if this method is called.public java.lang.Object next()
next
in interface java.util.Iterator
Object
representing the next element
to return according to the internal sorting of the elements.
NoSuchElementsException
- if hasNext()
returns false
, that means that there are no
elements left to return.hasNext()
public boolean hasNext()
hasNext
in interface java.util.Iterator
true
if there are more elements to return.
Otherwise false
is returned.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |