All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.inject.multibindings.OptionalBinderBinding Maven / Gradle / Ivy

package com.google.inject.multibindings;

import com.google.inject.Binding;
import com.google.inject.Key;
import com.google.inject.spi.Element;
import com.google.inject.spi.Elements;
import java.util.Set;

/**
 * A binding for a OptionalBinder.
 *
 * 

Although OptionalBinders may be injected through a variety of types * {@code T}, {@code Optional}, {@code Optional>}, etc..), an * OptionalBinderBinding exists only on the Binding associated with the * {@code Optional} key. Other bindings can be validated to be derived from this * OptionalBinderBinding using {@link #containsElement}. * * @param The fully qualified type of the optional binding, including Optional. * For example: {@code Optional}. */ public interface OptionalBinderBinding { /** * Returns the {@link Key} for this binding. */ Key getKey(); /** * Returns the keys of other bindings that represent this OptionalBinder. This will return an * entry for {@code Optional>} and {@code * Optional>}. */ Set> getAlternateKeys(); /** * Returns the default binding (set by {@link OptionalBinder#setDefault}) if one exists or null * if no default binding is set. This will throw {@link UnsupportedOperationException} if it is * called on an element retrieved from {@link Elements#getElements}. *

* The Binding's type will always match the type Optional's generic type. For example, if getKey * returns a key of Optional<String>, then this will always return a * Binding<String>. */ Binding getDefaultBinding(); /** * Returns the actual binding (set by {@link OptionalBinder#setBinding}) or null if not set. * This will throw {@link UnsupportedOperationException} if it is called on an element retrieved * from {@link Elements#getElements}. *

* The Binding's type will always match the type Optional's generic type. For example, if getKey * returns a key of Optional<String>, then this will always return a * Binding<String>. */ Binding getActualBinding(); /** * Returns true if this OptionalBinder contains the given Element in order to build the optional * binding or uses the given Element in order to support building and injecting its data. This * will work for OptionalBinderBinding retrieved from an injector and * {@link Elements#getElements}. Usually this is only necessary if you are working with elements * retrieved from modules (without an Injector), otherwise {@link #getDefaultBinding} and * {@link #getActualBinding} are better options. */ boolean containsElement(Element element); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy