Class TimeSpanMap<T>

  • Type Parameters:
    T - Type of the data.

    public class TimeSpanMap<T>
    extends Object
    Container for objects that apply to spans of time.
    Since:
    7.1
    Author:
    Luc Maisonobe
    • Constructor Detail

      • TimeSpanMap

        public TimeSpanMap​(T entry)
        Create a map containing a single object, initially valid throughout the timeline.

        The real validity of this first entry will be truncated as other entries are either added before it or added after it.

        Parameters:
        entry - entry (initially valid throughout the timeline)
    • Method Detail

      • addValidBefore

        public void addValidBefore​(T entry,
                                   AbsoluteDate latestValidityDate)
        Add an entry valid before a limit date.

        As an entry is valid, it truncates the validity of the neighboring entries already present in the map.

        The transition dates should be entered only once, either by a call to this method or by a call to addValidAfter(Object, AbsoluteDate). Repeating a transition date will lead to unexpected result and is not supported.

        Parameters:
        entry - entry to add
        latestValidityDate - date before which the entry is valid (must be different from all dates already used for transitions)
      • addValidAfter

        public void addValidAfter​(T entry,
                                  AbsoluteDate earliestValidityDate)
        Add an entry valid after a limit date.

        As an entry is valid, it truncates the validity of the neighboring entries already present in the map.

        The transition dates should be entered only once, either by a call to this method or by a call to addValidBefore(Object, AbsoluteDate). Repeating a transition date will lead to unexpected result and is not supported.

        Parameters:
        entry - entry to add
        earliestValidityDate - date after which the entry is valid (must be different from all dates already used for transitions)
      • get

        public T get​(AbsoluteDate date)
        Get the entry valid at a specified date.
        Parameters:
        date - date at which the entry must be valid
        Returns:
        valid entry at specified date
      • getSpan

        public TimeSpanMap.Span<T> getSpan​(AbsoluteDate date)
        Get the time span containing a specified date.
        Parameters:
        date - date belonging to the desired time span
        Returns:
        time span containing the specified date
        Since:
        9.3
      • extractRange

        public TimeSpanMap<T> extractRange​(AbsoluteDate start,
                                           AbsoluteDate end)
        Extract a range of the map.

        The object returned will be a new independent instance that will contain only the transitions that lie in the specified range.

        Consider for example a map containing objects O₀ valid before t₁, O₁ valid between t₁ and t₂, O₂ valid between t₂ and t₃, O₃ valid between t₃ and t₄, and O₄ valid after t₄. then calling this method with a start date between t₁ and t₂ and a end date between t₃ and t₄ will result in a new map containing objects O₁ valid before t₂, O₂ valid between t₂ and t₃, and O₃ valid after t₃. The validity of O₁ is therefore extended in the past, and the validity of O₃ is extended in the future.

        Parameters:
        start - earliest date at which a transition is included in the range (may be set to AbsoluteDate.PAST_INFINITY to keep all early transitions)
        end - latest date at which a transition is included in the r (may be set to AbsoluteDate.FUTURE_INFINITY to keep all late transitions)
        Returns:
        a new instance with all transitions restricted to the specified range
        Since:
        9.2
      • getTransitions

        public NavigableSet<TimeSpanMap.Transition<T>> getTransitions()
        Get an unmodifiable view of the sorted transitions.
        Returns:
        unmodifiable view of the sorted transitions