Rimosso ArraySequenceFake. Implementato positions() in NodePositionList. Creato il DefaultComparator. Prima implementazione di SortedPriorityList
This commit is contained in:
@@ -251,7 +251,7 @@ public class NodePositionList<E> implements PositionList<E> {
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
|
||||
throw new UnsupportedOperationException ();
|
||||
}
|
||||
|
||||
NodePositionList<E> new_structure;
|
||||
@@ -260,5 +260,73 @@ public class NodePositionList<E> implements PositionList<E> {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Position<E>> positions() {
|
||||
return new MyPositionsIterator(this);
|
||||
}
|
||||
|
||||
class MyPositionsIterator 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;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,5 +37,8 @@ public interface PositionList<E> extends Iterable<E> {
|
||||
public E set(Position<E> p, E e) throws InvalidPositionException;
|
||||
|
||||
|
||||
public Iterator<Position<E>> positions();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user