Class BoundedTimestampSet

  • All Implemented Interfaces:
    TimestampSet

    public class BoundedTimestampSet
    extends Object
    implements TimestampSet
    A BoundedTimestampSet is an implementation of TimestampSet that can contain a maximum number N of timestamps. If more than N timestamps are added then a uniform random sample of size approximately N of the timestamps is retained.

    This is useful in avoiding the in-memory or serialised size of the set of timestamps becoming too large. If less than N timestamps are added then the timestamps are stored in a RBMBackedTimestampSet. If more than N timestamps are added then a uniform random sample of size N of the timestamps is retained.

    • Method Detail

      • add

        public void add​(Instant instant)
        Description copied from interface: TimestampSet
        Adds the provided timestamp to the set.
        Specified by:
        add in interface TimestampSet
        Parameters:
        instant - The timestamp to be added.
      • getTimestamps

        public SortedSet<Instant> getTimestamps()
        Description copied from interface: TimestampSet
        Returns all the timestamps in the set, sorted in their natural order.
        Specified by:
        getTimestamps in interface TimestampSet
        Returns:
        All the timestamps in the set, sorted in their natural order.
      • getNumberOfTimestamps

        public long getNumberOfTimestamps()
        Description copied from interface: TimestampSet
        Returns the number of distinct timestamps in the set.
        Specified by:
        getNumberOfTimestamps in interface TimestampSet
        Returns:
        The number of distinct timestamps in the set.
      • getEarliest

        public Instant getEarliest()
        Description copied from interface: TimestampSet
        The earliest timestamp in the set.
        Specified by:
        getEarliest in interface TimestampSet
        Returns:
        The earliest timestamp in the set.
      • getLatest

        public Instant getLatest()
        Description copied from interface: TimestampSet
        The latest timestamp in the set.
        Specified by:
        getLatest in interface TimestampSet
        Returns:
        The latest timestamp in the set.
      • getMaxSize

        public int getMaxSize()
      • getRbmBackedTimestampSet

        public RBMBackedTimestampSet getRbmBackedTimestampSet()
        This exposes the underlying RBMBackedTimestampSet so that serialisers can access it. If the object is currently in the state of NOT_FULL then an exception is thrown.
        Returns:
        the RBMBackedTimestampSet used by this class to store the timestamps if it is in state NOT_FULL
      • getReservoirLongsUnion

        public org.apache.datasketches.sampling.ReservoirLongsUnion getReservoirLongsUnion()
        This exposes the underlying ReservoirLongsUnion so that serialisers can access it. If the object is currently in the state of NOT_FULL then an exception is thrown.
        Returns:
        the ReservoirLongsUnion used by this class to store the timestamps if it is in state SAMPLE
      • setReservoirLongsUnion

        public void setReservoirLongsUnion​(org.apache.datasketches.sampling.ReservoirLongsUnion reservoirLongsUnion)
        Allows the ReservoirLongsUnion to be set.
        Parameters:
        reservoirLongsUnion - the ReservoirLongsUnion to be set.
      • switchToSampleState

        public void switchToSampleState()
      • equals

        public boolean equals​(Object obj)
        Important - this equals method requires the underlying timestamps to be exactly the same. If it's in the state where it's sampling then it's randomly generated samples must be the same. So two BoundedTimestampSets which have had exactly the same data added might not be equal if the random samples are different.
        Overrides:
        equals in class Object
        Parameters:
        obj - the object to compare
        Returns:
        true if the obj is equal to this.
      • hashCode

        public int hashCode()
        Important - this hash code method will produce different values if the underlying timestamps are different. This may cause issues when using the randomly sampled data. So two BoundedTimestampSets which have had exactly the same data added might have different hash codes if the random samples are different.
        Overrides:
        hashCode in class Object
        Returns:
        the hash code