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 17package com.google.common.collect; 18 19import com.google.common.annotations.GwtCompatible; 20 21import java.util.Map; 22 23import 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 * @param <B> the common supertype that all entries must share; often this is 36 * simply {@link Object} 37 * 38 * @author Kevin Bourrillion 39 * @since 2.0 (imported from Google Collections Library) 40 */ 41@GwtCompatible 42public interface ClassToInstanceMap<B> extends Map<Class<? extends B>, B> { 43 /** 44 * Returns the value the specified class is mapped to, or {@code null} if no 45 * entry for this class is present. This will only return a value that was 46 * bound to this specific class, not a value that may have been bound to a 47 * subtype. 48 */ 49 <T extends B> T getInstance(Class<T> type); 50 51 /** 52 * Maps the specified class to the specified value. Does <i>not</i> associate 53 * this value with any of the class's supertypes. 54 * 55 * @return the value previously associated with this class (possibly {@code 56 * null}), or {@code null} if there was no previous entry. 57 */ 58 <T extends B> T putInstance(Class<T> type, @Nullable T value); 59} 60