1090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/* 21d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Copyright (C) 2007 The Guava Authors 3090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * 4090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * Licensed under the Apache License, Version 2.0 (the "License"); 5090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * you may not use this file except in compliance with the License. 6090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * You may obtain a copy of the License at 7090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * 8090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * http://www.apache.org/licenses/LICENSE-2.0 9090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * 10090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * Unless required by applicable law or agreed to in writing, software 11090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS, 12090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * See the License for the specific language governing permissions and 14090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * limitations under the License. 15090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson */ 16090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson 17090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonpackage com.google.common.collect; 18090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson 19090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonimport com.google.common.annotations.GwtCompatible; 20090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson 21090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonimport java.util.Map; 22090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson 23090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonimport javax.annotation.Nullable; 24090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson 25090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/** 26090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * A map, each entry of which maps a Java 27090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * <a href="http://tinyurl.com/2cmwkz">raw type</a> to an instance of that type. 28090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * In addition to implementing {@code Map}, the additional type-safe operations 29090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * {@link #putInstance} and {@link #getInstance} are available. 30090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * 31090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * <p>Like any other {@code Map<Class, Object>}, this map may contain entries 32090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * for primitive types, and a primitive type and its corresponding wrapper type 33090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * may map to different values. 34090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * 35090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * @param <B> the common supertype that all entries must share; often this is 36090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * simply {@link Object} 37090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * 38090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * @author Kevin Bourrillion 391d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @since 2.0 (imported from Google Collections Library) 40090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson */ 41090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson@GwtCompatible 42090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonpublic interface ClassToInstanceMap<B> extends Map<Class<? extends B>, B> { 43090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson /** 44090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * Returns the value the specified class is mapped to, or {@code null} if no 45090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * entry for this class is present. This will only return a value that was 46090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * bound to this specific class, not a value that may have been bound to a 47090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * subtype. 48090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson */ 49090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson <T extends B> T getInstance(Class<T> type); 50090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson 51090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson /** 52090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * Maps the specified class to the specified value. Does <i>not</i> associate 53090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * this value with any of the class's supertypes. 54090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * 55090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * @return the value previously associated with this class (possibly {@code 56090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * null}), or {@code null} if there was no previous entry. 57090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson */ 58090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson <T extends B> T putInstance(Class<T> type, @Nullable T value); 59090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson} 60