Package uk.gov.gchq.gaffer.time
Class BoundedTimestampSet
- java.lang.Object
-
- uk.gov.gchq.gaffer.time.BoundedTimestampSet
-
- All Implemented Interfaces:
TimestampSet
public class BoundedTimestampSet extends Object implements TimestampSet
ABoundedTimestampSet
is an implementation ofTimestampSet
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BoundedTimestampSet.Builder
static class
BoundedTimestampSet.State
-
Constructor Summary
Constructors Constructor Description BoundedTimestampSet(CommonTimeUtil.TimeBucket timeBucket, int maxSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(Instant instant)
Adds the provided timestamp to the set.void
add(Collection<Instant> instants)
Adds all the provided timestamps to the set.boolean
equals(Object obj)
Important - this equals method requires the underlying timestamps to be exactly the same.Instant
getEarliest()
The earliest timestamp in the set.Instant
getLatest()
The latest timestamp in the set.int
getMaxSize()
long
getNumberOfTimestamps()
Returns the number of distinct timestamps in the set.RBMBackedTimestampSet
getRbmBackedTimestampSet()
This exposes the underlyingRBMBackedTimestampSet
so that serialisers can access it.org.apache.datasketches.sampling.ReservoirLongsUnion
getReservoirLongsUnion()
This exposes the underlyingReservoirLongsUnion
so that serialisers can access it.BoundedTimestampSet.State
getState()
ReturnsBoundedTimestampSet.State.NOT_FULL
if less than or equal togetMaxSize()
timestamps have been added.CommonTimeUtil.TimeBucket
getTimeBucket()
SortedSet<Instant>
getTimestamps()
Returns all the timestamps in the set, sorted in their natural order.int
hashCode()
Important - this hash code method will produce different values if the underlying timestamps are different.void
setRbmBackedTimestampSet(RBMBackedTimestampSet rbmBackedTimestampSet)
Allows theRBMBackedTimestampSet
to be set.void
setReservoirLongsUnion(org.apache.datasketches.sampling.ReservoirLongsUnion reservoirLongsUnion)
Allows theReservoirLongsUnion
to be set.void
switchToSampleState()
String
toString()
-
-
-
Constructor Detail
-
BoundedTimestampSet
public BoundedTimestampSet(CommonTimeUtil.TimeBucket timeBucket, int maxSize)
-
-
Method Detail
-
add
public void add(Instant instant)
Description copied from interface:TimestampSet
Adds the provided timestamp to the set.- Specified by:
add
in interfaceTimestampSet
- Parameters:
instant
- The timestamp to be added.
-
add
public void add(Collection<Instant> instants)
Description copied from interface:TimestampSet
Adds all the provided timestamps to the set.- Specified by:
add
in interfaceTimestampSet
- Parameters:
instants
- TheCollection
of timestamps 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 interfaceTimestampSet
- 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 interfaceTimestampSet
- 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 interfaceTimestampSet
- 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 interfaceTimestampSet
- Returns:
- The latest timestamp in the set.
-
getTimeBucket
public CommonTimeUtil.TimeBucket getTimeBucket()
-
getMaxSize
public int getMaxSize()
-
getState
public BoundedTimestampSet.State getState()
ReturnsBoundedTimestampSet.State.NOT_FULL
if less than or equal togetMaxSize()
timestamps have been added. OtherwiseBoundedTimestampSet.State.SAMPLE
is returned.- Returns:
- The
BoundedTimestampSet.State
that this object is currently in.
-
getRbmBackedTimestampSet
public RBMBackedTimestampSet getRbmBackedTimestampSet()
This exposes the underlyingRBMBackedTimestampSet
so that serialisers can access it. If the object is currently in the state ofNOT_FULL
then an exception is thrown.- Returns:
- the
RBMBackedTimestampSet
used by this class to store the timestamps if it is in stateNOT_FULL
-
setRbmBackedTimestampSet
public void setRbmBackedTimestampSet(RBMBackedTimestampSet rbmBackedTimestampSet)
Allows theRBMBackedTimestampSet
to be set.- Parameters:
rbmBackedTimestampSet
- theRBMBackedTimestampSet
to set theRBMBackedTimestampSet
of this class to.
-
getReservoirLongsUnion
public org.apache.datasketches.sampling.ReservoirLongsUnion getReservoirLongsUnion()
This exposes the underlyingReservoirLongsUnion
so that serialisers can access it. If the object is currently in the state ofNOT_FULL
then an exception is thrown.- Returns:
- the
ReservoirLongsUnion
used by this class to store the timestamps if it is in stateSAMPLE
-
setReservoirLongsUnion
public void setReservoirLongsUnion(org.apache.datasketches.sampling.ReservoirLongsUnion reservoirLongsUnion)
Allows theReservoirLongsUnion
to be set.- Parameters:
reservoirLongsUnion
- theReservoirLongsUnion
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.
-
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.
-
-