T
- item-type in the storepublic class LazyEvaluationStore<T> extends Object implements NamedProviderStore<T>
The StoreSupplier
is called only upon first retieval, and thereafter stored.
Constructor and Description |
---|
LazyEvaluationStore(String storeDisplayName) |
Modifier and Type | Method and Description |
---|---|
void |
add(String identifier,
StoreSupplier<T> supplier)
Adds an element to the store.
|
T |
getException(String key)
Retrieves the item if it exists, or throws an exception if it doesn't exist.
|
Optional<T> |
getOptional(String key)
Retrieves the item if it exists, or returns
Optional.empty() if it doesn't exist. |
Set<String> |
keys()
Returns a set of keys associated with the provider.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getArbitraryElement, isEmpty
public LazyEvaluationStore(String storeDisplayName)
public T getException(String key) throws NamedProviderGetException
NamedProvider
getException
in interface NamedProvider<T>
key
- a unique name for the item.NamedProviderGetException
- if no item exists for identifier
public Optional<T> getOptional(String key) throws NamedProviderGetException
NamedProvider
Optional.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).
getOptional
in interface NamedProvider<T>
key
- a unique name for the item.Optional.empty()
.NamedProviderGetException
- if no item exists for identifier
.public Set<String> keys()
NamedProvider
There's no guarantee that it refers to all valid keys.
keys
in interface NamedProvider<T>
public void add(String identifier, StoreSupplier<T> supplier) throws OperationFailedException
NamedProviderStore
add
in interface NamedProviderStore<T>
identifier
- a unique identifier for the element.supplier
- supplies the element to be added (which may be evaluated immediately, or a
later point lazily).OperationFailedException
- if the identifier already exists, or otherwise the add
operation fails.Copyright © 2010–2023 Owen Feehan, ETH Zurich, University of Zurich, Hoffmann-La Roche. All rights reserved.