1 /* 2 * Copyright (C) 2007 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 17 package com.google.common.collect; 18 19 import com.google.common.annotations.GwtCompatible; 20 21 import java.util.Map; 22 23 import javax.annotation.Nullable; 24 25 /** 26 * A map, each entry of which maps a Java 27 * <a href="http://tinyurl.com/2cmwkz">raw type</a> to an instance of that type. 28 * In addition to implementing {@code Map}, the additional type-safe operations 29 * {@link #putInstance} and {@link #getInstance} are available. 30 * 31 * <p>Like any other {@code Map<Class, Object>}, this map may contain entries 32 * for primitive types, and a primitive type and its corresponding wrapper type 33 * may map to different values. 34 * 35 * <p>See the Guava User Guide article on <a href= 36 * "http://code.google.com/p/guava-libraries/wiki/NewCollectionTypesExplained#ClassToInstanceMap"> 37 * {@code ClassToInstanceMap}</a>. 38 * 39 * <p>To map a generic type to an instance of that type, use {@link 40 * com.google.common.reflect.TypeToInstanceMap} instead. 41 * 42 * @param <B> the common supertype that all entries must share; often this is 43 * simply {@link Object} 44 * 45 * @author Kevin Bourrillion 46 * @since 2.0 (imported from Google Collections Library) 47 */ 48 @GwtCompatible 49 public interface ClassToInstanceMap<B> extends Map<Class<? extends B>, B> { 50 /** 51 * Returns the value the specified class is mapped to, or {@code null} if no 52 * entry for this class is present. This will only return a value that was 53 * bound to this specific class, not a value that may have been bound to a 54 * subtype. 55 */ getInstance(Class<T> type)56 <T extends B> T getInstance(Class<T> type); 57 58 /** 59 * Maps the specified class to the specified value. Does <i>not</i> associate 60 * this value with any of the class's supertypes. 61 * 62 * @return the value previously associated with this class (possibly {@code 63 * null}), or {@code null} if there was no previous entry. 64 */ putInstance(Class<T> type, @Nullable T value)65 <T extends B> T putInstance(Class<T> type, @Nullable T value); 66 } 67