001 /*
002 * Copyright (C) 2010 The Guava Authors
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.Equivalence;
023 import com.google.common.base.Function;
024 import com.google.common.base.Objects;
025 import com.google.common.collect.MapMaker.RemovalListener;
026 import com.google.common.collect.MapMaker.RemovalNotification;
027
028 import java.util.concurrent.ConcurrentMap;
029 import java.util.concurrent.TimeUnit;
030
031 /**
032 * A class exactly like {@link MapMaker}, except restricted in the types of maps it can build.
033 * For the most part, you should probably just ignore the existence of this class.
034 *
035 * @param <K0> the base type for all key types of maps built by this map maker
036 * @param <V0> the base type for all value types of maps built by this map maker
037 * @author Kevin Bourrillion
038 * @since 7.0
039 */
040 @Beta
041 @GwtCompatible(emulated = true)
042 public abstract class GenericMapMaker<K0, V0> {
043 @GwtIncompatible("To be supported")
044 enum NullListener implements RemovalListener<Object, Object> {
045 INSTANCE;
046
047 @Override
048 public void onRemoval(RemovalNotification<Object, Object> notification) {}
049 }
050
051 // Set by MapMaker, but sits in this class to preserve the type relationship
052 @GwtIncompatible("To be supported")
053 RemovalListener<K0, V0> removalListener;
054
055 // No subclasses but our own
056 GenericMapMaker() {}
057
058 /**
059 * See {@link MapMaker#keyEquivalence}.
060 */
061 @GwtIncompatible("To be supported")
062 abstract GenericMapMaker<K0, V0> keyEquivalence(Equivalence<Object> equivalence);
063
064 /**
065 * See {@link MapMaker#valueEquivalence}.
066 */
067 @GwtIncompatible("To be supported")
068 abstract GenericMapMaker<K0, V0> valueEquivalence(Equivalence<Object> equivalence);
069
070 /**
071 * See {@link MapMaker#initialCapacity}.
072 */
073 public abstract GenericMapMaker<K0, V0> initialCapacity(int initialCapacity);
074
075 /**
076 * See {@link MapMaker#maximumSize}.
077 *
078 * @since 8.0
079 */
080 @Beta
081 @Deprecated
082 public abstract GenericMapMaker<K0, V0> maximumSize(int maximumSize);
083
084 /**
085 * See {@link MapMaker#strongKeys}.
086 */
087 abstract GenericMapMaker<K0, V0> strongKeys();
088
089 /**
090 * See {@link MapMaker#concurrencyLevel}.
091 */
092 public abstract GenericMapMaker<K0, V0> concurrencyLevel(int concurrencyLevel);
093
094 /**
095 * See {@link MapMaker#weakKeys}.
096 */
097 @GwtIncompatible("java.lang.ref.WeakReference")
098 public abstract GenericMapMaker<K0, V0> weakKeys();
099
100 /**
101 * See {@link MapMaker#strongValues}.
102 */
103 abstract GenericMapMaker<K0, V0> strongValues();
104
105 /**
106 * See {@link MapMaker#softKeys}.
107 */
108 @Deprecated
109 @GwtIncompatible("java.lang.ref.SoftReference")
110 public abstract GenericMapMaker<K0, V0> softKeys();
111
112 /**
113 * See {@link MapMaker#weakValues}.
114 */
115 @GwtIncompatible("java.lang.ref.WeakReference")
116 public abstract GenericMapMaker<K0, V0> weakValues();
117
118 /**
119 * See {@link MapMaker#softValues}.
120 */
121 @GwtIncompatible("java.lang.ref.SoftReference")
122 public abstract GenericMapMaker<K0, V0> softValues();
123
124 /**
125 * See {@link MapMaker#expiration}.
126 */
127 @Deprecated
128 public
129 abstract GenericMapMaker<K0, V0> expiration(long duration, TimeUnit unit);
130
131 /**
132 * See {@link MapMaker#expireAfterWrite}.
133 *
134 * @since 8.0
135 */
136 @Deprecated
137 public abstract GenericMapMaker<K0, V0> expireAfterWrite(long duration, TimeUnit unit);
138
139 /**
140 * See {@link MapMaker#expireAfterAccess}.
141 *
142 * @since 8.0
143 */
144 @GwtIncompatible("To be supported")
145 @Deprecated
146 public abstract GenericMapMaker<K0, V0> expireAfterAccess(long duration, TimeUnit unit);
147
148 /*
149 * Note that MapMaker's removalListener() is not here, because once you're interacting with a
150 * GenericMapMaker you've already called that, and shouldn't be calling it again.
151 */
152
153 @SuppressWarnings("unchecked") // safe covariant cast
154 @GwtIncompatible("To be supported")
155 <K extends K0, V extends V0> RemovalListener<K, V> getRemovalListener() {
156 return (RemovalListener<K, V>) Objects.firstNonNull(removalListener, NullListener.INSTANCE);
157 }
158
159 /**
160 * See {@link MapMaker#makeMap}.
161 */
162 public abstract <K extends K0, V extends V0> ConcurrentMap<K, V> makeMap();
163
164 /**
165 * See {@link MapMaker#makeCustomMap}.
166 */
167 @GwtIncompatible("CustomConcurrentHashMap")
168 abstract <K, V> CustomConcurrentHashMap<K, V> makeCustomMap();
169
170 /**
171 * See {@link MapMaker#makeComputingMap}.
172 */
173 @Deprecated
174 public abstract <K extends K0, V extends V0> ConcurrentMap<K, V> makeComputingMap(
175 Function<? super K, ? extends V> computingFunction);
176 }