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 17package com.google.common.collect; 18 19import com.google.common.annotations.Beta; 20import com.google.common.annotations.GwtCompatible; 21import com.google.common.annotations.GwtIncompatible; 22import com.google.common.base.Equivalence; 23import com.google.common.base.Function; 24import com.google.common.base.Objects; 25import com.google.common.collect.MapMaker.RemovalListener; 26import com.google.common.collect.MapMaker.RemovalNotification; 27 28import java.util.concurrent.ConcurrentMap; 29import 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 * @paramthe base type for all key types of maps built by this map maker 36 * @param the base type for all value types of maps built by this map maker 37 * @author Kevin Bourrillion 38 * @since 7.0 39 */ 40@Beta 41@GwtCompatible(emulated = true) 42public abstract class GenericMapMaker<K0, V0> { 43 @GwtIncompatible("To be supported") 44 enum NullListener implements RemovalListener<Object, Object> { 45 INSTANCE; 46 47 @Override 48 public void onRemoval(RemovalNotification<Object, Object> notification) {} 49 } 50 51 // Set by MapMaker, but sits in this class to preserve the type relationship 52 @GwtIncompatible("To be supported") 53 RemovalListener<K0, V0> removalListener; 54 55 // No subclasses but our own 56 GenericMapMaker() {} 57 58 /** 59 * See {@link MapMaker#keyEquivalence}. 60 */ 61 @GwtIncompatible("To be supported") 62 abstract GenericMapMaker<K0, V0> keyEquivalence(Equivalence<Object> equivalence); 63 64 /** 65 * See {@link MapMaker#valueEquivalence}. 66 */ 67 @GwtIncompatible("To be supported") 68 abstract GenericMapMaker<K0, V0> valueEquivalence(Equivalence<Object> equivalence); 69 70 /** 71 * See {@link MapMaker#initialCapacity}. 72 */ 73 public abstract GenericMapMaker<K0, V0> initialCapacity(int initialCapacity); 74 75 /** 76 * See {@link MapMaker#maximumSize}. 77 */ 78 abstract GenericMapMaker<K0, V0> maximumSize(int maximumSize); 79 80 /** 81 * See {@link MapMaker#strongKeys}. 82 */ 83 abstract GenericMapMaker<K0, V0> strongKeys(); 84 85 /** 86 * See {@link MapMaker#concurrencyLevel}. 87 */ 88 public abstract GenericMapMaker<K0, V0> concurrencyLevel(int concurrencyLevel); 89 90 /** 91 * See {@link MapMaker#weakKeys}. 92 */ 93 @GwtIncompatible("java.lang.ref.WeakReference") 94 public abstract GenericMapMaker<K0, V0> weakKeys(); 95 96 /** 97 * See {@link MapMaker#strongValues}. 98 */ 99 abstract GenericMapMaker<K0, V0> strongValues(); 100 101 /** 102 * See {@link MapMaker#softKeys}. 103 */ 104 @Deprecated 105 @GwtIncompatible("java.lang.ref.SoftReference") 106 public abstract GenericMapMaker<K0, V0> softKeys(); 107 108 /** 109 * See {@link MapMaker#weakValues}. 110 */ 111 @GwtIncompatible("java.lang.ref.WeakReference") 112 public abstract GenericMapMaker<K0, V0> weakValues(); 113 114 /** 115 * See {@link MapMaker#softValues}. 116 */ 117 @GwtIncompatible("java.lang.ref.SoftReference") 118 public abstract GenericMapMaker<K0, V0> softValues(); 119 120 /** 121 * See {@link MapMaker#expiration}. 122 */ 123 @Deprecated 124 public 125 abstract GenericMapMaker<K0, V0> expiration(long duration, TimeUnit unit); 126 127 /** 128 * See {@link MapMaker#expireAfterWrite}. 129 */ 130 abstract GenericMapMaker<K0, V0> expireAfterWrite(long duration, TimeUnit unit); 131 132 /** 133 * See {@link MapMaker#expireAfterAccess}. 134 */ 135 @GwtIncompatible("To be supported") 136 abstract GenericMapMaker<K0, V0> expireAfterAccess(long duration, TimeUnit unit); 137 138 /* 139 * Note that MapMaker's removalListener() is not here, because once you're interacting with a 140 * GenericMapMaker you've already called that, and shouldn't be calling it again. 141 */ 142 143 @SuppressWarnings("unchecked") // safe covariant cast 144 @GwtIncompatible("To be supported") 145 <K extends K0, V extends V0> RemovalListener<K, V> getRemovalListener() { 146 return (RemovalListener<K, V>) Objects.firstNonNull(removalListener, NullListener.INSTANCE); 147 } 148 149 /** 150 * See {@link MapMaker#makeMap}. 151 */ 152 public abstract <K extends K0, V extends V0> ConcurrentMap<K, V> makeMap(); 153 154 /** 155 * See {@link MapMaker#makeCustomMap}. 156 */ 157 @GwtIncompatible("MapMakerInternalMap") 158 abstract <K, V> MapMakerInternalMap<K, V> makeCustomMap(); 159 160 /** 161 * See {@link MapMaker#makeComputingMap}. 162 */ 163 @Deprecated 164 public abstract <K extends K0, V extends V0> ConcurrentMap<K, V> makeComputingMap( 165 Function<? super K, ? extends V> computingFunction); 166} 167