Class TimelineList<T>

  • All Implemented Interfaces:
    java.io.Serializable
    Direct Known Subclasses:
    Timeline

    public class TimelineList<T>
    extends java.lang.Object
    implements java.io.Serializable
    A 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
      class  TimelineList.TimeSegment
      A 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
      void add​(long start, long end, T value)  
      void add​(long start, T value)
      Add the value at the given time, with a duration of forever.
      void add​(TimelineList timelineList)  
      void add​(TimelineList.TimeSegment timeSegment)  
      boolean covered​(long time)
      Returns whether the timeline contains a segment that covers the specified time.
      T get​(long time)
      Returns the value for the specified time, or null if a value isn't defined.
      protected T get​(long time, boolean allowClosest, boolean allowRollover)  
      T getClosest​(long time)
      Returns the value for the given time, or the next defined value.
      protected TimelineList.TimeSegment getSegment​(int pos)  
      TimelineList.TimeSegment getSegment​(long time, boolean allowClosest)
      Returns the segment that contains the time.
      TimelineList.TimeSegment getSegment​(long time, boolean allowClosest, boolean allowRollover)
      Returns the segment that contains the time.
      java.util.List<TimelineList.TimeSegment> getSegments()  
      protected int indexOf​(long time, boolean allowRollover)
      Returns the index of the segment that covers the time, or comes next after the time.
      void mergeSegments()
      Merges together contiguous segments with the same value.
      long nextEvent​(long time)
      Returns the next time that something interesting happens after the given time.
      long nextEvent​(long time, boolean allowRollover)  
      int size()  
      void sort()  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • TimelineList

        public TimelineList()
    • 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.
      • 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)
      • 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:
        toString in class java.lang.Object
      • mergeSegments

        public void mergeSegments()
        Merges together contiguous segments with the same value. Used for composite user schedules.