TimeSpanMap addValidBefore/After inconsistent
Documentation for addValidAfter
states:
As an entry is valid, it truncates the validity of the neighboring entries already present in the map.
and
Using addValidAfter(entry, t) will make 'entry' valid [t, +∞[ (note the closed bracket).
But that is self conflicting. Either the new entry will be valid on the whole half interval, or it will only update the adjacent entries on the time line. Only updating the adjacent entries also makes this method harder to use because then the caller has to remember where those entries are on the time line. Current implementation favors the first statement over the second.
Test case for favoring the second statement over the first:
@Test
public void testHalfInterval() {
AbsoluteDate ref = AbsoluteDate.ARBITRARY_EPOCH.shiftedBy(1);
TimeSpanMap<Integer> map = new TimeSpanMap<>(0);
// action
map.addValidAfter(1, ref.shiftedBy(1));
map.addValidAfter(2, ref.shiftedBy(2));
map.addValidBefore(3, ref.shiftedBy(-1));
map.addValidAfter(4, ref.shiftedBy(-2));
// verify
Assert.assertEquals(4, (int) map.get(ref.shiftedBy(-2)));
Assert.assertEquals(4, (int) map.get(ref.shiftedBy(-1)));
Assert.assertEquals(4, (int) map.get(ref));
Assert.assertEquals(4, (int) map.get(ref.shiftedBy(1)));
Assert.assertEquals(4, (int) map.get(ref.shiftedBy(2)));
Assert.assertEquals(4, (int) map.get(ref.shiftedBy(3)));
}
Found this while attempting to fix #798 (closed)