001/*
002 * Copyright 2010 The Guava Authors All Rights Reserved.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS-IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package com.google.common.collect;
018
019import com.google.common.annotations.Beta;
020import com.google.common.annotations.GwtCompatible;
021import com.google.common.annotations.GwtIncompatible;
022import com.google.common.base.Function;
023
024import java.util.concurrent.ConcurrentMap;
025import java.util.concurrent.TimeUnit;
026
027/**
028 * A class exactly like {@link MapMaker}, except restricted in the types of maps
029 * it can build. This type is returned by {@link MapMaker#evictionListener} to
030 * prevent the user from trying to build a map that's incompatible with the key
031 * and value types of the listener.
032 *
033 * @param <K0> the base type for all key types of maps built by this map maker
034 * @param <V0> the base type for all value types of maps built by this map maker
035 * @author Kevin Bourrillion
036 * @since 7
037 */
038@Beta
039@GwtCompatible(emulated = true)
040public abstract class GenericMapMaker<K0, V0> {
041  // Set by MapMaker, but sits in this class to preserve the type relationship
042  @GwtIncompatible("To be supported")
043  MapEvictionListener<K0, V0> evictionListener;
044
045  // No subclasses but our own
046  GenericMapMaker() {}
047
048  /**
049   * See {@link MapMaker#initialCapacity}.
050   */
051  public abstract GenericMapMaker<K0, V0> initialCapacity(int initialCapacity);
052
053  /**
054   * See {@link MapMaker#maximumSize}.
055   *
056   * @since 8
057   */
058  @Beta
059  public abstract GenericMapMaker<K0, V0> maximumSize(int maximumSize);
060
061  /**
062   * See {@link MapMaker#concurrencyLevel}.
063   */
064  @GwtIncompatible("java.util.concurrent.ConcurrentHashMap concurrencyLevel")
065  public abstract GenericMapMaker<K0, V0> concurrencyLevel(
066      int concurrencyLevel);
067
068  /**
069   * See {@link MapMaker#weakKeys}.
070   */
071  @GwtIncompatible("java.lang.ref.WeakReference")
072  public abstract GenericMapMaker<K0, V0> weakKeys();
073
074  /**
075   * See {@link MapMaker#softKeys}.
076   */
077  @GwtIncompatible("java.lang.ref.SoftReference")
078  public abstract GenericMapMaker<K0, V0> softKeys();
079
080  /**
081   * See {@link MapMaker#weakValues}.
082   */
083  @GwtIncompatible("java.lang.ref.WeakReference")
084  public abstract GenericMapMaker<K0, V0> weakValues();
085
086  /**
087   * See {@link MapMaker#softValues}.
088   */
089  @GwtIncompatible("java.lang.ref.SoftReference")
090  public abstract GenericMapMaker<K0, V0> softValues();
091
092  /**
093   * See {@link MapMaker#expiration}.
094   */
095  // TODO(user): deprecate
096  public abstract GenericMapMaker<K0, V0> expiration(
097      long duration, TimeUnit unit);
098
099  /**
100   * See {@link MapMaker#expireAfterWrite}.
101   *
102   * @since 8
103   */
104  @Beta
105  public abstract GenericMapMaker<K0, V0> expireAfterWrite(
106      long duration, TimeUnit unit);
107
108  /**
109   * See {@link MapMaker#expireAfterAccess}.
110   *
111   * @since 8
112   */
113  @Beta
114  @GwtIncompatible("To be supported")
115  public abstract GenericMapMaker<K0, V0> expireAfterAccess(
116      long duration, TimeUnit unit);
117
118  /*
119   * Note that MapMaker's evictionListener() is not here, because once you're
120   * interacting with a GenericMapMaker you've already called that, and
121   * shouldn't be calling it again.
122   */
123
124  /**
125   * See {@link MapMaker#makeMap}.
126   */
127  public abstract <K extends K0, V extends V0> ConcurrentMap<K, V> makeMap();
128
129  /**
130   * See {@link MapMaker#makeComputingMap}.
131   */
132  public abstract <K extends K0, V extends V0> ConcurrentMap<K, V>
133      makeComputingMap(Function<? super K, ? extends V> computingFunction);
134}