All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.iwuyc.tools.commons.basic.collections.ConcurrentHashSet Maven / Gradle / Ivy

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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy