Class LargestSliceAccumulator<E,N extends Number & Comparable<? super N>>

java.lang.Object
org.consensusj.analytics.util.collector.LargestSliceAccumulator<E,N>
Type Parameters:
E - must be comparable because it is the second sort field
N - numeric type for Slice Size

public final class LargestSliceAccumulator<E,N extends Number & Comparable<? super N>> extends Object
Accumulates the n largest slices of a stream of objects of type <E>. Uses a PriorityQueue implementation of AbstractQueue internally.

This class is not thread-safe and is not designed for use with a Collector.Characteristics.CONCURRENT Collector. Switching the AbstractQueue implementation to PriorityBlockingQueue will work (with reduced performance) but the implementations of accumulate(Object), combine(LargestSliceAccumulator), and drain() are not thread-safe. Even if this class were thread-safe, enabling CONCURRENT in a Collector using this class would reduce performance because multiple threads would be trying to merge Objects into the same accumulator. The optimal way to use this class is with one accumulator per thread and this is what Collector will do without the CONCURRENT flag.

  • Constructor Details

    • LargestSliceAccumulator

      public LargestSliceAccumulator(int n, Function<E,N> sliceSizeExtractor, N zero, BinaryOperator<N> additionOperator)
      Construct
      Parameters:
      n - maximum number of keys (addresses) to track
      sliceSizeExtractor - Function to compute the slice size
      zero - The value zero for type N
      additionOperator - binary addition operator for type N