T - Type all classes in this instance must extendpublic final class ClassToInstanceStore<T> extends Object
| Constructor and Description |
|---|
ClassToInstanceStore() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
containsKey(Class<? extends T> clazz)
Check if this store contains a mapping for a class.
|
static <T> ClassToInstanceStore<T> |
create(T... instances)
Create a new instance based on explicit instances.
|
<U extends T> |
getInstance(Class<U> clazz)
Get an instance from the store.
|
boolean |
isEmpty()
Check if this store is empty.
|
Collection<Class<? extends T>> |
keys()
Get all keys of this store.
|
void |
putAll(ClassToInstanceStore<? extends T> toCopy)
Put all mappings from another instance.
|
<U extends T> |
putInstance(Class<? extends U> clazz,
U instance)
Put an explicit class to instance mapping.
|
<U extends T> |
putInstance(U instance)
Put an instance with implicit class mapping into this store.
|
<U extends T> |
removeInstance(Class<U> clazz)
Remove an instance from the store and return current value.
|
String |
toString()
Returns the toString on underlying map.
|
Collection<T> |
values()
Get all values of this store.
|
@SafeVarargs public static <T> ClassToInstanceStore<T> create(T... instances)
T - type of the storeinstances - instances to add to the new storeputInstance(Object) for each of thempublic <U extends T> Optional<U> getInstance(Class<U> clazz)
U - Type we are expectingclazz - Class under which we have created the mapping (String and CharSequence are two distinct mappings!)public <U extends T> Optional<U> putInstance(Class<? extends U> clazz, U instance)
U - Type we are expectingclazz - Class for which to create a mapping (String and CharSequence create two distinct mappings!)instance - Instance of the interface/classpublic <U extends T> Optional<U> removeInstance(Class<U> clazz)
U - Type of the objectclazz - Class of object to removepublic void putAll(ClassToInstanceStore<? extends T> toCopy)
toCopy - store to copy into this storepublic boolean containsKey(Class<? extends T> clazz)
clazz - class to checkpublic boolean isEmpty()
public <U extends T> Optional<U> putInstance(U instance)
putInstance(Class, Object) when
feasible as it provides more explicit mapping.
This is a helper method for instances obtained by other means or where we are sure of the class of the instance.U - Type of this instanceinstance - instance to map to its class (obtained through Object.getClass()public Collection<T> values()
public Collection<Class<? extends T>> keys()
Copyright © 2018, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.