edu.umd.cfar.lamp.viper.util
Class Range

java.lang.Object
  extended byedu.umd.cfar.lamp.viper.util.Range
All Implemented Interfaces:
java.lang.Cloneable, java.util.Collection, IntervalIndexList, java.util.Set
Direct Known Subclasses:
InstantRange

public class Range
extends java.lang.Object
implements java.lang.Cloneable, java.util.Set, IntervalIndexList

This class represents a set of Intervals. Note that all indexes must all be Comparable.


Nested Class Summary
 
Nested classes inherited from class edu.umd.cfar.lamp.viper.util.IntervalIndexList
IntervalIndexList.Change
 
Constructor Summary
Range()
          Creates a new, empty Range.
Range(java.util.Collection c)
          Creates a new Range from a Collection of Span objects.
Range(java.util.Comparator c)
          Creates a new, empty Range.
 
Method Summary
 boolean add(java.lang.Comparable start, java.lang.Comparable stop)
          Subsumes the Instants in the Span into this Range.
 boolean add(java.lang.Object o)
           
 boolean addAll(java.util.Collection c)
           
 boolean addAll(IntervalIndexList l)
          Adds all the elements from the given list at their specified locations
 boolean addAll(java.util.Iterator iter)
          Adds all the elements described by the iterator.
 void clear()
          Removes all elements from the list.
 java.lang.Object clone()
           
protected  void cloneInto(Range r)
           
 boolean contains(java.lang.Object o)
           
 boolean containsAll(java.util.Collection c)
           
 Interval createInterval(java.lang.Comparable s, java.lang.Comparable e)
          Creates a new interval.
 java.lang.Comparable endOf(java.lang.Comparable c)
          Gets the end of the element in which c is contained.
 boolean equals(java.lang.Object o)
           
 java.lang.Comparable firstAfter(java.lang.Comparable oldStart)
          Gets the start of the first element that begins strictly after c.
 java.lang.Comparable firstAfterOrAt(java.lang.Comparable oldStart)
          Gets the start of the first element that begins at c or after it.
 java.lang.Comparable firstBefore(java.lang.Comparable oldStart)
          Gets the start of the first element before c, exclusive.
 java.lang.Object get(java.lang.Comparable index)
          Returns null if the moment is in the span, otherwise returns Boolean.TRUE.
 int getContiguousIntervalCount()
          Gets a count of the contiguous (and homogenous, for those sort of things) intervals in the list.
 Interval getExtrema()
          Gets the Span that starts at the beginning of the first Span and ends at the end of the last Span.
 int hashCode()
           
 Range intersect(IntervalIndexList list)
          Gets the range shared by this and the specified range.
 Range intersectComplement(Range o)
          Gets all elements from this that are not elements of the specified range.
 boolean intersects(Interval s)
          Checks to see if some interval of this intersects the specified interval.
 boolean intersects(Range r)
          Tests to see if the this intersects the other range.
 boolean intersects(java.util.Set s)
          Tests to see if this range contains any element or intersects any element of the specified set.
 boolean isEmpty()
          True if no elements are described in the list.
 java.util.Iterator iterator()
          Gets an iterator over all the Interval objects here.
 java.util.Iterator iterator(Interval i)
          Gets an iterator over all the Interval objects that intersect the given Interval.
 void map(IntervalIndexList.Change c)
          Changes all the values of the elements by the given change function object.
 boolean remove(java.lang.Comparable start, java.lang.Comparable end)
          Removes all values at the given range.
 boolean remove(java.lang.Object o)
           
 boolean removeAll(java.util.Collection c)
           
 boolean retainAll(java.util.Collection c)
          TODO: currently unsupported
 void set(java.lang.Comparable start, java.lang.Comparable stop, java.lang.Object value)
          Since this is just a range, this ignores the value object except to check if it is "null".
 boolean setSpans(java.util.Collection s)
          Adds all of the Span objects in the Collection s to this one.
 int size()
          Gets the number of disconnected ranges of Instants this Range contains.
 IntervalIndexList subList(java.lang.Comparable start, java.lang.Comparable stop)
          Gets the sublist in the given interval
 java.lang.Object[] toArray()
           
 java.lang.Object[] toArray(java.lang.Object[] A)
           
 java.lang.String toString()
          Returns the list as a space delimited of "s:e" pairs.
 Range union(Range o)
          Gets the union of this and the specified range.
 boolean withinRange(java.lang.Comparable s, java.lang.Comparable e)
          Checks to see if the interval defined as [s,e) is entirely contained within this Range object.
 boolean withinRange(Interval s)
          Checks that this is
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Range

public Range()
Creates a new, empty Range.


Range

public Range(java.util.Comparator c)
Creates a new, empty Range.

Parameters:
c - The comparison to use while adding items to the range.

Range

public Range(java.util.Collection c)
Creates a new Range from a Collection of Span objects.

Parameters:
c - the intervals to add
Method Detail

size

public int size()
Gets the number of disconnected ranges of Instants this Range contains. Note this is not the number of total Instants included in the Range.

Specified by:
size in interface java.util.Set
Returns:
number of discrete sections of time covered by this Range.

withinRange

public boolean withinRange(Interval s)
Checks that this is

Parameters:
s -
Returns:

withinRange

public boolean withinRange(java.lang.Comparable s,
                           java.lang.Comparable e)
Checks to see if the interval defined as [s,e) is entirely contained within this Range object.

Parameters:
s -
e -
Returns:
boolean

get

public java.lang.Object get(java.lang.Comparable index)
Returns null if the moment is in the span, otherwise returns Boolean.TRUE. This is pretty hackish.

Specified by:
get in interface IntervalIndexList
Parameters:
index - the index to see if is in range
Returns:
null or Boolean.TRUE

set

public void set(java.lang.Comparable start,
                java.lang.Comparable stop,
                java.lang.Object value)
Since this is just a range, this ignores the value object except to check if it is "null". Setting to Null, or Boolean.FALSE, is the same as removing an Interval.

Specified by:
set in interface IntervalIndexList
Parameters:
start - the start point, inclusive
stop - the end point, exclusive
value - the value to set over the given range

add

public boolean add(java.lang.Comparable start,
                   java.lang.Comparable stop)
Subsumes the Instants in the Span into this Range.

Parameters:
start - the first instant to add
stop - the stop instant, exclusive
Returns:
true iff the operation modified this Range

getExtrema

public Interval getExtrema()
Gets the Span that starts at the beginning of the first Span and ends at the end of the last Span.

Returns:
Span a Span that has all the others as a subset. Null if empty.

remove

public boolean remove(java.lang.Comparable start,
                      java.lang.Comparable end)
Description copied from interface: IntervalIndexList
Removes all values at the given range. Note that, like SortedMap, this means that value is set in the range from start, inclusive, to stop, exclusive.

Specified by:
remove in interface IntervalIndexList
Parameters:
start - the first index to remove
end - the first index that is not removed
Returns:
true if any elements were removed
See Also:
IntervalIndexList.remove(java.lang.Comparable, java.lang.Comparable)

setSpans

public boolean setSpans(java.util.Collection s)
Adds all of the Span objects in the Collection s to this one. It won't remove any of the current Instants.

Parameters:
s - a set of homogenous type Span objects
Returns:
true if any new Instants are now part of this set.

cloneInto

protected void cloneInto(Range r)

clone

public java.lang.Object clone()
See Also:
Object.clone()

add

public boolean add(java.lang.Object o)
Specified by:
add in interface java.util.Set
See Also:
Set.add(java.lang.Object)

addAll

public boolean addAll(java.util.Iterator iter)
Adds all the elements described by the iterator.

Parameters:
iter - the elements to add
Returns:
if this changed

addAll

public boolean addAll(java.util.Collection c)
Specified by:
addAll in interface java.util.Set
See Also:
Set.addAll(java.util.Collection)

clear

public void clear()
Description copied from interface: IntervalIndexList
Removes all elements from the list.

Specified by:
clear in interface java.util.Set
See Also:
Set.clear()

contains

public boolean contains(java.lang.Object o)
Specified by:
contains in interface java.util.Set
See Also:
Set.contains(java.lang.Object)

containsAll

public boolean containsAll(java.util.Collection c)
Specified by:
containsAll in interface java.util.Set
See Also:
Set.containsAll(java.util.Collection)

isEmpty

public boolean isEmpty()
Description copied from interface: IntervalIndexList
True if no elements are described in the list.

Specified by:
isEmpty in interface java.util.Set
See Also:
Set.isEmpty()

iterator

public java.util.Iterator iterator()
Description copied from interface: IntervalIndexList
Gets an iterator over all the Interval objects here. Note that, if the

Specified by:
iterator in interface java.util.Set

iterator

public java.util.Iterator iterator(Interval i)
Description copied from interface: IntervalIndexList
Gets an iterator over all the Interval objects that intersect the given Interval.

Specified by:
iterator in interface IntervalIndexList
Returns:

remove

public boolean remove(java.lang.Object o)
Specified by:
remove in interface java.util.Set
See Also:
Set.remove(java.lang.Object)

removeAll

public boolean removeAll(java.util.Collection c)
Specified by:
removeAll in interface java.util.Set
See Also:
Set.removeAll(java.util.Collection)

retainAll

public boolean retainAll(java.util.Collection c)
TODO: currently unsupported

Specified by:
retainAll in interface java.util.Set
See Also:
Set.retainAll(java.util.Collection)

toArray

public java.lang.Object[] toArray()
Specified by:
toArray in interface java.util.Set
See Also:
Set.toArray()

toArray

public java.lang.Object[] toArray(java.lang.Object[] A)
Specified by:
toArray in interface java.util.Set
See Also:
Set.toArray(java.lang.Object[])

toString

public java.lang.String toString()
Returns the list as a space delimited of "s:e" pairs.

See Also:
Object.toString()

equals

public boolean equals(java.lang.Object o)
Specified by:
equals in interface java.util.Set
See Also:
Set.equals(java.lang.Object)

hashCode

public int hashCode()
Specified by:
hashCode in interface java.util.Set
See Also:
Set.hashCode()

intersects

public boolean intersects(java.util.Set s)
Tests to see if this range contains any element or intersects any element of the specified set.

Parameters:
s - the set to test against
Returns:
if there is an intersection/shared item

intersects

public boolean intersects(Range r)
Tests to see if the this intersects the other range.

Parameters:
r - the range to test against
Returns:
true if there is some shared interval

intersects

public boolean intersects(Interval s)
Checks to see if some interval of this intersects the specified interval.

Parameters:
s - the interval to test against
Returns:
true if there is some overlap

intersect

public Range intersect(IntervalIndexList list)
Gets the range shared by this and the specified range.

Parameters:
list - the list to intersect with
Returns:
the shared range

firstBefore

public java.lang.Comparable firstBefore(java.lang.Comparable oldStart)
Description copied from interface: IntervalIndexList
Gets the start of the first element before c, exclusive.

Specified by:
firstBefore in interface IntervalIndexList
Parameters:
oldStart - Where to start looking backwards from
Returns:
the start of the last element that starts before c; null if none found
See Also:
IntervalIndexList.firstBefore(java.lang.Comparable)

firstAfter

public java.lang.Comparable firstAfter(java.lang.Comparable oldStart)
Description copied from interface: IntervalIndexList
Gets the start of the first element that begins strictly after c.

Specified by:
firstAfter in interface IntervalIndexList
Parameters:
oldStart - the place to start looking
Returns:
the start of the first element after c; null if none found
See Also:
IntervalIndexList.firstAfter(java.lang.Comparable)

firstAfterOrAt

public java.lang.Comparable firstAfterOrAt(java.lang.Comparable oldStart)
Description copied from interface: IntervalIndexList
Gets the start of the first element that begins at c or after it.

Specified by:
firstAfterOrAt in interface IntervalIndexList
Parameters:
oldStart - the place to start looking
Returns:
the start of the first element after or at c; null if none found
See Also:
IntervalIndexList.firstAfterOrAt(java.lang.Comparable)

endOf

public java.lang.Comparable endOf(java.lang.Comparable c)
Description copied from interface: IntervalIndexList
Gets the end of the element in which c is contained.

Specified by:
endOf in interface IntervalIndexList
Parameters:
c - the element to check
Returns:
the end, if found; null if c isn't within an interval described by this list
See Also:
IntervalIndexList.endOf(java.lang.Comparable)

union

public Range union(Range o)
Gets the union of this and the specified range.

Parameters:
o - the range to union with
Returns:
a new range containing all items in either this or the specified range

intersectComplement

public Range intersectComplement(Range o)
Gets all elements from this that are not elements of the specified range.

Parameters:
o - the range to complement
Returns:
this - that

addAll

public boolean addAll(IntervalIndexList l)
Description copied from interface: IntervalIndexList
Adds all the elements from the given list at their specified locations

Specified by:
addAll in interface IntervalIndexList
Parameters:
l - the list to add
Returns:
true if this changed
See Also:
IntervalIndexList.addAll(edu.umd.cfar.lamp.viper.util.IntervalIndexList)

subList

public IntervalIndexList subList(java.lang.Comparable start,
                                 java.lang.Comparable stop)
Description copied from interface: IntervalIndexList
Gets the sublist in the given interval

Specified by:
subList in interface IntervalIndexList
Parameters:
start - the start of the chop, inclusive
stop - the end of the chop, exclusive
Returns:
a sublist. It may be wired to the containing list, or may be a copy or immutable, depending on the implementor
See Also:
IntervalIndexList.subList(java.lang.Comparable, java.lang.Comparable)

map

public void map(IntervalIndexList.Change c)
Description copied from interface: IntervalIndexList
Changes all the values of the elements by the given change function object.

Specified by:
map in interface IntervalIndexList
Parameters:
c - the method to apply to all elements
See Also:
IntervalIndexList.map(edu.umd.cfar.lamp.viper.util.IntervalIndexList.Change)

createInterval

public Interval createInterval(java.lang.Comparable s,
                               java.lang.Comparable e)
Creates a new interval. This is used instead of a constructor, so subclasses of this range which wish to return subclasses of interval should override this method.

Parameters:
s -
e -
Returns:

getContiguousIntervalCount

public int getContiguousIntervalCount()
Description copied from interface: IntervalIndexList
Gets a count of the contiguous (and homogenous, for those sort of things) intervals in the list.

Specified by:
getContiguousIntervalCount in interface IntervalIndexList
Returns:
See Also:
IntervalIndexList.getContiguousIntervalCount()