Package org.yamcs.utils
Class PartitionedTimeInterval<T extends TimeInterval>
- java.lang.Object
-
- org.yamcs.utils.PartitionedTimeInterval<T>
-
- All Implemented Interfaces:
Iterable<T>
public class PartitionedTimeInterval<T extends TimeInterval> extends Object implements Iterable<T>
A list of sorted, non overlappingTimeInterval
The composing time intervals are considered closed at start and open at end [start, end)It is implemented as a copy on write array and it is thread safe.
-
-
Constructor Summary
Constructors Constructor Description PartitionedTimeInterval()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TimeInterval
get(int i)
T
getFit(long t)
returns an interval where t would fit or null if there is no such intervalT
insert(T timeInterval)
Inserts an interval in the list if it doesn't overlap with an existing one.T
insert(T x, long tolerance)
Insert a new time interval in the list, if it doesn't overlap with the existing intervals.Iterator<T>
iterator()
Iterator<T>
overlappingIterator(TimeInterval timeInterval)
Creates an iterator that iterates over all the timeintervals overlapping with timeInterval The timeInterval is considered closed at both ends [start, stop]Iterator<T>
overlappingReverseIterator(TimeInterval timeInterval)
Creates an iterator that iterates over all the timeintervals overlapping with timeInterval The timeInterval is considered closed at both ends [start, stop]Iterator<T>
reverseIterator()
int
size()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
insert
public T insert(T x, long tolerance)
Insert a new time interval in the list, if it doesn't overlap with the existing intervals. If it overlaps but the overlap is within the tolerance (on either end), it modifies it such as to fit perfectly If it overlaps and the overlap is not within the tolerance margin, then it doesn't do anything and it returns null; This operation assumes that the lengths of the interval is at least twice the tolerance.- Returns:
- returns the possibly modified inserted interval
-
insert
public T insert(T timeInterval)
Inserts an interval in the list if it doesn't overlap with an existing one.- Returns:
- returns the interval inserted
-
overlappingIterator
public Iterator<T> overlappingIterator(TimeInterval timeInterval)
Creates an iterator that iterates over all the timeintervals overlapping with timeInterval The timeInterval is considered closed at both ends [start, stop]
-
overlappingReverseIterator
public Iterator<T> overlappingReverseIterator(TimeInterval timeInterval)
Creates an iterator that iterates over all the timeintervals overlapping with timeInterval The timeInterval is considered closed at both ends [start, stop]
-
getFit
public T getFit(long t)
returns an interval where t would fit or null if there is no such interval- Returns:
- ti such that ti.getStart() <= t < ti.getEnd()
-
size
public int size()
-
iterator
public Iterator<T> iterator()
- Specified by:
iterator
in interfaceIterable<T extends TimeInterval>
-
get
public TimeInterval get(int i)
-
-