Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. public class myIterator<E> implements Iterator<E> {
  2. E[] elemsOfMultiSet;
  3. int currentObj;
  4. int lastRemovedElement;
  5. myIterator() {
  6. elemsOfMultiSet = (E[])SimpleMultiSet.this.toArray();
  7. lastRemovedElement = -1;
  8. currentObj = -1;
  9. }
  10. @Override
  11. public E next() {
  12. if (this.hasNext()) {
  13. ++currentObj;
  14. return elemsOfMultiSet[currentObj];
  15. }
  16. else {
  17. throw new NoSuchElementException();
  18. }
  19.  
  20. }
  21.  
  22. @Override
  23. public boolean hasNext() {
  24. return currentObj < elemsOfMultiSet.length - 1;
  25. }
  26.  
  27. @Override
  28. public void remove() {
  29. if (lastRemovedElement == currentObj){
  30. throw new IllegalStateException();
  31. }
  32. try {
  33. lastRemovedElement = currentObj;
  34. SimpleMultiSet.this.remove(elemsOfMultiSet[currentObj]);
  35. }
  36. catch (Exception e) {
  37. throw new IllegalStateException();
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement