Migliroato positions e agiunto come metodo alla interfaccia position. Fixato alcuni bug. Aggiunto test della prova intercorso del 10/4/14. Bisogna implementare tree
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
package position;
|
||||
import exceptions.*;
|
||||
import iterator.ElementIterator;
|
||||
import iterator.IterablePosition;
|
||||
import position.utility.DNode;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* Realization of a PositionList using a doubly-linked list of nodes.
|
||||
@@ -198,91 +198,10 @@ public class NodePositionList<E> implements PositionList<E> {
|
||||
}
|
||||
|
||||
|
||||
// inception style. a dream in a dream in a dream
|
||||
|
||||
public Iterable<Position<E>> positions() {
|
||||
return new MyPositionsIterable(this);
|
||||
return new IterablePosition(this);
|
||||
}
|
||||
|
||||
class MyPositionsIterable implements Iterable<Position<E>>{
|
||||
|
||||
private NodePositionList<E> base = null;
|
||||
|
||||
public MyPositionsIterable(NodePositionList<E> in){
|
||||
base = in;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Position<E>> iterator() {
|
||||
return new MyPositionsIterator(base);
|
||||
}
|
||||
|
||||
class MyPositionsIterator <E> implements Iterator<Position<E>> {
|
||||
public MyPositionsIterator (NodePositionList<E> structure){
|
||||
|
||||
new_structure = new NodePositionList<Position<E>>();
|
||||
if (structure.size() != 0){
|
||||
Position<E> temp;
|
||||
for (temp = structure.first() ; temp!= structure.last() ; temp = structure.next(temp)){
|
||||
new_structure.addLast(temp);
|
||||
}
|
||||
new_structure.addLast(temp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@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 Position<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<Position<E>> new_structure;
|
||||
Position<Position<E>> pos = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// end inception style
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user