Class NamedStacks
Object
NamedStacks
- All Implemented Interfaces:
NamedProvider<Stack>
,NamedProviderStore<Stack>
A set of image-stacks each with a name.
- Author:
- Owen Feehan
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(String identifier, StoreSupplier<Stack> supplier) Adds an element to the store.void
Add a stack.void
addFrom
(NamedProvider<Stack> source) Adds aStack
from aNamedProvider
.void
addFromWithPrefix
(NamedProvider<Stack> source, String prefix) LikeaddFrom(NamedProvider)
but additionally adds a prefix to the name when adding.applyOperation
(UnaryOperator<Stack> operation, Optional<Dimensions> dimensions) Applies an operation on eachStack
in the collection and returns a new derived collection.<E extends Exception>
voidforEach
(CheckedBiConsumer<String, StoreSupplier<Stack>, E> consumer) Iterates over each entry in the map.getOptional
(String identifier) Retrieves the item if it exists, or returnsOptional.empty()
if it doesn't exist.keys()
Returns a set of keys associated with the provider.int
size()
Number of stacks.Creates a new collection containing only items whose keys exist in a particular set.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, getException, isEmpty
-
Constructor Details
-
NamedStacks
public NamedStacks()
-
-
Method Details
-
add
Add a stack.- Parameters:
identifier
- a unique name for the stack.stack
- the stack to add.
-
add
Description copied from interface:NamedProviderStore
Adds an element to the store.- Specified by:
add
in interfaceNamedProviderStore<Stack>
- 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).
-
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<Stack>
- Parameters:
identifier
- 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<Stack>
- Returns:
- a set of all keys associated with the provider.
-
applyOperation
public NamedStacks applyOperation(UnaryOperator<Stack> operation, Optional<Dimensions> dimensions) throws OperationFailedException Applies an operation on eachStack
in the collection and returns a new derived collection.- Parameters:
operation
- the operation to apply to each stack.dimensions
- if set, a check occurs that allStack
s have identical dimensions to this.- Returns:
- a new
NamedStacks
with identical identifiers, but with each identifier mapping to the result of applyingoperation
on the existing stack. - Throws:
OperationFailedException
- if any of the dimensions do not matchdimensions
(if set) or if an error occurs when retrieving a stack.
-
addFrom
Adds aStack
from aNamedProvider
.- Parameters:
source
- where to retrieve the stack and associated unique name.
-
addFromWithPrefix
LikeaddFrom(NamedProvider)
but additionally adds a prefix to the name when adding.- Parameters:
source
- where to retrieve the stack and associated unique name.prefix
- the prefix to place before the name.
-
subset
Creates a new collection containing only items whose keys exist in a particular set.- Parameters:
identifiersToInclude
- only stacks whose identifiers exist in this set are included in the newNamedStacks
.- Returns:
- the new
NamedStacks
.
-
forEach
public <E extends Exception> void forEach(CheckedBiConsumer<String, StoreSupplier<Stack>, throws EE> consumer) Iterates over each entry in the map.- Type Parameters:
E
- an exception that may be called byconsumer
.- Parameters:
consumer
- this consumer is called the name and stack-supplier for each entry in the map.- Throws:
E
- if the consumer throws the exception.
-
size
public int size()Number of stacks.- Returns:
- the number of stacks
-