001 /*
002 * Copyright 2010 Google Inc. 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
017 package com.google.common.collect;
018
019 import com.google.common.annotations.Beta;
020 import com.google.common.annotations.GwtCompatible;
021 import com.google.common.annotations.GwtIncompatible;
022 import com.google.common.base.Function;
023
024 import java.util.concurrent.ConcurrentMap;
025 import 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)
040 public 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 @GwtIncompatible("To be supported")
060 public abstract GenericMapMaker<K0, V0> maximumSize(int maximumSize);
061
062 /**
063 * See {@link MapMaker#concurrencyLevel}.
064 */
065 @GwtIncompatible("java.util.concurrent.ConcurrentHashMap concurrencyLevel")
066 public abstract GenericMapMaker<K0, V0> concurrencyLevel(
067 int concurrencyLevel);
068
069 /**
070 * See {@link MapMaker#weakKeys}.
071 */
072 @GwtIncompatible("java.lang.ref.WeakReference")
073 public abstract GenericMapMaker<K0, V0> weakKeys();
074
075 /**
076 * See {@link MapMaker#softKeys}.
077 */
078 @GwtIncompatible("java.lang.ref.SoftReference")
079 public abstract GenericMapMaker<K0, V0> softKeys();
080
081 /**
082 * See {@link MapMaker#weakValues}.
083 */
084 @GwtIncompatible("java.lang.ref.WeakReference")
085 public abstract GenericMapMaker<K0, V0> weakValues();
086
087 /**
088 * See {@link MapMaker#softValues}.
089 */
090 @GwtIncompatible("java.lang.ref.SoftReference")
091 public abstract GenericMapMaker<K0, V0> softValues();
092
093 /**
094 * See {@link MapMaker#expiration}.
095 */
096 // TODO(user): deprecate
097 public abstract GenericMapMaker<K0, V0> expiration(
098 long duration, TimeUnit unit);
099
100 /**
101 * See {@link MapMaker#expireAfterWrite}.
102 *
103 * @since 8
104 */
105 @Beta
106 public abstract GenericMapMaker<K0, V0> expireAfterWrite(
107 long duration, TimeUnit unit);
108
109 /**
110 * See {@link MapMaker#expireAfterAccess}.
111 *
112 * @since 8
113 */
114 @Beta
115 @GwtIncompatible("To be supported")
116 public abstract GenericMapMaker<K0, V0> expireAfterAccess(
117 long duration, TimeUnit unit);
118
119 /*
120 * Note that MapMaker's evictionListener() is not here, because once you're
121 * interacting with a GenericMapMaker you've already called that, and
122 * shouldn't be calling it again.
123 */
124
125 /**
126 * See {@link MapMaker#makeMap}.
127 */
128 public abstract <K extends K0, V extends V0> ConcurrentMap<K, V> makeMap();
129
130 /**
131 * See {@link MapMaker#makeComputingMap}.
132 */
133 public abstract <K extends K0, V extends V0> ConcurrentMap<K, V>
134 makeComputingMap(Function<? super K, ? extends V> computingFunction);
135 }