/** * @param concurrencyLevel passed in to the underlying CHM. See {@link java.util.concurrent.ConcurrentHashMap#ConcurrentHashMap(int, * float, int)} javadocs for details. */ public ConcurrentHashSet(int concurrencyLevel) { map = CollectionFactory.makeConcurrentMap(16, concurrencyLevel); }
public static int computeCapacity(int expectedSize) { return computeCapacity(expectedSize, DEFAULT_LOAD_FACTOR); }
/** * @deprecated Since 9.0, please use {@link #makeConcurrentParallelMap(int, int)} instead. */ @Deprecated public static <K, V> ConcurrentMap<K, V> makeConcurrentParallelMap( int initCapacity, int concurrencyLevel, Equivalence<? super K> keyEq, Equivalence<? super V> valueEq) { return makeConcurrentParallelMap(initCapacity, concurrencyLevel); }
@Test(expected = UnsupportedOperationException.class) public void testAddAll2() throws Exception { Set<Integer> hashSet = CollectionFactory.makeSet(1, 4); IntSet sis = new SingletonIntSet(3); sis.addAll(hashSet); }
@Test public void testContainsAll1() throws Exception { IntSet sis = new SingletonIntSet(3); Set<Integer> hashSet = CollectionFactory.makeSet(new Integer[]{3}); assertTrue(sis.containsAll(hashSet)); assertTrue(hashSet.containsAll(sis)); hashSet.add(0); assertTrue(hashSet.containsAll(sis)); assertFalse(sis.containsAll(hashSet)); }
/** * Params passed in to the underlying CHM. See {@link java.util.concurrent.ConcurrentHashMap#ConcurrentHashMap(int, * float, int)} javadocs for details. */ public ConcurrentHashSet(int initSize, float loadFactor, int concurrencyLevel) { map = CollectionFactory.makeConcurrentMap(initSize, loadFactor, concurrencyLevel); }
@Test public void testAddAll2() throws Exception { intSet.addAll(CollectionFactory.makeSet(1, 4)); assertEquals(2, intSet.size()); }
/** * Unmarshall the {@link Map}. * <p> * If the marshalled map is {@link null}, then the {@link MapBuilder} is not invoked. * * @param in {@link ObjectInput} to read. * @param builder {@link MapBuilder} to create the concrete {@link Map} implementation. * @return The populated {@link Map} created by the {@link MapBuilder} or {@code null}. * @throws IOException If any of the usual Input/Output related exceptions occur. * @throws ClassNotFoundException If the class of a serialized object cannot be found. * @see #marshallMap(Map, ObjectOutput) */ public static <K, V, T extends Map<K, V>> T unmarshallMap(ObjectInput in, MapBuilder<K, V, T> builder) throws IOException, ClassNotFoundException { final int size = unmarshallSize(in); if (size == NULL_VALUE) { return null; } final T map = Objects.requireNonNull(builder, "MapBuilder must be non-null").build(computeCapacity(size)); for (int i = 0; i < size; i++) //noinspection unchecked map.put((K) in.readObject(), (V) in.readObject()); return map; }
public ConcurrentHashSet() { map = CollectionFactory.makeConcurrentMap(); }
/** * Unmarshall the {@link Map}. * <p> * If the marshalled map is {@link null}, then the {@link MapBuilder} is not invoked. * * @param in {@link ObjectInput} to read. * @param builder {@link MapBuilder} to create the concrete {@link Map} implementation. * @return The populated {@link Map} created by the {@link MapBuilder} or {@code null}. * @throws IOException If any of the usual Input/Output related exceptions occur. * @throws ClassNotFoundException If the class of a serialized object cannot be found. * @see #marshallMap(Map, ElementWriter, ElementWriter, ObjectOutput) */ public static <K, V, T extends Map<K, V>> T unmarshallMap(ObjectInput in, ElementReader<K> keyReader, ElementReader<V> valueReader, MapBuilder<K, V, T> builder) throws IOException, ClassNotFoundException { final int size = unmarshallSize(in); if (size == NULL_VALUE) { return null; } final T map = Objects.requireNonNull(builder, "MapBuilder must be non-null").build(computeCapacity(size)); for (int i = 0; i < size; i++) //noinspection unchecked map.put(keyReader.readFrom(in), valueReader.readFrom(in)); return map; }
public TemporaryTable(int capacity) { table = CollectionFactory.makeConcurrentMap(capacity); }
@Test public void testContainsAll1() throws Exception { intSet.add(1); intSet.add(4); Set<Integer> set = CollectionFactory.makeSet(1, 4, 7); assertFalse(intSet.containsAll(set)); assertTrue(set.containsAll(intSet)); }
/** * @deprecated Since 9.0, please use {@link #makeConcurrentMap(int, int)} instead. */ @Deprecated public static <K, V> ConcurrentMap<K, V> makeConcurrentMap( int initCapacity, int concurrencyLevel, Equivalence<? super K> keyEq, Equivalence<? super V> valueEq) { return makeConcurrentMap(initCapacity, concurrencyLevel); }
@Test public void testForEachObject() { intSet.add(0); intSet.add(4); intSet.add(7); Set<Integer> results = new HashSet<>(); intSet.forEach((Consumer<? super Integer>) results::add); assertEquals(CollectionFactory.makeSet(0, 4, 7), results); }
/** * @deprecated Since 9.0, please use {@link #makeConcurrentMap()} instead. */ @Deprecated public static <K, V> ConcurrentMap<K, V> makeConcurrentMap( Equivalence<? super K> keyEq, Equivalence<? super V> valueEq) { return makeConcurrentMap(); }
/** * @deprecated Since 9.0, please use {@link #makeConcurrentMap(int, float, int)} instead. */ @Deprecated public static <K, V> ConcurrentMap<K, V> makeConcurrentMap( int initCapacity, float loadFactor, int concurrencyLevel, Equivalence<? super K> keyEq, Equivalence<? super V> valueEq) { return makeConcurrentMap(initCapacity, loadFactor, concurrencyLevel); }
@Test public void testForEachPrimitive() { intSet.add(0); intSet.add(4); intSet.add(7); Set<Integer> results = new HashSet<>(); intSet.forEach((IntConsumer) results::add); assertEquals(CollectionFactory.makeSet(0, 4, 7), results); }
/** * @deprecated Since 9.0, please use {@link #makeConcurrentMap(int)} instead. */ @Deprecated public static <K, V> ConcurrentMap<K, V> makeConcurrentMap( int initCapacity, Equivalence<? super K> keyEq, Equivalence<? super V> valueEq) { return makeConcurrentMap(initCapacity); }