Skip to content

Commit

Permalink
Changed DataSet merge retention policy: last timestamp wins (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
climategadgets committed May 18, 2021
1 parent e351321 commit 38803e0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
16 changes: 7 additions & 9 deletions dz3-model/src/main/java/net/sf/dz3/controller/DataSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,16 @@ public final synchronized void record(final long millis, final T value, boolean

if (lastValue != null && merge && lastValue.equals(value)) {

// Skip this one, we already have it
//LogManager.getLogger(getClass()).error("dupe: " + value);
// Will replace it with the same value and new timestamp right below. Slower on
// the way in, faster on the way out.

} else {

//LogManager.getLogger(getClass()).error("take: " + value);

dataSet.put(Long.valueOf(millis), value);
lastValue = value;
lastTimestamp = millis;
dataSet.remove(lastTimestamp);
}

dataSet.put(Long.valueOf(millis), value);
lastValue = value;
lastTimestamp = millis;

expire();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,11 @@ public void mergeExpire() {

assertEquals("wrong data set size", 1, ds.size());

// This one blows the old one past expiration, but nothing will happen
// because new timestamp will not be recorded
// This one blows the old one past expiration

ds.record(200, 1.0, true);

// The very first timestamp will be still retained

assertEquals("Wrong value after expiration", 1, ds.iterator().next().longValue());
assertEquals("Wrong value after expiration", 200, ds.iterator().next().longValue());
assertEquals("Wrong data set size", 1, ds.size());
}

Expand Down

0 comments on commit 38803e0

Please sign in to comment.