|
@@ -527,12 +527,13 @@ public class LightWeightHashSet<T> implements Collection<T> {
|
|
}
|
|
}
|
|
|
|
|
|
private class LinkedSetIterator implements Iterator<T> {
|
|
private class LinkedSetIterator implements Iterator<T> {
|
|
- /** The starting modification for fail-fast. */
|
|
|
|
- private final int startModification = modification;
|
|
|
|
|
|
+ /** The current modification epoch. */
|
|
|
|
+ private int expectedModification = modification;
|
|
/** The current index of the entry array. */
|
|
/** The current index of the entry array. */
|
|
private int index = -1;
|
|
private int index = -1;
|
|
/** The next element to return. */
|
|
/** The next element to return. */
|
|
private LinkedElement<T> next = nextNonemptyEntry();
|
|
private LinkedElement<T> next = nextNonemptyEntry();
|
|
|
|
+ private LinkedElement<T> current;
|
|
|
|
|
|
private LinkedElement<T> nextNonemptyEntry() {
|
|
private LinkedElement<T> nextNonemptyEntry() {
|
|
for (index++; index < entries.length && entries[index] == null; index++);
|
|
for (index++; index < entries.length && entries[index] == null; index++);
|
|
@@ -546,13 +547,14 @@ public class LightWeightHashSet<T> implements Collection<T> {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public T next() {
|
|
public T next() {
|
|
- if (modification != startModification) {
|
|
|
|
|
|
+ if (modification != expectedModification) {
|
|
throw new ConcurrentModificationException("modification="
|
|
throw new ConcurrentModificationException("modification="
|
|
- + modification + " != startModification = " + startModification);
|
|
|
|
|
|
+ + modification + " != expectedModification = " + expectedModification);
|
|
}
|
|
}
|
|
if (next == null) {
|
|
if (next == null) {
|
|
throw new NoSuchElementException();
|
|
throw new NoSuchElementException();
|
|
}
|
|
}
|
|
|
|
+ current = next;
|
|
final T e = next.element;
|
|
final T e = next.element;
|
|
// find the next element
|
|
// find the next element
|
|
final LinkedElement<T> n = next.next;
|
|
final LinkedElement<T> n = next.next;
|
|
@@ -562,7 +564,16 @@ public class LightWeightHashSet<T> implements Collection<T> {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void remove() {
|
|
public void remove() {
|
|
- throw new UnsupportedOperationException("Remove is not supported.");
|
|
|
|
|
|
+ if (current == null) {
|
|
|
|
+ throw new NoSuchElementException();
|
|
|
|
+ }
|
|
|
|
+ if (modification != expectedModification) {
|
|
|
|
+ throw new ConcurrentModificationException("modification="
|
|
|
|
+ + modification + " != expectedModification = " + expectedModification);
|
|
|
|
+ }
|
|
|
|
+ LightWeightHashSet.this.removeElem(current.element);
|
|
|
|
+ current = null;
|
|
|
|
+ expectedModification = modification;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|