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#initialCapacity}. 066 */ 067 public abstract GenericMapMaker<K0, V0> initialCapacity(int initialCapacity); 068 069 /** 070 * See {@link MapMaker#maximumSize}. 071 */ 072 abstract GenericMapMaker<K0, V0> maximumSize(int maximumSize); 073 074 /** 075 * See {@link MapMaker#concurrencyLevel}. 076 */ 077 public abstract GenericMapMaker<K0, V0> concurrencyLevel(int concurrencyLevel); 078 079 /** 080 * See {@link MapMaker#weakKeys}. 081 */ 082 @GwtIncompatible("java.lang.ref.WeakReference") 083 public abstract GenericMapMaker<K0, V0> weakKeys(); 084 085 /** 086 * See {@link MapMaker#softKeys}. 087 */ 088 @Deprecated 089 @GwtIncompatible("java.lang.ref.SoftReference") 090 public abstract GenericMapMaker<K0, V0> softKeys(); 091 092 /** 093 * See {@link MapMaker#weakValues}. 094 */ 095 @GwtIncompatible("java.lang.ref.WeakReference") 096 public abstract GenericMapMaker<K0, V0> weakValues(); 097 098 /** 099 * See {@link MapMaker#softValues}. 100 */ 101 @GwtIncompatible("java.lang.ref.SoftReference") 102 public abstract GenericMapMaker<K0, V0> softValues(); 103 104 /** 105 * See {@link MapMaker#expireAfterWrite}. 106 */ 107 abstract GenericMapMaker<K0, V0> expireAfterWrite(long duration, TimeUnit unit); 108 109 /** 110 * See {@link MapMaker#expireAfterAccess}. 111 */ 112 @GwtIncompatible("To be supported") 113 abstract GenericMapMaker<K0, V0> expireAfterAccess(long duration, TimeUnit unit); 114 115 /* 116 * Note that MapMaker's removalListener() is not here, because once you're interacting with a 117 * GenericMapMaker you've already called that, and shouldn't be calling it again. 118 */ 119 120 @SuppressWarnings("unchecked") // safe covariant cast 121 @GwtIncompatible("To be supported") 122 <K extends K0, V extends V0> RemovalListener<K, V> getRemovalListener() { 123 return (RemovalListener<K, V>) Objects.firstNonNull(removalListener, NullListener.INSTANCE); 124 } 125 126 /** 127 * See {@link MapMaker#makeMap}. 128 */ 129 public abstract <K extends K0, V extends V0> ConcurrentMap<K, V> makeMap(); 130 131 /** 132 * See {@link MapMaker#makeCustomMap}. 133 */ 134 @GwtIncompatible("MapMakerInternalMap") 135 abstract <K, V> MapMakerInternalMap<K, V> makeCustomMap(); 136 137 /** 138 * See {@link MapMaker#makeComputingMap}. 139 */ 140 @Deprecated 141 public abstract <K extends K0, V extends V0> ConcurrentMap<K, V> makeComputingMap( 142 Function<? super K, ? extends V> computingFunction); 143 }