diff --git a/src/main/java/net/engio/mbassy/common/WeakConcurrentSet.java b/src/main/java/net/engio/mbassy/common/WeakConcurrentSet.java index 0741cf1..d5d060e 100644 --- a/src/main/java/net/engio/mbassy/common/WeakConcurrentSet.java +++ b/src/main/java/net/engio/mbassy/common/WeakConcurrentSet.java @@ -23,25 +23,26 @@ public class WeakConcurrentSet extends AbstractConcurrentSet{ super(new WeakHashMap>()); } + @Override public Iterator iterator() { return new Iterator() { // the current listelement of this iterator // used to keep track of the iteration process - private ISetEntry current = head; + private ISetEntry current = WeakConcurrentSet.this.head; // this method will remove all orphaned entries // until it finds the first entry whose value has not yet been garbage collected // the method assumes that the current element is already orphaned and will remove it private void removeOrphans(){ - Lock writelock = lock.writeLock(); + Lock writelock = WeakConcurrentSet.this.lock.writeLock(); try{ writelock.lock(); do { - ISetEntry orphaned = current; - current = current.next(); + ISetEntry orphaned = this.current; + this.current = this.current.next(); orphaned.remove(); - } while(current != null && current.getValue() == null); + } while(this.current != null && this.current.getValue() == null); } finally { writelock.unlock(); @@ -49,40 +50,45 @@ public class WeakConcurrentSet extends AbstractConcurrentSet{ } + @Override public boolean hasNext() { - if (current == null) return false; - if (current.getValue() == null) { + if (this.current == null) { + return false; + } + if (this.current.getValue() == null) { // trigger removal of orphan references // because a null value indicates that the value has been garbage collected removeOrphans(); - return current != null; // if any entry is left then it will have a value + return this.current != null; // if any entry is left then it will have a value } else { return true; } } + @Override public T next() { - if (current == null) { + if (this.current == null) { return null; } - T value = current.getValue(); + T value = this.current.getValue(); if (value == null) { // auto-removal of orphan references removeOrphans(); return next(); } else { - current = current.next(); + this.current = this.current.next(); return value; } } + @Override public void remove() { //throw new UnsupportedOperationException("Explicit removal of set elements is only allowed via the controlling set. Sorry!"); - if (current == null) { + if (this.current == null) { return; } - ISetEntry newCurrent = current.next(); - WeakConcurrentSet.this.remove(current.getValue()); - current = newCurrent; + ISetEntry newCurrent = this.current.next(); + WeakConcurrentSet.this.remove(this.current.getValue()); + this.current = newCurrent; } }; } @@ -109,7 +115,7 @@ public class WeakConcurrentSet extends AbstractConcurrentSet{ @Override public T getValue() { - return value.get(); + return this.value.get(); }