package net.sourceforge.fenixedu.commons;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
/**
* @author Goncalo Luiz
*
*
* Created on 18:43:06,3/Nov/2005
* @version $Id: OrderedIterator.java 37665 2008-08-14 13:13:11Z nmgo $
*/
public class OrderedIterator implements Iterator {
private Iterator iterator;
private List buildBackingList(Iterator iterator) {
List backingList = new ArrayList();
while (iterator.hasNext()) {
backingList.add(iterator.next());
}
return backingList;
}
public OrderedIterator(Iterator iterator, Comparator comparator) {
super();
List backingList = this.buildBackingList(iterator);
Collections.sort(backingList, comparator);
this.iterator = backingList.iterator();
}
public OrderedIterator(Iterator iterator) {
super();
List backingList = this.buildBackingList(iterator);
Collections.sort(backingList);
this.iterator = backingList.iterator();
}
public boolean hasNext() {
return this.iterator.hasNext();
}
public T next() {
return this.iterator.next();
}
public void remove() {
throw new UnsupportedOperationException();
}
}