Implementato Iterator in NodePositionList e aggiunto solo i prototipi nelle altre classe che implementano Sequence
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
package position;
|
||||
import exceptions.*;
|
||||
import position.utility.DNode;
|
||||
import sun.org.mozilla.javascript.internal.ObjToIntMap;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* Realization of a PositionList using a doubly-linked list of nodes.
|
||||
@@ -187,4 +191,74 @@ public class NodePositionList<E> implements PositionList<E> {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Iterator<E> iterator() {
|
||||
return new MyIterator(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() {
|
||||
|
||||
}
|
||||
|
||||
NodePositionList<E> new_structure;
|
||||
Position<E> pos = null;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import exceptions.*;
|
||||
//Copyright (c) 2003 Brown University, Providence, RI
|
||||
//Additional modifications and methods by xgiovio
|
||||
|
||||
public interface PositionList<E> {
|
||||
public interface PositionList<E> extends Iterable<E> {
|
||||
|
||||
|
||||
public int size();
|
||||
|
||||
Reference in New Issue
Block a user