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

com.shijingsh.core.utility.ConcurrentHashSet Maven / Gradle / Ivy

The newest version!
package com.shijingsh.core.utility;

import java.util.AbstractSet;
import java.util.Collection;
import java.util.Iterator;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 并发哈希集合
 *
 * 
 * 基于{@link ConcurrentHashMap}
 * 
* * @author Birdy * * @param */ public class ConcurrentHashSet extends AbstractSet { private static final Object object = new Object(); protected final ConcurrentHashMap map; public ConcurrentHashSet() { this.map = new ConcurrentHashMap(); } public ConcurrentHashSet(int capacity) { this.map = new ConcurrentHashMap(capacity); } public ConcurrentHashSet(int capacity, float factor) { this.map = new ConcurrentHashMap(capacity, factor); } public ConcurrentHashSet(int capacity, float factor, int concurrencyLevel) { this.map = new ConcurrentHashMap(capacity, factor, concurrencyLevel); } public ConcurrentHashSet(Collection collection) { this(collection.size()); addAll(collection); } @Override public int size() { return map.size(); } @Override public boolean contains(Object element) { return map.containsKey(element); } @Override public Iterator iterator() { return map.keySet().iterator(); } @Override public boolean add(E element) { return map.put(element, object) == null; } @Override public boolean remove(Object element) { return map.remove(element) != null; } @Override public void clear() { map.clear(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy