Class SlidingWindowReservoir

  • All Implemented Interfaces:
    Reservoir

    public class SlidingWindowReservoir
    extends java.lang.Object
    implements Reservoir
    A Reservoir implementation backed by a sliding window that stores the last N measurements.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private long count  
      private long[] measurements  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Snapshot getSnapshot()
      Returns a snapshot of the reservoir's values.
      int size()
      Returns the number of values recorded.
      void update​(long value)
      Adds a new recorded value to the reservoir.
      • Methods inherited from class java.lang.Object

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

      • measurements

        private final long[] measurements
      • count

        private long count
    • Constructor Detail

      • SlidingWindowReservoir

        public SlidingWindowReservoir​(int size)
        Creates a new SlidingWindowReservoir which stores the last size measurements.
        Parameters:
        size - the number of measurements to store
    • Method Detail

      • size

        public int size()
        Description copied from interface: Reservoir
        Returns the number of values recorded.
        Specified by:
        size in interface Reservoir
        Returns:
        the number of values recorded
      • update

        public void update​(long value)
        Description copied from interface: Reservoir
        Adds a new recorded value to the reservoir.
        Specified by:
        update in interface Reservoir
        Parameters:
        value - a new recorded value
      • getSnapshot

        public Snapshot getSnapshot()
        Description copied from interface: Reservoir
        Returns a snapshot of the reservoir's values.
        Specified by:
        getSnapshot in interface Reservoir
        Returns:
        a snapshot of the reservoir's values