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 public void onRemoval(RemovalNotification<Object, Object> notification) {}
048 }
049
050 // Set by MapMaker, but sits in this class to preserve the type relationship
051 @GwtIncompatible("To be supported")
052 RemovalListener<K0, V0> removalListener;
053
054 // No subclasses but our own
055 GenericMapMaker() {}
056
057 /**
058 * See {@link MapMaker#keyEquivalence}.
059 */
060 @GwtIncompatible("To be supported")
061 abstract GenericMapMaker<K0, V0> keyEquivalence(Equivalence<Object> equivalence);
062
063 /**
064 * See {@link MapMaker#initialCapacity}.
065 */
066 public abstract GenericMapMaker<K0, V0> initialCapacity(int initialCapacity);
067
068 /**
069 * See {@link MapMaker#maximumSize}.
070 */
071 abstract GenericMapMaker<K0, V0> maximumSize(int maximumSize);
072
073 /**
074 * See {@link MapMaker#concurrencyLevel}.
075 */
076 public abstract GenericMapMaker<K0, V0> concurrencyLevel(int concurrencyLevel);
077
078 /**
079 * See {@link MapMaker#weakKeys}.
080 */
081 @GwtIncompatible("java.lang.ref.WeakReference")
082 public abstract GenericMapMaker<K0, V0> weakKeys();
083
084 /**
085 * See {@link MapMaker#softKeys}.
086 */
087 @Deprecated
088 @GwtIncompatible("java.lang.ref.SoftReference")
089 public abstract GenericMapMaker<K0, V0> softKeys();
090
091 /**
092 * See {@link MapMaker#weakValues}.
093 */
094 @GwtIncompatible("java.lang.ref.WeakReference")
095 public abstract GenericMapMaker<K0, V0> weakValues();
096
097 /**
098 * See {@link MapMaker#softValues}.
099 */
100 @GwtIncompatible("java.lang.ref.SoftReference")
101 public abstract GenericMapMaker<K0, V0> softValues();
102
103 /**
104 * See {@link MapMaker#expireAfterWrite}.
105 */
106 abstract GenericMapMaker<K0, V0> expireAfterWrite(long duration, TimeUnit unit);
107
108 /**
109 * See {@link MapMaker#expireAfterAccess}.
110 */
111 @GwtIncompatible("To be supported")
112 abstract GenericMapMaker<K0, V0> expireAfterAccess(long duration, TimeUnit unit);
113
114 /*
115 * Note that MapMaker's removalListener() is not here, because once you're interacting with a
116 * GenericMapMaker you've already called that, and shouldn't be calling it again.
117 */
118
119 @SuppressWarnings("unchecked") // safe covariant cast
120 @GwtIncompatible("To be supported")
121 <K extends K0, V extends V0> RemovalListener<K, V> getRemovalListener() {
122 return (RemovalListener<K, V>) Objects.firstNonNull(removalListener, NullListener.INSTANCE);
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#makeCustomMap}.
132 */
133 @GwtIncompatible("MapMakerInternalMap")
134 abstract <K, V> MapMakerInternalMap<K, V> makeCustomMap();
135
136 /**
137 * See {@link MapMaker#makeComputingMap}.
138 */
139 @Deprecated
140 public abstract <K extends K0, V extends V0> ConcurrentMap<K, V> makeComputingMap(
141 Function<? super K, ? extends V> computingFunction);
142 }