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
017package com.google.common.collect;
018
019import com.google.common.annotations.Beta;
020import com.google.common.annotations.GwtCompatible;
021import com.google.common.annotations.GwtIncompatible;
022import com.google.common.base.Equivalence;
023import com.google.common.base.Function;
024import com.google.common.base.Objects;
025import com.google.common.collect.MapMaker.RemovalListener;
026import com.google.common.collect.MapMaker.RemovalNotification;
027
028import java.util.concurrent.ConcurrentMap;
029import 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 * @deprecated This class existed only to support the generic paramterization necessary for the
040 *     caching functionality in {@code MapMaker}. That functionality has been moved to {@link
041 *     com.google.common.cache.CacheBuilder}, which is a properly generified class and thus needs no
042 *     "Generic" equivalent; simple use {@code CacheBuilder} naturally. For general migration
043 *     instructions, see the <a
044 *     href="http://code.google.com/p/guava-libraries/wiki/MapMakerMigration">MapMaker Migration
045 *     Guide</a>. This class is scheduled for removal in Guava 16.0.
046 */
047@Beta
048@Deprecated
049@GwtCompatible(emulated = true)
050public abstract class GenericMapMaker<K0, V0> {
051  @GwtIncompatible("To be supported")
052  enum NullListener implements RemovalListener<Object, Object> {
053    INSTANCE;
054
055    @Override
056    public void onRemoval(RemovalNotification<Object, Object> notification) {}
057  }
058
059  // Set by MapMaker, but sits in this class to preserve the type relationship
060  @GwtIncompatible("To be supported")
061  RemovalListener<K0, V0> removalListener;
062
063  // No subclasses but our own
064  GenericMapMaker() {}
065
066  /**
067   * See {@link MapMaker#keyEquivalence}.
068   */
069  @GwtIncompatible("To be supported")
070  abstract GenericMapMaker<K0, V0> keyEquivalence(Equivalence<Object> equivalence);
071
072  /**
073   * See {@link MapMaker#initialCapacity}.
074   */
075  public abstract GenericMapMaker<K0, V0> initialCapacity(int initialCapacity);
076
077  /**
078   * See {@link MapMaker#maximumSize}.
079   */
080  abstract GenericMapMaker<K0, V0> maximumSize(int maximumSize);
081
082  /**
083   * See {@link MapMaker#concurrencyLevel}.
084   */
085  public abstract GenericMapMaker<K0, V0> concurrencyLevel(int concurrencyLevel);
086
087  /**
088   * See {@link MapMaker#weakKeys}.
089   */
090  @GwtIncompatible("java.lang.ref.WeakReference")
091  public abstract GenericMapMaker<K0, V0> weakKeys();
092
093  /**
094   * See {@link MapMaker#weakValues}.
095   */
096  @GwtIncompatible("java.lang.ref.WeakReference")
097  public abstract GenericMapMaker<K0, V0> weakValues();
098
099  /**
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 deletion in August 2014.</b>
107   */
108  @Deprecated
109  @GwtIncompatible("java.lang.ref.SoftReference")
110  public abstract GenericMapMaker<K0, V0> softValues();
111
112  /**
113   * See {@link MapMaker#expireAfterWrite}.
114   */
115  abstract GenericMapMaker<K0, V0> expireAfterWrite(long duration, TimeUnit unit);
116
117  /**
118   * See {@link MapMaker#expireAfterAccess}.
119   */
120  @GwtIncompatible("To be supported")
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")
130  <K extends K0, V extends V0> RemovalListener<K, V> getRemovalListener() {
131    return (RemovalListener<K, V>) Objects.firstNonNull(removalListener, NullListener.INSTANCE);
132  }
133
134  /**
135   * See {@link MapMaker#makeMap}.
136   */
137  public abstract <K extends K0, V extends V0> ConcurrentMap<K, V> makeMap();
138
139  /**
140   * See {@link MapMaker#makeCustomMap}.
141   */
142  @GwtIncompatible("MapMakerInternalMap")
143  abstract <K, V> MapMakerInternalMap<K, V> makeCustomMap();
144
145  /**
146   * See {@link MapMaker#makeComputingMap}.
147   */
148  @Deprecated
149  abstract <K extends K0, V extends V0> ConcurrentMap<K, V> makeComputingMap(
150      Function<? super K, ? extends V> computingFunction);
151}