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 TypeMethodDescriptionvoidadd(String identifier, StoreSupplier<Stack> supplier) Adds an element to the store.voidAdd a stack.voidaddFrom(NamedProvider<Stack> source) Adds aStackfrom aNamedProvider.voidaddFromWithPrefix(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 eachStackin 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.intsize()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, waitMethods 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:NamedProviderStoreAdds an element to the store.- Specified by:
addin 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:NamedProviderRetrieves 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:
getOptionalin 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:NamedProviderReturns a set of keys associated with the provider.There's no guarantee that it refers to all valid keys.
- Specified by:
keysin 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 eachStackin the collection and returns a new derived collection.- Parameters:
operation- the operation to apply to each stack.dimensions- if set, a check occurs that allStacks have identical dimensions to this.- Returns:
- a new
NamedStackswith identical identifiers, but with each identifier mapping to the result of applyingoperationon 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 aStackfrom 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
-