public class DynamicSet<T>
extends java.lang.Object
implements java.lang.Iterable<T>
DynamicSets are always mapped as singletons in Guice. Sets store Providers internally, and resolve the provider to an instance on demand. This enables registrations to decide between singleton and non-singleton members.
Constructor and Description |
---|
DynamicSet() |
Modifier and Type | Method and Description |
---|---|
ReloadableRegistrationHandle<T> |
add(java.lang.String pluginName,
com.google.inject.Key<T> key,
com.google.inject.Provider<T> item)
Add one new element that may be hot-replaceable in the future.
|
RegistrationHandle |
add(java.lang.String pluginName,
com.google.inject.Provider<T> item)
Add one new element to the set.
|
RegistrationHandle |
add(java.lang.String pluginName,
T item)
Add one new element to the set.
|
static <T> com.google.inject.binder.LinkedBindingBuilder<T> |
bind(com.google.inject.Binder binder,
java.lang.Class<T> type)
Bind one implementation into the set using a unique annotation.
|
static <T> com.google.inject.binder.LinkedBindingBuilder<T> |
bind(com.google.inject.Binder binder,
java.lang.Class<T> type,
com.google.inject.name.Named name)
Bind a named implementation into the set.
|
static <T> com.google.inject.binder.LinkedBindingBuilder<T> |
bind(com.google.inject.Binder binder,
com.google.inject.TypeLiteral<T> type)
Bind one implementation into the set using a unique annotation.
|
static <T> com.google.inject.binder.LinkedBindingBuilder<T> |
bind(com.google.inject.Binder binder,
com.google.inject.TypeLiteral<T> type,
com.google.inject.name.Named name)
Bind a named implementation into the set.
|
com.google.common.collect.ImmutableSet<com.google.inject.Provider<T>> |
byPlugin(java.lang.String pluginName)
Get the items exported by a single plugin.
|
boolean |
contains(T item)
Returns
true if this set contains the given item. |
static <T> DynamicSet<T> |
emptySet() |
java.lang.Iterable<Extension<T>> |
entries() |
java.util.Iterator<T> |
iterator() |
com.google.common.collect.ImmutableSortedSet<java.lang.String> |
plugins()
Get the names of all running plugins supplying this type.
|
static <T> void |
setOf(com.google.inject.Binder binder,
java.lang.Class<T> member)
Declare a singleton
DynamicSet<T> with a binder. |
static <T> void |
setOf(com.google.inject.Binder binder,
com.google.inject.TypeLiteral<T> member)
Declare a singleton
DynamicSet<T> with a binder. |
public static <T> void setOf(com.google.inject.Binder binder, java.lang.Class<T> member)
DynamicSet<T>
with a binder.
Sets must be defined in a Guice module before they can be bound:
DynamicSet.setOf(binder(), Interface.class); DynamicSet.bind(binder(), Interface.class).to(Impl.class);
binder
- a new binder created in the module.member
- type of entry in the set.public static <T> void setOf(com.google.inject.Binder binder, com.google.inject.TypeLiteral<T> member)
DynamicSet<T>
with a binder.
Sets must be defined in a Guice module before they can be bound:
DynamicSet.setOf(binder(), new TypeLiteral<Thing<Foo>>() {});
binder
- a new binder created in the module.member
- type of entry in the set.public static <T> com.google.inject.binder.LinkedBindingBuilder<T> bind(com.google.inject.Binder binder, java.lang.Class<T> type)
binder
- a new binder created in the module.type
- type of entries in the set.public static <T> com.google.inject.binder.LinkedBindingBuilder<T> bind(com.google.inject.Binder binder, com.google.inject.TypeLiteral<T> type)
binder
- a new binder created in the module.type
- type of entries in the set.public static <T> com.google.inject.binder.LinkedBindingBuilder<T> bind(com.google.inject.Binder binder, java.lang.Class<T> type, com.google.inject.name.Named name)
binder
- a new binder created in the module.type
- type of entries in the set.name
- @Named
annotation to apply instead of a unique annotation.public static <T> com.google.inject.binder.LinkedBindingBuilder<T> bind(com.google.inject.Binder binder, com.google.inject.TypeLiteral<T> type, com.google.inject.name.Named name)
binder
- a new binder created in the module.type
- type of entries in the set.name
- @Named
annotation to apply instead of a unique annotation.public static <T> DynamicSet<T> emptySet()
public java.util.Iterator<T> iterator()
iterator
in interface java.lang.Iterable<T>
public boolean contains(T item)
true
if this set contains the given item.item
- item to check whether or not it is contained.true
if this set contains the given item.public com.google.common.collect.ImmutableSortedSet<java.lang.String> plugins()
public com.google.common.collect.ImmutableSet<com.google.inject.Provider<T>> byPlugin(java.lang.String pluginName)
pluginName
- name of the plugin.public RegistrationHandle add(java.lang.String pluginName, T item)
item
- the item to add to the collection. Must not be null.public RegistrationHandle add(java.lang.String pluginName, com.google.inject.Provider<T> item)
item
- the item to add to the collection. Must not be null.public ReloadableRegistrationHandle<T> add(java.lang.String pluginName, com.google.inject.Key<T> key, com.google.inject.Provider<T> item)
pluginName
- unique name of the plugin providing the item.key
- unique description from the item's Guice binding. This can be later obtained from
the registration handle to facilitate matching with the new equivalent instance during a
hot reload.item
- the item to add to the collection right now. Must not be null.