public class NamedStacks extends Object implements NamedProviderStore<Stack>
Constructor and Description |
---|
NamedStacks() |
Modifier and Type | Method and Description |
---|---|
void |
add(String identifier,
Stack stack)
Add a stack.
|
void |
add(String identifier,
StoreSupplier<Stack> supplier)
Adds an element to the store.
|
void |
addFrom(NamedProvider<Stack> source)
Adds a
Stack from a NamedProvider . |
void |
addFromWithPrefix(NamedProvider<Stack> source,
String prefix)
Like
addFrom(NamedProvider) but additionally adds a prefix to the name when adding. |
NamedStacks |
applyOperation(java.util.function.UnaryOperator<Stack> operation,
Optional<Dimensions> dimensions)
Applies an operation on each
Stack in the collection and returns a new derived
collection. |
<E extends Exception> |
forEach(CheckedBiConsumer<String,StoreSupplier<Stack>,E> consumer)
Iterates over each entry in the map.
|
Optional<Stack> |
getOptional(String identifier)
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.
|
int |
size()
Number of stacks.
|
NamedStacks |
subset(StringSet identifiersToInclude)
Creates a new collection containing only items whose keys exist in a particular set.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getArbitraryElement, getException, isEmpty
public void add(String identifier, Stack stack)
identifier
- a unique name for the stack.stack
- the stack to add.public void add(String identifier, StoreSupplier<Stack> supplier)
NamedProviderStore
add
in interface NamedProviderStore<Stack>
identifier
- a unique identifier for the element.supplier
- supplies the element to be added (which may be evaluated immediately, or a
later point lazily).public Optional<Stack> getOptional(String identifier) 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<Stack>
identifier
- 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<Stack>
public NamedStacks applyOperation(java.util.function.UnaryOperator<Stack> operation, Optional<Dimensions> dimensions) throws OperationFailedException
Stack
in the collection and returns a new derived
collection.operation
- the operation to apply to each stack.dimensions
- if set, a check occurs that all Stack
s have identical dimensions to
this.NamedStacks
with identical identifiers, but with each identifier
mapping to the result of applying operation
on the existing stack.OperationFailedException
- if any of the dimensions do not match dimensions
(if
set) or if an error occurs when retrieving a stack.public void addFrom(NamedProvider<Stack> source)
Stack
from a NamedProvider
.source
- where to retrieve the stack and associated unique name.public void addFromWithPrefix(NamedProvider<Stack> source, String prefix)
addFrom(NamedProvider)
but additionally adds a prefix to the name when adding.source
- where to retrieve the stack and associated unique name.prefix
- the prefix to place before the name.public NamedStacks subset(StringSet identifiersToInclude)
identifiersToInclude
- only stacks whose identifiers exist in this set are included in
the new NamedStacks
.NamedStacks
.public <E extends Exception> void forEach(CheckedBiConsumer<String,StoreSupplier<Stack>,E> consumer) throws E extends Exception
E
- an exception that may be called by consumer
.consumer
- this consumer is called the name and stack-supplier for each entry in the
map.E
- if the consumer throws the exception.E extends Exception
public int size()
Copyright © 2010–2023 Owen Feehan, ETH Zurich, University of Zurich, Hoffmann-La Roche. All rights reserved.