Class GroupMapByName<S,​T>

Object
org.anchoranalysis.plugin.image.task.grouped.GroupMapByName<S,​T>
Type Parameters:
S - single item type
T - aggregator type

public abstract class GroupMapByName<S,​T>
extends Object
Adds items to aggregate structures identified uniquely by a name, and allows these items to be later outputted.

If any of the MultiName have a higher level aggregation-key, this is used to partition the output at the end into sub-directories.

Author:
Owen Feehan
  • Constructor Details

    • GroupMapByName

      protected GroupMapByName​(String nounT, Optional<Stream<String>> groupIdentifiers, Optional<org.anchoranalysis.io.output.outputter.InputOutputContext> outputContext, Supplier<T> createAggregator, org.anchoranalysis.core.functional.checked.CheckedBiConsumer<S,​T,​org.anchoranalysis.core.exception.OperationFailedException> addSingleToAggregator)
      Creates a group-map.
      Parameters:
      nounT - a word to describe a single instance of T in user error messages.
      groupIdentifiers - a stream with each group-identifier that should be added to the map.
      outputContext - the subdirectory to output into. If not set, no outputs occur.
      createAggregator - called to create a new aggregator, whenever needed e.g. for a particular group.
      addSingleToAggregator - adds a single-item into an aggregator.
  • Method Details

    • add

      public void add​(Optional<String> groupIdentifier, List<org.apache.commons.math3.util.Pair<String,​S>> singleItemsToAdd) throws org.anchoranalysis.core.exception.OperationFailedException
      Adds an item with a non-group identifier, and also optionally a group identifier.
      Parameters:
      groupIdentifier - optional group identifier.
      singleItemsToAdd - the single-items to add, each with a corresponding non-group name.
      Throws:
      org.anchoranalysis.core.exception.OperationFailedException - if the operation cannot successfully complete.
    • outputAnyRemainingGroups

      public void outputAnyRemainingGroups() throws org.anchoranalysis.core.exception.OperationFailedException
      Outputs any groups that have not already been outputted.
      Throws:
      org.anchoranalysis.core.exception.OperationFailedException - if thrown by the outputting.
    • outputGroupIntoSubdirectory

      protected abstract void outputGroupIntoSubdirectory​(Collection<Map.Entry<String,​T>> namedAggregators, Function<Boolean,​org.anchoranalysis.io.output.outputter.InputOutputContext> createContext, Optional<String> outputNameSingle) throws IOException
      Output a particular group into a subdirectory.
      Parameters:
      namedAggregators - all the aggregators for this group.
      createContext - the subdirectory into which outputting occurs, given a boolean which is true (when multiple outputs occur), or false (when a single output occurs).
      outputNameSingle - the output-name to use if there is only a single output, (in which case createContext should always be called with false).
      Throws:
      IOException - if unable to output successfully.