public final class TimeIntervalCollection extends Object implements List<TimeInterval>, IEquatable<TimeIntervalCollection>, IEquatableEpsilon<TimeIntervalCollection>, IFreezable
Constructor and Description |
---|
TimeIntervalCollection()
Initializes a new, empty interval collection.
|
TimeIntervalCollection(TimeInterval interval)
Initializes a new instance from a single interval.
|
TimeIntervalCollection(TimeIntervalCollection collection)
Initializes a new interval collection by copying an existing one.
|
Modifier and Type | Method and Description |
---|---|
void |
add(int index,
TimeInterval item)
Adds a time interval to the list.
|
boolean |
add(TimeInterval item)
Adds an interval to the interval collection.
|
void |
add(TimeIntervalCollection collection)
Adds another interval collection to this interval collection.
|
boolean |
addAll(Collection<? extends TimeInterval> c)
Appends all of the elements in the specified collection to the end of
this list, in the order that they are returned by the specified
collection's iterator (optional operation).
|
boolean |
addAll(int index,
Collection<? extends TimeInterval> c)
Inserts all of the elements in the specified collection into this
list at the specified position (optional operation).
|
<T> TimeIntervalCollection1<T> |
addData(T data)
Converts this collection to a
TimeIntervalCollection1 by
filling in the Data (get ) property for all intervals. |
void |
clear()
Removes all intervals from the interval collection.
|
TimeIntervalCollection |
complement(JulianDate startDate,
JulianDate endDate)
Computes the complement of this time interval collection.
|
boolean |
contains(JulianDate date)
Determines if the collection contains a specified date.
|
boolean |
contains(Object item)
Determines if this collection contains all of a specified interval.
|
boolean |
containsAll(Collection<?> c)
Returns true if this list contains all of the elements of the
specified collection.
|
void |
copyTo(TimeInterval[] array,
int arrayIndex)
Copies the intervals in this collection to an array.
|
boolean |
equals(Object obj)
Indicates whether another object is exactly equal to this instance.
|
static boolean |
equals(TimeIntervalCollection left,
TimeIntervalCollection right)
Returns
true if the two instances are exactly equal. |
boolean |
equalsEpsilon(TimeIntervalCollection other,
double epsilon)
Determines if this
TimeIntervalCollection is equal to another by comparing each of the TimeInterval elements in the two collections with TimeInterval.equalsEpsilon(agi.foundation.time.TimeInterval, double) . |
boolean |
equalsType(TimeIntervalCollection other)
Indicates whether another instance of this type is exactly equal to this instance.
|
TimeInterval |
findIntervalContainingDate(JulianDate date)
Finds the
TimeInterval in this collection that contains a specified date. |
void |
freeze()
Freezes this object.
|
TimeInterval |
get(int index)
Gets the interval at the specified index.
|
static TimeIntervalCollection |
getEmpty()
Gets an empty, read-only
TimeIntervalCollection . |
static TimeIntervalCollection |
getInfinite()
Gets an unbounded, infinite, read-only
TimeIntervalCollection . |
boolean |
getIsEmpty()
Gets a value indicating whether this interval collection is empty,
where emptiness is defined as the count of intervals being equal to zero.
|
boolean |
getIsFrozen()
Gets a value indicating whether this object is frozen.
|
boolean |
getIsInfinite()
Gets a value indicating whether the interval collection is infinite.
|
JulianDate |
getStart()
Gets the start date of the first interval in the collection.
|
JulianDate |
getStop()
Gets the stop date of the last interval in the collection
|
int |
hashCode()
Returns a hash code for this instance, which is suitable for use in hashing algorithms and data structures like a hash table.
|
int |
indexOf(JulianDate date)
Finds the index of the
TimeInterval in this collection
that contains the specified date. |
int |
indexOf(Object item)
Finds the index of a given
TimeInterval in the collection. |
TimeIntervalCollection |
intersect(TimeInterval interval)
Computes the intersection of this interval collection with an interval.
|
TimeIntervalCollection |
intersect(TimeIntervalCollection collection)
Computes the intersection of this interval collection with another.
|
boolean |
isEmpty()
Returns true if this list contains no elements.
|
Iterator<TimeInterval> |
iterator()
Gets an enumerator for this interval list.
|
int |
lastIndexOf(Object o)
Returns the index of the last occurrence of the specified element
in this list, or -1 if this list does not contain the element.
|
ListIterator<TimeInterval> |
listIterator()
Returns a list iterator over the elements in this list (in proper
sequence).
|
ListIterator<TimeInterval> |
listIterator(int index)
Returns a list iterator over the elements in this list (in proper
sequence), starting at the specified position in the list.
|
static boolean |
notEquals(TimeIntervalCollection left,
TimeIntervalCollection right)
Returns
true if the two instances are not exactly equal. |
TimeInterval |
remove(int index)
Removes the interval at a specified index in the collection.
|
boolean |
remove(Object item)
Removes the specified interval from this interval list, creating a hole
over the specified interval.
|
boolean |
remove(TimeIntervalCollection collection)
Removes the specified intervals from this interval list, creating a hole over the specified intervals.
|
boolean |
removeAll(Collection<?> c)
Removes from this list all of its elements that are contained in the
specified collection (optional operation).
|
boolean |
removeLeavingEndpoints(TimeInterval item)
Removes the specified interval from this interval list,
creating a hole over the specified interval.
|
boolean |
removeLeavingEndpoints(TimeIntervalCollection collection)
Removes the specified intervals from this interval list,
creating a hole over the specified intervals.
|
boolean |
retainAll(Collection<?> c)
Retains only the elements in this list that are contained in the
specified collection (optional operation).
|
TimeInterval |
set(int index,
TimeInterval value)
Sets the interval at the specified index.
|
int |
size()
Gets the number of intervals in this interval collection.
|
List<TimeInterval> |
subList(int fromIndex,
int toIndex)
Returns a view of the portion of this list between the specified
fromIndex, inclusive, and toIndex, exclusive.
|
Object[] |
toArray()
Returns an array containing all of the elements in this list in proper
sequence (from first to last element).
|
<T> T[] |
toArray(T[] a)
Returns an array containing all of the elements in this list in
proper sequence (from first to last element); the runtime type of
the returned array is that of the specified array.
|
Duration |
toDuration()
Returns a
Duration representing the span of time represented by the sum of the individual time intervals
in the collection. |
String |
toString()
Returns a string representation of the object.
|
TimeIntervalCollection |
toTimeStandard(TimeStandard timeStandard)
Converts all times in this time interval collection to be the specified time standard.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
replaceAll, sort, spliterator
parallelStream, removeIf, stream
public TimeIntervalCollection()
public TimeIntervalCollection(@Nonnull TimeIntervalCollection collection)
The new collection will not be IsFrozen
(get
), even if the original was.
collection
- The existing collection to copy.public TimeIntervalCollection(@Nonnull TimeInterval interval)
interval
- The interval to add to the collection.public final void freeze()
ObjectFrozenException
.freeze
in interface IFreezable
public final boolean getIsFrozen()
ObjectFrozenException
will be thrown if an attempt is made to do so.getIsFrozen
in interface IFreezable
@Nonnull public static TimeIntervalCollection getEmpty()
TimeIntervalCollection
.@Nonnull public static TimeIntervalCollection getInfinite()
TimeIntervalCollection
.public final void add(@Nullable TimeIntervalCollection collection)
collection
- The collection to add to this collection. This parameter can be
null, in which case nothing will be added.ObjectFrozenException
- Thrown when this TimeIntervalCollection
is read-only.public final boolean add(@Nonnull TimeInterval item)
add
in interface Collection<TimeInterval>
add
in interface List<TimeInterval>
item
- The interval to add.Collection.add(E)
)ObjectFrozenException
- Thrown when this TimeIntervalCollection
is read-only.@Nonnull public final TimeIntervalCollection intersect(@Nonnull TimeInterval interval)
The returned collection will only contain the intervals that are in both collections.
interval
- The interval to intersect with this collection@Nonnull public final TimeIntervalCollection intersect(@Nullable TimeIntervalCollection collection)
The returned collection will only contain the intervals that are in both collections.
collection
- The collection to intersect with this collection. The parameter
can be null, in which case Intersect returns this instance.public final void clear()
clear
in interface Collection<TimeInterval>
clear
in interface List<TimeInterval>
ObjectFrozenException
- Thrown when this TimeIntervalCollection
is read-only.public final boolean getIsEmpty()
TimeIntervalCollection.toDuration()
and check for equality with Zero
(get
).public final boolean getIsInfinite()
public final int indexOf(Object item)
TimeInterval
in the collection. This method requires
that the given interval exactly match an interval in the collection. Intervals with
different time standards or even slightly different values due to floating point noise
will be considered to be different.indexOf
in interface List<TimeInterval>
item
- The interval to find.public final int indexOf(@Nonnull JulianDate date)
TimeInterval
in this collection
that contains the specified date.date
- The Julian date to find.date
,
or if no interval starts after the specified date, the bitwise complement of Count
(get
).@Nullable public final TimeInterval findIntervalContainingDate(@Nonnull JulianDate date)
TimeInterval
in this collection that contains a specified date.date
- The date to look for in the collection.TimeInterval
in the collection that contains the date,
or null
if the collection does not contain the date at all.public final boolean contains(@Nonnull JulianDate date)
date
- The date to look for in the collection.true
if this interval collection contains the specified date; otherwise false
.public final boolean contains(@Nonnull Object item)
contains
in interface Collection<TimeInterval>
contains
in interface List<TimeInterval>
item
- The interval to check.true
if this interval collection contains the specified interval,
or false
if this collection has any gaps over the input interval.public final void copyTo(TimeInterval[] array, int arrayIndex)
array
- The destination array.arrayIndex
- The index at which to begin copying.public final int size()
size
in interface Collection<TimeInterval>
size
in interface List<TimeInterval>
public final boolean remove(@Nonnull TimeIntervalCollection collection)
collection
- The interval collection to remove.true
if any part of the input interval collection was in the interval collection; otherwise false
.public final TimeInterval remove(int index)
remove
in interface List<TimeInterval>
index
- The index of the interval to remove.public final boolean remove(@Nonnull Object item)
remove
in interface Collection<TimeInterval>
remove
in interface List<TimeInterval>
item
- The interval to remove.true
if any part of the input interval was in the interval list; otherwise false
.ObjectFrozenException
- Thrown when this TimeIntervalCollection
is read-only.public final boolean removeLeavingEndpoints(@Nonnull TimeIntervalCollection collection)
collection
- The interval collection to remove.true
if any part of the input interval collection was in the interval collection; otherwise false
.public final boolean removeLeavingEndpoints(@Nonnull TimeInterval item)
item
- The interval to remove.true
if any part of the input interval was in the interval list; otherwise false
.ObjectFrozenException
- Thrown when this TimeIntervalCollection
is read-only.@Nonnull public final TimeIntervalCollection complement(@Nonnull JulianDate startDate, @Nonnull JulianDate endDate)
The new TimeIntervalCollection
is the complement of this TimeIntervalCollection
within
the given startDate
and endDate
bounds. In other words,
the new TimeIntervalCollection
will represent all dates that are between the start and end dates
and that were NOT present in the original collection. Any dates before the given startDate
and
after the given endDate
are removed.
startDate
- The earliest date to include in the complement.endDate
- The latest date to include in the complement.@Nonnull public final TimeIntervalCollection toTimeStandard(TimeStandard timeStandard)
timeStandard
- The time standard to use.public final Iterator<TimeInterval> iterator()
iterator
in interface Iterable<TimeInterval>
iterator
in interface Collection<TimeInterval>
iterator
in interface List<TimeInterval>
public final TimeInterval get(int index)
get
in interface List<TimeInterval>
index
- The index.public final TimeInterval set(int index, TimeInterval value)
set
in interface List<TimeInterval>
index
- The index.value
- element to be stored at the specified position@Nonnull public final JulianDate getStart()
@Nonnull public final JulianDate getStop()
@Nonnull public final Duration toDuration()
Duration
representing the span of time represented by the sum of the individual time intervals
in the collection.public String toString()
java.lang.Object
toString
method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString
method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@
', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
public final boolean equalsType(TimeIntervalCollection other)
In order for two collections to be considered equal, each TimeInterval
in one collection must
be equal to the TimeInterval
at the same index in the other collection.
equalsType
in interface IEquatable<TimeIntervalCollection>
other
- The instance to compare to this instance.true
if other
represents the same value as this instance; otherwise false
.public int hashCode()
hashCode
in interface Collection<TimeInterval>
hashCode
in interface List<TimeInterval>
hashCode
in class Object
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
public boolean equals(Object obj)
In order for two collections to be considered equal, each TimeInterval
in one collection must
be equal to the TimeInterval
at the same index in the other collection.
equals
in interface Collection<TimeInterval>
equals
in interface List<TimeInterval>
equals
in class Object
obj
- The object to compare to this instance.true
if obj
is an instance of this type and represents the same value as this instance; otherwise false
.Object.hashCode()
,
HashMap
public static boolean equals(TimeIntervalCollection left, TimeIntervalCollection right)
true
if the two instances are exactly equal.
In order for two collections to be considered equal, each TimeInterval
in one collection must
be equal to the TimeInterval
at the same index in the other collection.
left
- The instance to compare to right
.right
- The instance to compare to left
.true
if left
represents the same value as right
; otherwise false
.public static boolean notEquals(TimeIntervalCollection left, TimeIntervalCollection right)
true
if the two instances are not exactly equal.
In order for two collections to be considered equal, each TimeInterval
in one collection must
be equal to the TimeInterval
at the same index in the other collection.
left
- The instance to compare to right
.right
- The instance to compare to left
.true
if left
does not represent the same value as right
; otherwise false
.public final boolean equalsEpsilon(TimeIntervalCollection other, double epsilon)
TimeIntervalCollection
is equal to another by comparing each of the TimeInterval
elements in the two collections with TimeInterval.equalsEpsilon(agi.foundation.time.TimeInterval, double)
.equalsEpsilon
in interface IEquatableEpsilon<TimeIntervalCollection>
other
- A TimeIntervalCollection
to compare this one to.epsilon
- The largest difference between the Start and Stop dates, in seconds, such that they will be considered equal.TimeIntervals
are equal as defined by the epsilon value.@Nonnull public final <T> TimeIntervalCollection1<T> addData(T data)
TimeIntervalCollection1
by
filling in the Data
(get
) property for all intervals.T
- The type of the data.data
- The value of the Data
(get
) property for all intervals in the new collection.public final void add(int index, TimeInterval item)
TimeIntervalCollection.add(TimeInterval)
- the
index
parameter is ignored.add
in interface List<TimeInterval>
index
- Ignored.item
- The interval to add to this collection.public final boolean isEmpty()
java.util.List
isEmpty
in interface Collection<TimeInterval>
isEmpty
in interface List<TimeInterval>
public final boolean addAll(Collection<? extends TimeInterval> c)
java.util.List
addAll
in interface Collection<TimeInterval>
addAll
in interface List<TimeInterval>
c
- collection containing elements to be added to this listList.add(Object)
public final boolean addAll(int index, Collection<? extends TimeInterval> c)
java.util.List
addAll
in interface List<TimeInterval>
index
- index at which to insert the first element from the
specified collectionc
- collection containing elements to be added to this listpublic final boolean containsAll(Collection<?> c)
java.util.List
containsAll
in interface Collection<TimeInterval>
containsAll
in interface List<TimeInterval>
c
- collection to be checked for containment in this listList.contains(Object)
public final Object[] toArray()
java.util.List
The returned array will be "safe" in that no references to it are maintained by this list. (In other words, this method must allocate a new array even if this list is backed by an array). The caller is thus free to modify the returned array.
This method acts as bridge between array-based and collection-based APIs.
toArray
in interface Collection<TimeInterval>
toArray
in interface List<TimeInterval>
Arrays.asList(Object[])
public final <T> T[] toArray(T[] a)
java.util.List
If the list fits in the specified array with room to spare (i.e., the array has more elements than the list), the element in the array immediately following the end of the list is set to null. (This is useful in determining the length of the list only if the caller knows that the list does not contain any null elements.)
Like the List.toArray()
method, this method acts as bridge between
array-based and collection-based APIs. Further, this method allows
precise control over the runtime type of the output array, and may,
under certain circumstances, be used to save allocation costs.
Suppose x is a list known to contain only strings. The following code can be used to dump the list into a newly allocated array of String:
String[] y = x.toArray(new String[0]);
Note that toArray(new Object[0]) is identical in function to
toArray().toArray
in interface Collection<TimeInterval>
toArray
in interface List<TimeInterval>
T
- the runtime type of the array to contain the collectiona
- the array into which the elements of this list are to
be stored, if it is big enough; otherwise, a new array of the
same runtime type is allocated for this purpose.public final int lastIndexOf(Object o)
java.util.List
lastIndexOf
in interface List<TimeInterval>
o
- element to search forpublic final ListIterator<TimeInterval> listIterator()
java.util.List
listIterator
in interface List<TimeInterval>
public final ListIterator<TimeInterval> listIterator(int index)
java.util.List
next
.
An initial call to previous
would
return the element with the specified index minus one.listIterator
in interface List<TimeInterval>
index
- index of the first element to be returned from the
list iterator (by a call to next
)public final List<TimeInterval> subList(int fromIndex, int toIndex)
java.util.List
This method eliminates the need for explicit range operations (of the sort that commonly exist for arrays). Any operation that expects a list can be used as a range operation by passing a subList view instead of a whole list. For example, the following idiom removes a range of elements from a list:
list.subList(from, to).clear();
Similar idioms may be constructed for indexOf and
lastIndexOf, and all of the algorithms in the
Collections class can be applied to a subList.The semantics of the list returned by this method become undefined if the backing list (i.e., this list) is structurally modified in any way other than via the returned list. (Structural modifications are those that change the size of this list, or otherwise perturb it in such a fashion that iterations in progress may yield incorrect results.)
subList
in interface List<TimeInterval>
fromIndex
- low endpoint (inclusive) of the subListtoIndex
- high endpoint (exclusive) of the subListpublic final boolean removeAll(Collection<?> c)
java.util.List
removeAll
in interface Collection<TimeInterval>
removeAll
in interface List<TimeInterval>
c
- collection containing elements to be removed from this listList.remove(Object)
,
List.contains(Object)
public final boolean retainAll(Collection<?> c)
java.util.List
retainAll
in interface Collection<TimeInterval>
retainAll
in interface List<TimeInterval>
c
- collection containing elements to be retained in this listList.remove(Object)
,
List.contains(Object)