com.iwuyc.tools.commons.basic.collections.ConcurrentHashSet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of iwuyc-common Show documentation
Show all versions of iwuyc-common Show documentation
Common tools.Include utility classes,and much much more.
The newest version!
package com.iwuyc.tools.commons.basic.collections;
import java.util.concurrent.ConcurrentHashMap;
/**
* 线程安全的hash set实现
* @author Neil
*/
public class ConcurrentHashSet extends EmbellishSet {
public ConcurrentHashSet() {
super(new ConcurrentHashMap<>());
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public boolean add(T o) {
Object previousVal = ((ConcurrentHashMap) this.container).putIfAbsent(o, Boolean.TRUE);
return previousVal == null;
}
}