Class HeadTailAccumulator<T>

java.lang.Object
org.assertj.core.presentation.HeadTailAccumulator<T>

final class HeadTailAccumulator<T> extends Object
Accumulates the values in a stream or iterable, keeping the first and last elements and discarding everything in between.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Queue<T>
    The first elements seen.
    private final Queue<T>
    The elements seen most recently, excluding anything already on head.
  • Constructor Summary

    Constructors
    Constructor
    Description
    HeadTailAccumulator(int headCapacity, int tailCapacity)
    Creates a new HeadTailAccumulator.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) void
    add(T element)
    Adds an element to the accumulator, possibly displacing an older element.
    (package private) Stream<T>
    Converts the accumulated elements into a stream.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • tail

      private final Queue<T> tail
      The elements seen most recently, excluding anything already on head.
  • Constructor Details

    • HeadTailAccumulator

      HeadTailAccumulator(int headCapacity, int tailCapacity)
      Creates a new HeadTailAccumulator.
      Parameters:
      headCapacity - the maximum number of elements to retain from the start of the stream
      tailCapacity - the maximum number of elements to retain from the end of the stream.
      Throws:
      IllegalArgumentException - if either argument is negative
  • Method Details

    • add

      void add(T element)
      Adds an element to the accumulator, possibly displacing an older element.
      Parameters:
      element - the element to add (may be null)
    • stream

      Stream<T> stream()
      Converts the accumulated elements into a stream.
      Returns:
      the head and tail concatenated