Class GroupMapByName<S,T>
Object
GroupMapByName<S,T>
- Type Parameters:
S
- single item typeT
- aggregator type
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 Summary
ConstructorsModifierConstructorDescriptionprotected
GroupMapByName
(String nounT, Optional<Stream<String>> groupIdentifiers, Optional<InputOutputContext> outputContext, Supplier<T> createAggregator, CheckedBiConsumer<S, T, OperationFailedException> addSingleToAggregator) Creates a group-map. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(Optional<String> groupIdentifier, List<org.apache.commons.math3.util.Pair<String, S>> singleItemsToAdd) Adds an item with a non-group identifier, and also optionally a group identifier.void
Outputs any groups that have not already been outputted.protected abstract void
outputGroupIntoSubdirectory
(Collection<Map.Entry<String, T>> namedAggregators, Function<Boolean, InputOutputContext> createContext, Optional<String> outputNameSingle) Output a particular group into a subdirectory.
-
Constructor Details
-
GroupMapByName
protected GroupMapByName(String nounT, Optional<Stream<String>> groupIdentifiers, Optional<InputOutputContext> outputContext, Supplier<T> createAggregator, CheckedBiConsumer<S, T, 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 OperationFailedExceptionAdds 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:
OperationFailedException
- if the operation cannot successfully complete.
-
outputAnyRemainingGroups
Outputs any groups that have not already been outputted.- Throws:
OperationFailedException
- if thrown by the outputting.
-
outputGroupIntoSubdirectory
protected abstract void outputGroupIntoSubdirectory(Collection<Map.Entry<String, T>> namedAggregators, Function<Boolean, throws IOExceptionInputOutputContext> createContext, Optional<String> outputNameSingle) 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 casecreateContext
should always be called with false).- Throws:
IOException
- if unable to output successfully.
-