1 /*
2  * Copyright (C) 2010 The Guava Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS-IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.common.collect;
18 
19 import com.google.common.annotations.Beta;
20 import com.google.common.annotations.GwtCompatible;
21 import com.google.common.annotations.GwtIncompatible;
22 import com.google.common.base.Equivalence;
23 import com.google.common.base.Function;
24 import com.google.common.base.MoreObjects;
25 import com.google.common.collect.MapMaker.RemovalListener;
26 import com.google.common.collect.MapMaker.RemovalNotification;
27 
28 import java.util.concurrent.ConcurrentMap;
29 import java.util.concurrent.TimeUnit;
30 
31 /**
32  * A class exactly like {@link MapMaker}, except restricted in the types of maps it can build.
33  * For the most part, you should probably just ignore the existence of this class.
34  *
35  * @param <K0> the base type for all key types of maps built by this map maker
36  * @param <V0> the base type for all value types of maps built by this map maker
37  * @author Kevin Bourrillion
38  * @since 7.0
39  * @deprecated This class existed only to support the generic paramterization necessary for the
40  *     caching functionality in {@code MapMaker}. That functionality has been moved to {@link
41  *     com.google.common.cache.CacheBuilder}, which is a properly generified class and thus needs no
42  *     "Generic" equivalent; simple use {@code CacheBuilder} naturally. For general migration
43  *     instructions, see the <a
44  *     href="http://code.google.com/p/guava-libraries/wiki/MapMakerMigration">MapMaker Migration
45  *     Guide</a>.
46  */
47 @Beta
48 @Deprecated
49 @GwtCompatible(emulated = true)
50 abstract class GenericMapMaker<K0, V0> {
51   @GwtIncompatible("To be supported")
52   enum NullListener implements RemovalListener<Object, Object> {
53     INSTANCE;
54 
55     @Override
onRemoval(RemovalNotification<Object, Object> notification)56     public void onRemoval(RemovalNotification<Object, Object> notification) {}
57   }
58 
59   // Set by MapMaker, but sits in this class to preserve the type relationship
60   @GwtIncompatible("To be supported")
61   RemovalListener<K0, V0> removalListener;
62 
63   // No subclasses but our own
GenericMapMaker()64   GenericMapMaker() {}
65 
66   /**
67    * See {@link MapMaker#keyEquivalence}.
68    */
69   @GwtIncompatible("To be supported")
keyEquivalence(Equivalence<Object> equivalence)70   abstract GenericMapMaker<K0, V0> keyEquivalence(Equivalence<Object> equivalence);
71 
72   /**
73    * See {@link MapMaker#initialCapacity}.
74    */
initialCapacity(int initialCapacity)75   public abstract GenericMapMaker<K0, V0> initialCapacity(int initialCapacity);
76 
77   /**
78    * See {@link MapMaker#maximumSize}.
79    */
maximumSize(int maximumSize)80   abstract GenericMapMaker<K0, V0> maximumSize(int maximumSize);
81 
82   /**
83    * See {@link MapMaker#concurrencyLevel}.
84    */
concurrencyLevel(int concurrencyLevel)85   public abstract GenericMapMaker<K0, V0> concurrencyLevel(int concurrencyLevel);
86 
87   /**
88    * See {@link MapMaker#weakKeys}.
89    */
90   @GwtIncompatible("java.lang.ref.WeakReference")
weakKeys()91   public abstract GenericMapMaker<K0, V0> weakKeys();
92 
93   /**
94    * See {@link MapMaker#weakValues}.
95    */
96   @GwtIncompatible("java.lang.ref.WeakReference")
weakValues()97   public abstract GenericMapMaker<K0, V0> weakValues();
98 
99   /**
100    * See {@link MapMaker#softValues}.
101    *
102    * @deprecated Caching functionality in {@code MapMaker} has been moved to {@link
103    *     com.google.common.cache.CacheBuilder}, with {@link #softValues} being replaced by {@link
104    *     com.google.common.cache.CacheBuilder#softValues}. Note that {@code CacheBuilder} is simply
105    *     an enhanced API for an implementation which was branched from {@code MapMaker}. <b>This
106    *     method is scheduled for removal in March 2015.</b>
107    */
108   @Deprecated
109   @GwtIncompatible("java.lang.ref.SoftReference")
softValues()110   public abstract GenericMapMaker<K0, V0> softValues();
111 
112   /**
113    * See {@link MapMaker#expireAfterWrite}.
114    */
expireAfterWrite(long duration, TimeUnit unit)115   abstract GenericMapMaker<K0, V0> expireAfterWrite(long duration, TimeUnit unit);
116 
117   /**
118    * See {@link MapMaker#expireAfterAccess}.
119    */
120   @GwtIncompatible("To be supported")
expireAfterAccess(long duration, TimeUnit unit)121   abstract GenericMapMaker<K0, V0> expireAfterAccess(long duration, TimeUnit unit);
122 
123   /*
124    * Note that MapMaker's removalListener() is not here, because once you're interacting with a
125    * GenericMapMaker you've already called that, and shouldn't be calling it again.
126    */
127 
128   @SuppressWarnings("unchecked") // safe covariant cast
129   @GwtIncompatible("To be supported")
getRemovalListener()130   <K extends K0, V extends V0> RemovalListener<K, V> getRemovalListener() {
131     return (RemovalListener<K, V>) MoreObjects.firstNonNull(removalListener, NullListener.INSTANCE);
132   }
133 
134   /**
135    * See {@link MapMaker#makeMap}.
136    */
makeMap()137   public abstract <K extends K0, V extends V0> ConcurrentMap<K, V> makeMap();
138 
139   /**
140    * See {@link MapMaker#makeCustomMap}.
141    */
142   @GwtIncompatible("MapMakerInternalMap")
makeCustomMap()143   abstract <K, V> MapMakerInternalMap<K, V> makeCustomMap();
144 
145   /**
146    * See {@link MapMaker#makeComputingMap}.
147    */
148   @Deprecated
makeComputingMap( Function<? super K, ? extends V> computingFunction)149   abstract <K extends K0, V extends V0> ConcurrentMap<K, V> makeComputingMap(
150       Function<? super K, ? extends V> computingFunction);
151 }
152