Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (C) 2009 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.facebook.presto.jdbc.internal.guava.collect;
import static com.facebook.presto.jdbc.internal.guava.base.Preconditions.checkArgument;
import static com.facebook.presto.jdbc.internal.guava.base.Preconditions.checkNotNull;
import static com.facebook.presto.jdbc.internal.guava.base.Preconditions.checkState;
import com.facebook.presto.jdbc.internal.guava.annotations.GwtCompatible;
import com.facebook.presto.jdbc.internal.guava.annotations.GwtIncompatible;
import com.facebook.presto.jdbc.internal.guava.base.Ascii;
import com.facebook.presto.jdbc.internal.guava.base.Equivalence;
import com.facebook.presto.jdbc.internal.guava.base.MoreObjects;
import com.facebook.presto.jdbc.internal.guava.collect.MapMakerInternalMap.Strength;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.lang.ref.WeakReference;
import java.util.ConcurrentModificationException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
/**
* A builder of {@link ConcurrentMap} instances that can have keys or values automatically wrapped
* in {@linkplain WeakReference weak} references.
*
*
These features are all optional; {@code new MapMaker().makeMap()} returns a valid concurrent
* map that behaves similarly to a {@link ConcurrentHashMap}.
*
*
The returned map is implemented as a hash table with similar performance characteristics to
* {@link ConcurrentHashMap}. It supports all optional operations of the {@code ConcurrentMap}
* interface. It does not permit null keys or values.
*
*
Note: by default, the returned map uses equality comparisons (the {@link Object#equals
* equals} method) to determine equality for keys or values. However, if {@link #weakKeys} was
* specified, the map uses identity ({@code ==}) comparisons instead for keys. Likewise, if {@link
* #weakValues} was specified, the map uses identity comparisons for values.
*
*
The view collections of the returned map have weakly consistent iterators. This means
* that they are safe for concurrent use, but if other threads modify the map after the iterator is
* created, it is undefined which of these changes, if any, are reflected in that iterator. These
* iterators never throw {@link ConcurrentModificationException}.
*
*
If {@link #weakKeys} or {@link #weakValues} are requested, it is possible for a key or value
* present in the map to be reclaimed by the garbage collector. Entries with reclaimed keys or
* values may be removed from the map on each map modification or on occasional map accesses; such
* entries may be counted by {@link Map#size}, but will never be visible to read or write
* operations. A partially-reclaimed entry is never exposed to the user. Any {@link java.util.Entry}
* instance retrieved from the map's {@linkplain Map#entrySet entry set} is a snapshot of that
* entry's state at the time of retrieval; such entries do, however, support {@link
* java.util.Entry#setValue}, which simply calls {@link Map#put} on the entry's key.
*
*
The maps produced by {@code MapMaker} are serializable, and the deserialized maps retain all
* the configuration properties of the original map. During deserialization, if the original map had
* used weak references, the entries are reconstructed as they were, but it's not unlikely they'll
* be quickly garbage-collected before they are ever accessed.
*
*
{@code new MapMaker().weakKeys().makeMap()} is a recommended replacement for {@link
* java.util.WeakHashMap}, but note that it compares keys using object identity whereas {@code
* WeakHashMap} uses {@link Object#equals}.
*
* @author Bob Lee
* @author Charles Fry
* @author Kevin Bourrillion
* @since 2.0
*/
@GwtCompatible(emulated = true)
public final class MapMaker {
private static final int DEFAULT_INITIAL_CAPACITY = 16;
private static final int DEFAULT_CONCURRENCY_LEVEL = 4;
static final int UNSET_INT = -1;
// TODO(kevinb): dispense with this after benchmarking
boolean useCustomMap;
int initialCapacity = UNSET_INT;
int concurrencyLevel = UNSET_INT;
@MonotonicNonNull Strength keyStrength;
@MonotonicNonNull Strength valueStrength;
@MonotonicNonNull Equivalence