This commit is contained in:
2014-04-08 18:18:58 +02:00
parent fe79fbe138
commit 0956f6b92f
4 changed files with 77 additions and 54 deletions

View File

@@ -63,6 +63,11 @@ public class NodePositionListTest {
System.out.print(it.next());
System.out.print(it.hasNext());
System.out.print(a.positions().iterator());
System.out.print(it.hasNext());
System.out.print(((Position<Integer>)(it.next().);

View File

@@ -198,73 +198,91 @@ public class NodePositionList<E> implements PositionList<E> {
}
// inception style. a dream in a dream in a dream
public Iterator<Position<E>> positions() {
return new MyPositionsIterator(this);
public Iterable<Position<E>> positions() {
return new MyPositionsIterable(this);
}
class MyPositionsIterator implements Iterator<Position<E>>{
class MyPositionsIterable implements Iterable<Position<E>>{
public MyPositionsIterator (NodePositionList<E> structure){
private NodePositionList<E> base = null;
new_structure = new NodePositionList<Position<E>>();
if (structure.size() != 0){
Position<E> temp;
for (temp = structure.first() ; temp!= structure.last() ; temp = structure.next(temp)){
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);
}
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()){
@Override
public boolean hasNext() {
if (pos == null){
pos = new_structure.first();
}else {
pos = new_structure.next(pos);
if (new_structure.size() <= 0){
return false;
} else {
return true;
}
} else {
try {
new_structure.next(pos);
return true;
}
catch (BoundaryViolationException err){
return false;
}
}
return pos.element();
} else{
throw new NoSuchElementException();
}
@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;
}
@Override
public void remove() {
throw new UnsupportedOperationException ();
}
NodePositionList<Position<E>> new_structure;
Position<Position<E>> pos = null;
}
// end inception style
}

View File

@@ -55,7 +55,7 @@ public class SortedListPriorityQueue<K,V> implements PriorityQueue<K,V> {
data.addFirst(t);
return t;
} else {
Iterator<Position<MyEntry<K, V>>> itp = data.positions();
Iterator<Position<MyEntry<K, V>>> itp = data.positions().iterator();
int status;
Position<MyEntry<K, V>> temp_pos = null;
for (; itp.hasNext(); ) {

View File

@@ -43,7 +43,7 @@ public class UnsortedListPriorityQueue<K,V> implements PriorityQueue<K,V> {
if (isEmpty()){
throw new EmptyPriorityQueueException();
} else {
Iterator<Position<MyEntry<K, V>>> itp = data.positions();
Iterator<Position<MyEntry<K, V>>> itp = data.positions().iterator();
int status;
Position<MyEntry<K, V>> min = null;
Position<MyEntry<K, V>> temp_pos = null;
@@ -83,7 +83,7 @@ public class UnsortedListPriorityQueue<K,V> implements PriorityQueue<K,V> {
if (isEmpty()){
throw new EmptyPriorityQueueException();
} else {
Iterator<Position<MyEntry<K, V>>> itp = data.positions();
Iterator<Position<MyEntry<K, V>>> itp = data.positions().iterator();
int status;
Position<MyEntry<K, V>> min = null;
Position<MyEntry<K, V>> temp_pos = null;