Class NamedStacks

Object
NamedStacks
All Implemented Interfaces:
NamedProvider<Stack>, NamedProviderStore<Stack>

public class NamedStacks extends Object implements NamedProviderStore<Stack>
A set of image-stacks each with a name.
Author:
Owen Feehan
  • Constructor Details

    • NamedStacks

      public NamedStacks()
  • Method Details

    • add

      public void add(String identifier, Stack stack)
      Add a stack.
      Parameters:
      identifier - a unique name for the stack.
      stack - the stack to add.
    • add

      public void add(String identifier, StoreSupplier<Stack> supplier)
      Description copied from interface: NamedProviderStore
      Adds an element to the store.
      Specified by:
      add in interface NamedProviderStore<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

      public Optional<Stack> getOptional(String identifier) throws NamedProviderGetException
      Description copied from interface: NamedProvider
      Retrieves the item if it exists, or returns 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).

      Specified by:
      getOptional in interface NamedProvider<Stack>
      Parameters:
      identifier - a unique name for the item.
      Returns:
      the item, if it exists, otherwise Optional.empty().
      Throws:
      NamedProviderGetException - if no item exists for identifier.
    • keys

      public Set<String> 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 interface NamedProvider<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 each Stack 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 all Stacks have identical dimensions to this.
      Returns:
      a new NamedStacks with identical identifiers, but with each identifier mapping to the result of applying operation on the existing stack.
      Throws:
      OperationFailedException - if any of the dimensions do not match dimensions (if set) or if an error occurs when retrieving a stack.
    • addFrom

      public void addFrom(NamedProvider<Stack> source)
      Adds a Stack from a NamedProvider.
      Parameters:
      source - where to retrieve the stack and associated unique name.
    • addFromWithPrefix

      public void addFromWithPrefix(NamedProvider<Stack> source, String prefix)
      Like addFrom(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

      public NamedStacks subset(StringSet identifiersToInclude)
      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 new NamedStacks.
      Returns:
      the new NamedStacks.
    • forEach

      public <E extends Exception> void forEach(CheckedBiConsumer<String,StoreSupplier<Stack>,E> consumer) throws E
      Iterates over each entry in the map.
      Type Parameters:
      E - an exception that may be called by consumer.
      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