java.lang.Object
io.helidon.security.ClassToInstanceStore<T>
- Type Parameters:
T
- Type all classes in this instance must extend
Map of classes to their instances.
This class is mutable and not thread safe.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
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.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.putInstance
(Class<? extends U> clazz, U instance) Put an explicit class to instance mapping.putInstance
(U instance) Put an instance with implicit class mapping into this store.removeInstance
(Class<U> clazz) Remove an instance from the store and return current value.toString()
Returns the toString on underlying map.values()
Get all values of this store.
-
Constructor Details
-
ClassToInstanceStore
public ClassToInstanceStore()
-
-
Method Details
-
create
Create a new instance based on explicit instances. This method creates a MUTABLE instance (contrary to such methods on java collections).- Type Parameters:
T
- type of the store- Parameters:
instances
- instances to add to the new store- Returns:
- new store with instances inserted as when calling
putInstance(Object)
for each of them
-
getInstance
Get an instance from the store.- Type Parameters:
U
- Type we are expecting- Parameters:
clazz
- Class under which we have created the mapping (String and CharSequence are two distinct mappings!)- Returns:
- Instance of the class or null if no mapping exists
-
putInstance
Put an explicit class to instance mapping.- Type Parameters:
U
- Type we are expecting- Parameters:
clazz
- Class for which to create a mapping (String and CharSequence create two distinct mappings!)instance
- Instance of the interface/class- Returns:
- Instance of the class if a mapping previously existed or null for no existing mapping
-
removeInstance
Remove an instance from the store and return current value.- Type Parameters:
U
- Type of the object- Parameters:
clazz
- Class of object to remove- Returns:
- instance that was removed (if there was one)
-
putAll
Put all mappings from another instance.- Parameters:
toCopy
- store to copy into this store
-
containsKey
Check if this store contains a mapping for a class.- Parameters:
clazz
- class to check- Returns:
- true if there is a mapping for the class
-
isEmpty
public boolean isEmpty()Check if this store is empty.- Returns:
- true if there are no mappings in this store
-
putInstance
Put an instance with implicit class mapping into this store. Please useputInstance(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.- Type Parameters:
U
- Type of this instance- Parameters:
instance
- instance to map to its class (obtained throughObject.getClass()
- Returns:
- existing value for the class of this instance
-
values
Get all values of this store.- Returns:
- collection of values
-
keys
Get all keys of this store.- Returns:
- collection of classes used for mapping to instances
-
toString
Returns the toString on underlying map.
-