Skip to content
Snippets Groups Projects
Commit 14fbeea4 authored by Luc Maisonobe's avatar Luc Maisonobe
Browse files

Return added Span in TimeSpanMap.

parent 8c3c9e6c
No related branches found
No related tags found
No related merge requests found
......@@ -141,9 +141,10 @@ public class TimeSpanMap<T> {
* @param latestValidityDate date before which the entry is valid
* @param erasesEarlier if true, the entry erases all existing transitions
* that are earlier than {@code latestValidityDate}
* @return span with added entry
* @since 11.1
*/
public synchronized void addValidBefore(final T entry, final AbsoluteDate latestValidityDate, final boolean erasesEarlier) {
public synchronized Span<T> addValidBefore(final T entry, final AbsoluteDate latestValidityDate, final boolean erasesEarlier) {
// update current reference to transition date
locate(latestValidityDate);
......@@ -185,6 +186,8 @@ public class TimeSpanMap<T> {
// we consider the last added transition as the new current one
current = span;
return span;
}
/** Add an entry valid after a limit date.
......@@ -229,9 +232,10 @@ public class TimeSpanMap<T> {
* @param earliestValidityDate date after which the entry is valid
* @param erasesLater if true, the entry erases all existing transitions
* that are later than {@code earliestValidityDate}
* @return span with added entry
* @since 11.1
*/
public synchronized void addValidAfter(final T entry, final AbsoluteDate earliestValidityDate, final boolean erasesLater) {
public synchronized Span<T> addValidAfter(final T entry, final AbsoluteDate earliestValidityDate, final boolean erasesLater) {
// update current reference to transition date
locate(earliestValidityDate);
......@@ -267,6 +271,8 @@ public class TimeSpanMap<T> {
// we consider the last added transition as the new current one
current = span;
return span;
}
/** Add an entry valid between two limit dates.
......@@ -277,9 +283,10 @@ public class TimeSpanMap<T> {
* @param entry entry to add
* @param earliestValidityDate date after which the entry is valid
* @param latestValidityDate date before which the entry is valid
* @return span with added entry
* @since 11.1
*/
public synchronized void addValidBetween(final T entry, final AbsoluteDate earliestValidityDate, final AbsoluteDate latestValidityDate) {
public synchronized Span<T> addValidBetween(final T entry, final AbsoluteDate earliestValidityDate, final AbsoluteDate latestValidityDate) {
// locate spans at earliest and latest dates
locate(earliestValidityDate);
......@@ -315,6 +322,8 @@ public class TimeSpanMap<T> {
// we consider the last added transition as the new current one
current = span;
return span;
}
/** Get the entry valid at a specified date.
......
......@@ -53,7 +53,9 @@ public class TimeSpanMapTest {
TimeSpanMap<Integer> map = new TimeSpanMap<>(Integer.valueOf(0));
checkCountConsistency(map);
for (int i = 1; i < 100; ++i) {
map.addValidAfter(Integer.valueOf(i), ref.shiftedBy(i), false);
Integer entry = Integer.valueOf(i);
TimeSpanMap.Span<Integer> span = map.addValidAfter(entry, ref.shiftedBy(i), false);
Assert.assertSame(entry, span.getData());
checkCountConsistency(map);
}
Assert.assertEquals(0, map.get(ref.shiftedBy(-1000.0)).intValue());
......@@ -88,7 +90,9 @@ public class TimeSpanMapTest {
TimeSpanMap<Integer> map = new TimeSpanMap<>(Integer.valueOf(0));
checkCountConsistency(map);
for (int i = -1; i > -100; --i) {
map.addValidBefore(Integer.valueOf(i), ref.shiftedBy(i), false);
Integer entry = Integer.valueOf(i);
TimeSpanMap.Span<Integer> span = map.addValidBefore(entry, ref.shiftedBy(i), false);
Assert.assertSame(entry, span.getData());
checkCountConsistency(map);
}
Assert.assertEquals(0, map.get(ref.shiftedBy( 1000.0)).intValue());
......@@ -270,7 +274,9 @@ public class TimeSpanMapTest {
map.addValidAfter(4, AbsoluteDate.ARBITRARY_EPOCH.shiftedBy(4), false);
map.addValidAfter(5, AbsoluteDate.ARBITRARY_EPOCH.shiftedBy(5), false);
Assert.assertEquals(6, map.getSpansNumber());
map.addValidBetween(-1, AbsoluteDate.ARBITRARY_EPOCH.shiftedBy(1.5), AbsoluteDate.ARBITRARY_EPOCH.shiftedBy(4.5));
Integer entry = Integer.valueOf(-1);
TimeSpanMap.Span<Integer> span = map.addValidBetween(entry, AbsoluteDate.ARBITRARY_EPOCH.shiftedBy(1.5), AbsoluteDate.ARBITRARY_EPOCH.shiftedBy(4.5));
Assert.assertSame(entry, span.getData());
Assert.assertEquals(5, map.getSpansNumber());
Assert.assertEquals( 0, map.get(AbsoluteDate.ARBITRARY_EPOCH.shiftedBy(0.75)).intValue());
Assert.assertEquals( 1, map.get(AbsoluteDate.ARBITRARY_EPOCH.shiftedBy(1.25)).intValue());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment