Class TimelineList<T>
- java.lang.Object
-
- com.inductiveautomation.ignition.common.util.TimelineList<T>
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
Timeline
public class TimelineList<T> extends java.lang.Object implements java.io.SerializableA timeline list is a list of values that cover a span of time. There is only one timeline, and so values cannot overlap. Items can be added with a start time, in which the end will be "forever", or a fixed range. In either case, the start and end may be adjusted (or the value overwritten) by new values that get added.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classTimelineList.TimeSegmentA time segment covers a span of time.
-
Constructor Summary
Constructors Constructor Description TimelineList()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(long start, long end, T value)voidadd(long start, T value)Add the value at the given time, with a duration of forever.voidadd(TimelineList timelineList)voidadd(TimelineList.TimeSegment timeSegment)booleancovered(long time)Returns whether the timeline contains a segment that covers the specified time.Tget(long time)Returns the value for the specified time, or null if a value isn't defined.protected Tget(long time, boolean allowClosest, boolean allowRollover)TgetClosest(long time)Returns the value for the given time, or the next defined value.protected TimelineList.TimeSegmentgetSegment(int pos)TimelineList.TimeSegmentgetSegment(long time, boolean allowClosest)Returns the segment that contains the time.TimelineList.TimeSegmentgetSegment(long time, boolean allowClosest, boolean allowRollover)Returns the segment that contains the time.java.util.List<TimelineList.TimeSegment>getSegments()protected intindexOf(long time, boolean allowRollover)Returns the index of the segment that covers the time, or comes next after the time.voidmergeSegments()Merges together contiguous segments with the same value.longnextEvent(long time)Returns the next time that something interesting happens after the given time.longnextEvent(long time, boolean allowRollover)intsize()voidsort()java.lang.StringtoString()
-
-
-
Method Detail
-
size
public int size()
-
sort
public void sort()
-
indexOf
protected int indexOf(long time, boolean allowRollover)Returns the index of the segment that covers the time, or comes next after the time.- Parameters:
allowRollover- if the time is beyond the last segment, and this parameter is true, the first index will be returned. Otherwise the last index of the list will be returned.- Returns:
- the index of the segment that covers the time, or comes next after the time.
-
getSegment
protected TimelineList.TimeSegment getSegment(int pos)
-
add
public void add(long start, T value)Add the value at the given time, with a duration of forever. Some care should be taken when using this function, because if values do not arrive in ascending time, previous entries will be overwritten. Because of this behavior, this function can also check the equality of values and avoid making extra segments, improving performance.
-
add
public void add(long start, long end, T value)
-
add
public void add(TimelineList.TimeSegment timeSegment)
-
add
public void add(TimelineList timelineList)
-
covered
public boolean covered(long time)
Returns whether the timeline contains a segment that covers the specified time.
-
get
public T get(long time)
Returns the value for the specified time, or null if a value isn't defined.
-
getClosest
public T getClosest(long time)
Returns the value for the given time, or the next defined value. Returns null if there is no value specified at, or beyond, the given time.
-
get
protected T get(long time, boolean allowClosest, boolean allowRollover)
-
getSegment
public TimelineList.TimeSegment getSegment(long time, boolean allowClosest)
Returns the segment that contains the time. If allowClosest is true, will return the next possible time, if a time segment doesn't cover the current time.
-
getSegment
public TimelineList.TimeSegment getSegment(long time, boolean allowClosest, boolean allowRollover)
Returns the segment that contains the time. If allowClosest is true, will return the next possible time, if a time segment doesn't cover the current time.
-
nextEvent
public long nextEvent(long time)
Returns the next time that something interesting happens after the given time. That is, the current segment ends, the next one starts, etc. If nothing else happens, Long.Max is returned.
-
nextEvent
public long nextEvent(long time, boolean allowRollover)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getSegments
public java.util.List<TimelineList.TimeSegment> getSegments()
-
mergeSegments
public void mergeSegments()
Merges together contiguous segments with the same value. Used for composite user schedules.
-
-