Package google.registry.model.common
Class TimedTransitionProperty<V extends java.io.Serializable>
- java.lang.Object
-
- com.google.common.collect.ForwardingObject
-
- com.google.common.collect.ForwardingMap<org.joda.time.DateTime,V>
-
- google.registry.model.common.TimedTransitionProperty<V>
-
- All Implemented Interfaces:
UnsafeSerializable
,java.io.Serializable
,java.util.Map<org.joda.time.DateTime,V>
public class TimedTransitionProperty<V extends java.io.Serializable> extends com.google.common.collect.ForwardingMap<org.joda.time.DateTime,V> implements UnsafeSerializable
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 "start of time" value (corresponding toSTART_OF_TIME
, i.e. the Unix epoch) must be provided so that the property will have a value for all possible times.This concept is naturally represented by a sorted map of
DateTime
toTimedTransitionProperty
. This class implementsForwardingMap
and stores the data in a backing map and exposes several convenient methods to extrapolate the value at arbitrary point in time.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
checkValidity()
Checks whether thisTimedTransitionProperty
is in a valid state, i.e.protected com.google.common.collect.ImmutableSortedMap<org.joda.time.DateTime,V>
delegate()
static <V extends java.io.Serializable>
TimedTransitionProperty<V>fromValueMap(com.google.common.collect.ImmutableSortedMap<org.joda.time.DateTime,V> valueMap)
Returns a new immutableTimedTransitionProperty
representing the given map ofDateTime
to valueTimedTransitionProperty
.org.joda.time.DateTime
getNextTransitionAfter(org.joda.time.DateTime time)
Returns the time of the next transition.V
getValueAtTime(org.joda.time.DateTime time)
Returns the value of the property that is active at the specified time.static <V extends java.io.Serializable>
TimedTransitionProperty<V>make(com.google.common.collect.ImmutableSortedMap<org.joda.time.DateTime,V> newTransitions, com.google.common.collect.ImmutableMultimap<V,V> allowedTransitions, java.lang.String allowedTransitionMapName, V initialValue, java.lang.String badInitialValueErrorMessage)
Validates a new set of transitions and returns the resultingTimedTransitionProperty
.com.google.common.collect.ImmutableSortedMap<org.joda.time.DateTime,V>
toValueMap()
Exposes the underlyingImmutableSortedMap
.static <V extends java.io.Serializable>
voidvalidateTimedTransitionMap(java.util.NavigableMap<org.joda.time.DateTime,V> transitionMap, com.google.common.collect.ImmutableMultimap<V,V> allowedTransitions, java.lang.String mapName)
Validates that a transition map is not null or empty, starts atSTART_OF_TIME
, and has transitions which move from one value to another in allowed ways.static <V extends java.io.Serializable>
TimedTransitionProperty<V>withInitialValue(V initialValue)
Returns a new immutableTimedTransitionProperty
with an initial value atSTART_OF_TIME
.-
Methods inherited from class com.google.common.collect.ForwardingMap
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, standardClear, standardContainsKey, standardContainsValue, standardEquals, standardHashCode, standardIsEmpty, standardPutAll, standardRemove, standardToString, values
-
-
-
-
Method Detail
-
fromValueMap
public static <V extends java.io.Serializable> TimedTransitionProperty<V> fromValueMap(com.google.common.collect.ImmutableSortedMap<org.joda.time.DateTime,V> valueMap)
Returns a new immutableTimedTransitionProperty
representing the given map ofDateTime
to valueTimedTransitionProperty
.
-
withInitialValue
public static <V extends java.io.Serializable> TimedTransitionProperty<V> withInitialValue(V initialValue)
Returns a new immutableTimedTransitionProperty
with an initial value atSTART_OF_TIME
.
-
make
public static <V extends java.io.Serializable> TimedTransitionProperty<V> make(com.google.common.collect.ImmutableSortedMap<org.joda.time.DateTime,V> newTransitions, com.google.common.collect.ImmutableMultimap<V,V> allowedTransitions, java.lang.String allowedTransitionMapName, V initialValue, java.lang.String badInitialValueErrorMessage)
Validates a new set of transitions and returns the resultingTimedTransitionProperty
.- Parameters:
newTransitions
- map fromDateTime
to transition valueTimedTransitionProperty
allowedTransitions
- optional map of all possible state-to-state transitionsallowedTransitionMapName
- optional transition map description string for error messagesinitialValue
- optional initial value; if present, the first transition must have this valuebadInitialValueErrorMessage
- option error message string if the initial value is wrong
-
validateTimedTransitionMap
public static <V extends java.io.Serializable> void validateTimedTransitionMap(@Nullable java.util.NavigableMap<org.joda.time.DateTime,V> transitionMap, com.google.common.collect.ImmutableMultimap<V,V> allowedTransitions, java.lang.String mapName)
Validates that a transition map is not null or empty, starts atSTART_OF_TIME
, and has transitions which move from one value to another in allowed ways.
-
checkValidity
public void checkValidity()
Checks whether thisTimedTransitionProperty
is in a valid state, i.e. whether it has a transition entry forSTART_OF_TIME
, and throwsIllegalStateException
if not.
-
delegate
protected com.google.common.collect.ImmutableSortedMap<org.joda.time.DateTime,V> delegate()
- Specified by:
delegate
in classcom.google.common.collect.ForwardingMap<org.joda.time.DateTime,V extends java.io.Serializable>
-
toValueMap
public com.google.common.collect.ImmutableSortedMap<org.joda.time.DateTime,V> toValueMap()
Exposes the underlyingImmutableSortedMap
.
-
getValueAtTime
public V getValueAtTime(org.joda.time.DateTime time)
Returns the value of the property that is active at the specified time. The active value for a time beforeSTART_OF_TIME
is extrapolated to be the value that is active atSTART_OF_TIME
.
-
getNextTransitionAfter
@Nullable public org.joda.time.DateTime getNextTransitionAfter(org.joda.time.DateTime time)
Returns the time of the next transition. Returns null if there is no subsequent transition.
-
-