Class LazyEvaluationStore<T>
Object
LazyEvaluationStore<T>
- Type Parameters:
T
- item-type in the store
- All Implemented Interfaces:
NamedProvider<T>
,NamedProviderStore<T>
Lazily delays evaluating items until when they are first retrieved.
The StoreSupplier
is called only upon first retieval, and thereafter stored.
- Author:
- Owen Feehan
-
Constructor Summary
ConstructorsConstructorDescriptionLazyEvaluationStore
(String storeDisplayName) Creates a newLazyEvaluationStore
instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(String identifier, StoreSupplier<T> supplier) Adds an element to the store.getException
(String key) Retrieves the item if it exists, or throws an exception if it doesn't exist.getOptional
(String key) Retrieves the item if it exists, or returnsOptional.empty()
if it doesn't exist.keys()
Returns a set of keys associated with the provider.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.anchoranalysis.core.identifier.provider.NamedProvider
getArbitraryElement, isEmpty
-
Constructor Details
-
LazyEvaluationStore
Creates a newLazyEvaluationStore
instance.- Parameters:
storeDisplayName
- A user-friendly name to describe the store, when printing its contents in a string-representation.
-
-
Method Details
-
getException
Description copied from interface:NamedProvider
Retrieves the item if it exists, or throws an exception if it doesn't exist.- Specified by:
getException
in interfaceNamedProvider<T>
- Parameters:
key
- a unique name for the item.- Returns:
- the item
- Throws:
NamedProviderGetException
- if no item exists foridentifier
-
getOptional
Description copied from interface:NamedProvider
Retrieves the item if it exists, or returnsOptional.empty()
if it doesn't exist.Note that a 'key' might still throw an exception for another reason (but never because a particular key is absent).
- Specified by:
getOptional
in interfaceNamedProvider<T>
- Parameters:
key
- a unique name for the item.- Returns:
- the item, if it exists, otherwise
Optional.empty()
. - Throws:
NamedProviderGetException
- if no item exists foridentifier
.
-
keys
Description copied from interface:NamedProvider
Returns a set of keys associated with the provider.There's no guarantee that it refers to all valid keys.
- Specified by:
keys
in interfaceNamedProvider<T>
- Returns:
- a set of all keys associated with the provider.
-
add
Description copied from interface:NamedProviderStore
Adds an element to the store.- Specified by:
add
in interfaceNamedProviderStore<T>
- Parameters:
identifier
- a unique identifier for the element.supplier
- supplies the element to be added (which may be evaluated immediately, or a later point lazily).- Throws:
OperationFailedException
- if the identifier already exists, or otherwise the add operation fails.
-