mirror of
https://github.com/google/nomulus.git
synced 2025-05-15 17:07:15 +02:00
Add TimedTransitionProperty.getTransitionTime()
Add a method to get the next transition time so that we can return the expiry date along with the EAP fee for a given time. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=125076484
This commit is contained in:
parent
4f91d03704
commit
61f37b756a
2 changed files with 21 additions and 0 deletions
|
@ -35,6 +35,8 @@ import org.joda.time.DateTime;
|
||||||
import java.util.NavigableMap;
|
import java.util.NavigableMap;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An entity property whose value transitions over time. Each value it takes on becomes active
|
* An entity property whose value transitions over time. Each value it takes on becomes active
|
||||||
* at a corresponding instant, and remains active until the next transition occurs. At least one
|
* at a corresponding instant, and remains active until the next transition occurs. At least one
|
||||||
|
@ -203,4 +205,12 @@ public class TimedTransitionProperty<V, T extends TimedTransitionProperty.TimedT
|
||||||
// where any given time earlier than START_OF_TIME is replaced by START_OF_TIME.
|
// where any given time earlier than START_OF_TIME is replaced by START_OF_TIME.
|
||||||
return backingMap.floorEntry(latestOf(START_OF_TIME, time)).getValue().getValue();
|
return backingMap.floorEntry(latestOf(START_OF_TIME, time)).getValue().getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the time of the next transition. Returns null if there is no subsequent transition.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public DateTime getNextTransitionAfter(DateTime time) {
|
||||||
|
return backingMap.higherKey(latestOf(START_OF_TIME, time));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,6 +106,17 @@ public class TimedTransitionPropertyTest {
|
||||||
testGetValueAtTime(timedString);
|
testGetValueAtTime(timedString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSuccess_getNextTransitionAfter() throws Exception {
|
||||||
|
assertThat(timedString.getNextTransitionAfter(A_LONG_TIME_AGO)).isEqualTo(DATE_1);
|
||||||
|
assertThat(timedString.getNextTransitionAfter(START_OF_TIME.plusMillis(1))).isEqualTo(DATE_1);
|
||||||
|
assertThat(timedString.getNextTransitionAfter(DATE_1.minusMillis(1))).isEqualTo(DATE_1);
|
||||||
|
assertThat(timedString.getNextTransitionAfter(DATE_1)).isEqualTo(DATE_2);
|
||||||
|
assertThat(timedString.getNextTransitionAfter(DATE_2.minusMillis(1))).isEqualTo(DATE_2);
|
||||||
|
assertThat(timedString.getNextTransitionAfter(DATE_2)).isEqualTo(DATE_3);
|
||||||
|
assertThat(timedString.getNextTransitionAfter(DATE_3)).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_simulatedLoad() throws Exception {
|
public void testSuccess_simulatedLoad() throws Exception {
|
||||||
// Just for testing, don't extract transitions from a TimedTransitionProperty in real code.
|
// Just for testing, don't extract transitions from a TimedTransitionProperty in real code.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue