Skip to content

Commit

Permalink
Done
Browse files Browse the repository at this point in the history
  • Loading branch information
amirg00 committed Dec 12, 2021
1 parent 2a3d959 commit f62489e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
Binary file added Ex2.jar
Binary file not shown.
54 changes: 54 additions & 0 deletions src/api/Iterator_Operation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package api;

import java.util.Iterator;

public class Iterator_Operation<T> implements Iterator {
private Iterator<T> graphComponent;
private int mc, mc_2;


public Iterator_Operation(Iterator<T> iterator, int mc) {
this.graphComponent = iterator;
this.mc = mc;
this.mc_2 = mc;
}


@Override
public boolean hasNext() {
try {
if (mc != mc_2) {
throw new RuntimeException("Graph was changed since the iterator was constructed!");
}
} catch (RuntimeException e) {
e.printStackTrace();
}
return graphComponent.hasNext();
}

@Override
public Object next() {
try {
if (mc != mc_2) {
throw new RuntimeException("Graph was changed since the iterator was constructed!");
}
} catch (RuntimeException e) {
e.printStackTrace();
}
return graphComponent.next();
}

@Override
public void remove(){
try {
if (mc != mc_2) {
throw new RuntimeException("Graph was changed since the iterator was constructed!");
}
} catch (RuntimeException e) {
e.printStackTrace();
}
graphComponent.remove();
}

}

0 comments on commit f62489e

Please sign in to comment.