Class ReductionOutcome<T>

Object
ReductionOutcome<T>
Type Parameters:
T - element-type that is reduced / added.

public class ReductionOutcome<T> extends Object
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 Details

    • ReductionOutcome

      public ReductionOutcome()
      Create with an empty list of retained-indices.
    • ReductionOutcome

      public ReductionOutcome(List<Integer> indicesRetained)
      Creates a new ReductionOutcome instance.
      Parameters:
      indicesRetained - The indices of elements in the list that are retained after the reduction operation. Zero-indexed.
    • ReductionOutcome

      public ReductionOutcome(List<Integer> indicesRetained, List<T> added)
      Creates a new ReductionOutcome 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

      public 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.
      Parameters:
      toAdd - the element to add.
    • listAfter

      public List<T> listAfter(List<T> input)
      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

      public <S> ReductionOutcome<S> map(UnaryOperator<Integer> mapIndex, Function<T,S> mapAdded)
      Creates a new ReductionOutcome 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.