IndexListIterator che implementa Iterator mediante un array list. Implementazione di Iterator mediante cursore : ElementIterator per PositionList. Aggiunti alcuni metodi e spostato le classi IndexListIterator,ElementIterator nel package Iterator.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package position;
|
||||
import exceptions.*;
|
||||
import iterator.ElementIterator;
|
||||
import position.utility.DNode;
|
||||
import sun.org.mozilla.javascript.internal.ObjToIntMap;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
@@ -192,75 +192,13 @@ public class NodePositionList<E> implements PositionList<E> {
|
||||
|
||||
|
||||
@Override
|
||||
// iterator created using specific class for PositionList data structures : ElementIterator
|
||||
public Iterator<E> iterator() {
|
||||
return new MyIterator(this);
|
||||
return new ElementIterator<E>(this);
|
||||
}
|
||||
|
||||
class MyIterator implements Iterator<E>{
|
||||
|
||||
public MyIterator (NodePositionList<E> structure){
|
||||
|
||||
new_structure = new NodePositionList<E>();
|
||||
if (structure.size() != 0){
|
||||
Position<E> temp;
|
||||
for (temp = structure.first() ; temp!= structure.last() ; temp = structure.next(temp)){
|
||||
new_structure.addLast(temp.element());
|
||||
}
|
||||
new_structure.addLast(temp.element());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
if (pos == null){
|
||||
if (new_structure. size() <= 0){
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
try {
|
||||
new_structure.next(pos);
|
||||
return true;
|
||||
}
|
||||
catch (BoundaryViolationException err){
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public E next() throws NoSuchElementException {
|
||||
if (hasNext()){
|
||||
if (pos == null){
|
||||
pos = new_structure.first();
|
||||
}else {
|
||||
pos = new_structure.next(pos);
|
||||
}
|
||||
return pos.element();
|
||||
} else{
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException ();
|
||||
}
|
||||
|
||||
NodePositionList<E> new_structure;
|
||||
Position<E> pos = null;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Position<E>> positions() {
|
||||
return new MyPositionsIterator(this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user