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
ABoundedTimestampSetis an implementation ofTimestampSetthat 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 classBoundedTimestampSet.Builderstatic classBoundedTimestampSet.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 voidadd(Instant instant)Adds the provided timestamp to the set.voidadd(Collection<Instant> instants)Adds all the provided timestamps to the set.booleanequals(Object obj)Important - this equals method requires the underlying timestamps to be exactly the same.InstantgetEarliest()The earliest timestamp in the set.InstantgetLatest()The latest timestamp in the set.intgetMaxSize()longgetNumberOfTimestamps()Returns the number of distinct timestamps in the set.RBMBackedTimestampSetgetRbmBackedTimestampSet()This exposes the underlyingRBMBackedTimestampSetso that serialisers can access it.org.apache.datasketches.sampling.ReservoirLongsUniongetReservoirLongsUnion()This exposes the underlyingReservoirLongsUnionso that serialisers can access it.BoundedTimestampSet.StategetState()ReturnsBoundedTimestampSet.State.NOT_FULLif less than or equal togetMaxSize()timestamps have been added.CommonTimeUtil.TimeBucketgetTimeBucket()SortedSet<Instant>getTimestamps()Returns all the timestamps in the set, sorted in their natural order.inthashCode()Important - this hash code method will produce different values if the underlying timestamps are different.voidsetRbmBackedTimestampSet(RBMBackedTimestampSet rbmBackedTimestampSet)Allows theRBMBackedTimestampSetto be set.voidsetReservoirLongsUnion(org.apache.datasketches.sampling.ReservoirLongsUnion reservoirLongsUnion)Allows theReservoirLongsUnionto be set.voidswitchToSampleState()StringtoString()
-
-
-
Constructor Detail
-
BoundedTimestampSet
public BoundedTimestampSet(CommonTimeUtil.TimeBucket timeBucket, int maxSize)
-
-
Method Detail
-
add
public void add(Instant instant)
Description copied from interface:TimestampSetAdds the provided timestamp to the set.- Specified by:
addin interfaceTimestampSet- Parameters:
instant- The timestamp to be added.
-
add
public void add(Collection<Instant> instants)
Description copied from interface:TimestampSetAdds all the provided timestamps to the set.- Specified by:
addin interfaceTimestampSet- Parameters:
instants- TheCollectionof timestamps to be added.
-
getTimestamps
public SortedSet<Instant> getTimestamps()
Description copied from interface:TimestampSetReturns all the timestamps in the set, sorted in their natural order.- Specified by:
getTimestampsin interfaceTimestampSet- Returns:
- All the timestamps in the set, sorted in their natural order.
-
getNumberOfTimestamps
public long getNumberOfTimestamps()
Description copied from interface:TimestampSetReturns the number of distinct timestamps in the set.- Specified by:
getNumberOfTimestampsin interfaceTimestampSet- Returns:
- The number of distinct timestamps in the set.
-
getEarliest
public Instant getEarliest()
Description copied from interface:TimestampSetThe earliest timestamp in the set.- Specified by:
getEarliestin interfaceTimestampSet- Returns:
- The earliest timestamp in the set.
-
getLatest
public Instant getLatest()
Description copied from interface:TimestampSetThe latest timestamp in the set.- Specified by:
getLatestin 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_FULLif less than or equal togetMaxSize()timestamps have been added. OtherwiseBoundedTimestampSet.State.SAMPLEis returned.- Returns:
- The
BoundedTimestampSet.Statethat this object is currently in.
-
getRbmBackedTimestampSet
public RBMBackedTimestampSet getRbmBackedTimestampSet()
This exposes the underlyingRBMBackedTimestampSetso that serialisers can access it. If the object is currently in the state ofNOT_FULLthen an exception is thrown.- Returns:
- the
RBMBackedTimestampSetused by this class to store the timestamps if it is in stateNOT_FULL
-
setRbmBackedTimestampSet
public void setRbmBackedTimestampSet(RBMBackedTimestampSet rbmBackedTimestampSet)
Allows theRBMBackedTimestampSetto be set.- Parameters:
rbmBackedTimestampSet- theRBMBackedTimestampSetto set theRBMBackedTimestampSetof this class to.
-
getReservoirLongsUnion
public org.apache.datasketches.sampling.ReservoirLongsUnion getReservoirLongsUnion()
This exposes the underlyingReservoirLongsUnionso that serialisers can access it. If the object is currently in the state ofNOT_FULLthen an exception is thrown.- Returns:
- the
ReservoirLongsUnionused by this class to store the timestamps if it is in stateSAMPLE
-
setReservoirLongsUnion
public void setReservoirLongsUnion(org.apache.datasketches.sampling.ReservoirLongsUnion reservoirLongsUnion)
Allows theReservoirLongsUnionto be set.- Parameters:
reservoirLongsUnion- theReservoirLongsUnionto 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.
-
-