T - Type all classes in this instance must extendpublic final class ClassToInstanceStore<T>
extends java.lang.Object
| Constructor | Description |
|---|---|
ClassToInstanceStore() |
| Modifier and Type | Method | Description |
|---|---|---|
boolean |
containsKey(java.lang.Class<? extends T> clazz) |
Check if this store contains a mapping for a class.
|
<U extends T> |
getInstance(java.lang.Class<U> clazz) |
Get an instance from the store.
|
boolean |
isEmpty() |
Check if this store is empty.
|
java.util.Collection<java.lang.Class<? extends T>> |
keys() |
Get all keys of this store.
|
static <T> ClassToInstanceStore<T> |
of(T... instances) |
Create a new instance based on explicit instances.
|
void |
putAll(ClassToInstanceStore<? extends T> toCopy) |
Put all mappings from another instance.
|
<U extends T> |
putInstance(java.lang.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(java.lang.Class<U> clazz) |
Remove an instance from the store and return current value.
|
java.lang.String |
toString() |
Returns the toString on underlying map.
|
java.util.Collection<T> |
values() |
Get all values of this store.
|
@SafeVarargs public static <T> ClassToInstanceStore<T> of(T... instances)
T - type of the storeinstances - instances to add to the new storeputInstance(Object) for each of thempublic <U extends T> java.util.Optional<U> getInstance(java.lang.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> java.util.Optional<U> putInstance(java.lang.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> java.util.Optional<U> removeInstance(java.lang.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(java.lang.Class<? extends T> clazz)
clazz - class to checkpublic boolean isEmpty()
public <U extends T> java.util.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 java.util.Collection<T> values()
public java.util.Collection<java.lang.Class<? extends T>> keys()
public java.lang.String toString()
toString in class java.lang.ObjectCopyright © 2018, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.