![JAR search and dependency download from the Maven repository](/logo.png)
net.engio.mbassy.common.StrongConcurrentSet Maven / Gradle / Ivy
package net.engio.mbassy.common;
import java.util.HashMap;
import java.util.Iterator;
/**
* This implementation uses strong references to the elements.
*
*
* @author bennidi
* Date: 2/12/12
*/
public class StrongConcurrentSet extends AbstractConcurrentSet{
public StrongConcurrentSet() {
super(new HashMap>());
}
public Iterator iterator() {
return new Iterator() {
private ISetEntry current = head;
public boolean hasNext() {
return current != null;
}
public T next() {
if (current == null) {
return null;
}
else {
T value = current.getValue();
current = current.next();
return value;
}
}
public void remove() {
if (current == null) {
return;
}
ISetEntry newCurrent = current.next();
StrongConcurrentSet.this.remove(current.getValue());
current = newCurrent;
}
};
}
@Override
protected Entry createEntry(T value, Entry next) {
return next != null ? new StrongEntry(value, next) : new StrongEntry(value);
}
public static class StrongEntry extends Entry {
private T value;
private StrongEntry(T value, Entry next) {
super(next);
this.value = value;
}
private StrongEntry(T value) {
super();
this.value = value;
}
@Override
public T getValue() {
return value;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy