Package uk.gov.gchq.gaffer.time
Class LongTimeSeries
- java.lang.Object
-
- uk.gov.gchq.gaffer.time.LongTimeSeries
-
- All Implemented Interfaces:
TimeSeries<Long>
public class LongTimeSeries extends Object implements TimeSeries<Long>
This is a time series where the values areLong
s. When the time series is created, aCommonTimeUtil.TimeBucket
is specified. When timestamps are added, they are rounded to the nearest bucket, e.g. if aCommonTimeUtil.TimeBucket
ofMINUTE
is specified, and a timestamp of January 1st 2017, 12:34:56 is added then the seconds are removed so that the value is associated to 12:34.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
LongTimeSeries.Builder
-
Constructor Summary
Constructors Constructor Description LongTimeSeries(CommonTimeUtil.TimeBucket timeBucket)
LongTimeSeries(CommonTimeUtil.TimeBucket timeBucket, Map<Instant,Long> timeSeries)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
Long
get(Instant instant)
Returns the value associated to the givenInstant
.SortedSet<Instant>
getInstants()
int
getNumberOfInstants()
Returns the number of instants in the time series.CommonTimeUtil.TimeBucket
getTimeBucket()
SortedMap<Instant,Long>
getTimeSeries()
int
hashCode()
void
put(Instant instant, Long value)
void
setTimeSeries(Map<Instant,Long> timeSeries)
Sets the time series to be the given time series.String
toString()
void
upsert(Instant instant, long count)
Adds the givencount
to the current value associated to the givenInstant
.
-
-
-
Constructor Detail
-
LongTimeSeries
public LongTimeSeries(CommonTimeUtil.TimeBucket timeBucket)
-
LongTimeSeries
public LongTimeSeries(CommonTimeUtil.TimeBucket timeBucket, Map<Instant,Long> timeSeries)
-
-
Method Detail
-
put
public void put(Instant instant, Long value)
Puts the providedvalue
into the time series associated to theInstant
instant
. Note that this overwrites any previous value in that bucket.- Specified by:
put
in interfaceTimeSeries<Long>
- Parameters:
instant
- The instant at which the value was observed.value
- The value observed at the instant.
-
get
public Long get(Instant instant)
Returns the value associated to the givenInstant
. Note that this instant is rounded to the nearest time bucket.- Specified by:
get
in interfaceTimeSeries<Long>
- Parameters:
instant
- The instant that the value is required for.- Returns:
- The value associated to the instant.
-
upsert
public void upsert(Instant instant, long count)
Adds the givencount
to the current value associated to the givenInstant
. If there is no value currently associated to theInstant
then thecount
is simply inserted. Note that the caller of this method is responsible for dealing with the case where addingcount
would cause an overflow.- Parameters:
instant
- The instant at which the value was observed.count
- The value observed at the instant.
-
getNumberOfInstants
public int getNumberOfInstants()
Returns the number of instants in the time series.- Returns:
- The number of instants in the time series.
-
getTimeSeries
public SortedMap<Instant,Long> getTimeSeries()
Returns the time series as aSortedMap
where the key is anInstant
rounded to the nearest bucket and the value is the associated count.- Returns:
- The time series.
-
setTimeSeries
public void setTimeSeries(Map<Instant,Long> timeSeries)
Sets the time series to be the given time series.- Parameters:
timeSeries
- The time series to copy entries from.
-
getTimeBucket
public CommonTimeUtil.TimeBucket getTimeBucket()
-
-