SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.interval
Class Intervals<T extends java.lang.Comparable<T>>

java.lang.Object
  extended by com.numericalmethod.suanshu.interval.Intervals<T>
Type Parameters:
T - a class that is Comparable
Direct Known Subclasses:
TimeIntervals

public class Intervals<T extends java.lang.Comparable<T>>
extends java.lang.Object

This class represents a disjoint set of Intervals.

This implementation keeps the disjointed intervals sorted in ascending order. That is, suppose I1 is indexed before I2. It means that the end of I1 is strictly smaller than the begin of I2, as defined by the partial ordering relation.


Constructor Summary
Intervals()
          Construct an empty set of Intervals.
Intervals(Interval<T>... intervals)
          Construct a set of Intervals from the given intervals.
Intervals(Interval<T> interval)
          Construct a set that contains only one Interval.
Intervals(Intervals<T> that)
          Copy constructor.
Intervals(T begin, T end)
          Construct a set that contains only one interval [begin, end].
 
Method Summary
 void add(Interval<T>... intervals)
          Add a collection of Intervals to the set.
 void add(Interval<T> interval)
          Add an Interval to the set.
 boolean equals(java.lang.Object obj)
           
 Interval<T> get(int i)
          Get the i-th interval.
 int hashCode()
           
 int size()
          Get the number of disjoint intervals.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Intervals

public Intervals()
Construct an empty set of Intervals.


Intervals

public Intervals(Interval<T> interval)
Construct a set that contains only one Interval.

Parameters:
interval - an Interval

Intervals

public Intervals(T begin,
                 T end)
Construct a set that contains only one interval [begin, end].

Parameters:
begin - the beginning of an Interval
end - the end of an Interval

Intervals

public Intervals(Interval<T>... intervals)
Construct a set of Intervals from the given intervals.

Parameters:
intervals - Intervals

Intervals

public Intervals(Intervals<T> that)
Copy constructor.

Parameters:
that - another Intervals
Method Detail

size

public int size()
Get the number of disjoint intervals.

Returns:
the number of disjoint intervals

get

public Interval<T> get(int i)
Get the i-th interval.

The intervals are sorted such that if I1 is indexed before I2, then the end of I1 is strictly smaller than the begin of I2.

Parameters:
i - the index, counting from 0
Returns:
the i-th interval

add

public void add(Interval<T> interval)
Add an Interval to the set.

The union remains disjoint and sorted.

Parameters:
interval - an Interval

add

public void add(Interval<T>... intervals)
Add a collection of Intervals to the set.

The set remains disjoint.

Parameters:
intervals - an array of Intervals

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

SuanShu, a Java numerical and statistical library

Copyright © 2011 Numerical Method Inc. Ltd. All Rights Reserved.