Class ReductionOutcome<T>
Object
ReductionOutcome<T>
- Type Parameters:
T
- element-type that is reduced / added.
The result of a reduction operation.
The reduction operation takes an input list of elements, and creates an output list.
The output list contains, and combination of:
- retained elements from the input-list (a subset), each identified by its index in the input list.
- newly-added elements, that didn't exist in the input-list (typically a merging of elements in the input-list, who are not otherwise retained).
- Author:
- Owen Feehan
-
Constructor Summary
ConstructorsConstructorDescriptionCreate with an empty list of retained-indices.ReductionOutcome
(List<Integer> indicesRetained) Creates a newReductionOutcome
instance.ReductionOutcome
(List<Integer> indicesRetained, List<T> added) Creates a newReductionOutcome
instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addIndexToRetain
(int index) Adds an index to be retained after reduction.void
addNewlyAdded
(T toAdd) Adds a newly-added element, that didn't exist in the input list for reduction, but should exist in the output list.Generates a list of elements that exist after the reduction.<S> ReductionOutcome
<S> map
(UnaryOperator<Integer> mapIndex, Function<T, S> mapAdded) Creates a newReductionOutcome
where both the retained-indices and the newly-added elements may be mapped.int
The total number of elements after reduction.
-
Constructor Details
-
ReductionOutcome
public ReductionOutcome()Create with an empty list of retained-indices. -
ReductionOutcome
Creates a newReductionOutcome
instance.- Parameters:
indicesRetained
- The indices of elements in the list that are retained after the reduction operation. Zero-indexed.
-
ReductionOutcome
Creates a newReductionOutcome
instance.- Parameters:
indicesRetained
- The indices of elements in the list that are retained after the reduction operation. Zero-indexed.added
-
-
-
Method Details
-
addIndexToRetain
public void addIndexToRetain(int index) Adds an index to be retained after reduction.- Parameters:
index
- an index identifying an element in the input list for reduction, that should be retained in the output.
-
addNewlyAdded
Adds a newly-added element, that didn't exist in the input list for reduction, but should exist in the output list.- Parameters:
toAdd
- the element to add.
-
listAfter
Generates a list of elements that exist after the reduction.- Parameters:
input
- the list of elements that was passed as an input to reduce.- Returns:
- a newly created list, containing retained elements, and newly-added elements.
-
sizeAfter
public int sizeAfter()The total number of elements after reduction.- Returns:
- the total number of elements, summing both those retained and those newly added.
-
map
Creates a newReductionOutcome
where both the retained-indices and the newly-added elements may be mapped.- Type Parameters:
S
- the type of the newly-added elements after the mapping.- Parameters:
mapIndex
- maps a given index in the input-list to a new index in the output-list.mapAdded
- maps a given newly-added object in the input-list to corresponding element in the output-list.- Returns:
- a newly created
ReductionOutcome
containing the result of the mappings, as described above.
-