Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class myIterator<E> implements Iterator<E> {
- E[] elemsOfMultiSet;
- int currentObj;
- int lastRemovedElement;
- myIterator() {
- elemsOfMultiSet = (E[])SimpleMultiSet.this.toArray();
- lastRemovedElement = -1;
- currentObj = -1;
- }
- @Override
- public E next() {
- if (this.hasNext()) {
- ++currentObj;
- return elemsOfMultiSet[currentObj];
- }
- else {
- throw new NoSuchElementException();
- }
- }
- @Override
- public boolean hasNext() {
- return currentObj < elemsOfMultiSet.length - 1;
- }
- @Override
- public void remove() {
- if (lastRemovedElement == currentObj){
- throw new IllegalStateException();
- }
- try {
- lastRemovedElement = currentObj;
- SimpleMultiSet.this.remove(elemsOfMultiSet[currentObj]);
- }
- catch (Exception e) {
- throw new IllegalStateException();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement