LongTimeSeries implements TimeSeries<Long> { public void upsert(final Instant instant, final long count) { final long bucket = toLong(timeBucket, instant.toEpochMilli()); timeSeries.merge(bucket, count, (x, y) -> x + y); } LongTimeSeries(final TimeBucket timeBucket); @JsonCreator  LongTimeSeries(@JsonProperty("timeBucket") final TimeBucket timeBucket,
                          @JsonProperty("timeSeries") final Map<Instant, Long> timeSeries); @Override void put(final Instant instant, final Long value); @JsonIgnore @Override Long get(final Instant instant); void upsert(final Instant instant, final long count); @JsonIgnore SortedSet<Instant> getInstants(); @JsonIgnore int getNumberOfInstants(); SortedMap<Instant, Long> getTimeSeries(); void setTimeSeries(final Map<Instant, Long> timeSeries); TimeBucket getTimeBucket(); @Override boolean equals(final Object obj); @Override int hashCode(); @Override String toString();  }
@Test public void testUpsert() { final LongTimeSeries timeSeries = new LongTimeSeries(TimeBucket.MINUTE); final Instant instant = Instant.ofEpochMilli(1000L * 60); timeSeries.put(instant, 100L); timeSeries.upsert(instant, 200L); assertEquals(300L, (long) timeSeries.get(instant)); }