org.jscience.mathematics.analysis
Class IntervalsList

java.lang.Object
  extended by org.jscience.mathematics.analysis.IntervalsList
All Implemented Interfaces:
Set

public class IntervalsList
extends java.lang.Object
implements Set

This class represents an intervals list.

An interval list represent a list of contiguous regions on the real line. All intervals of the list are disjoints to each other, they are stored in ascending order.

Empty intervals are discarted. All intervals in the list must use the same ComparableNumber class.

The class supports the main set operations like union and intersection.

See Also:
Interval

Constructor Summary
IntervalsList()
          Build an empty intervals list.
IntervalsList(Interval i)
          Build an intervals list containing only one interval.
IntervalsList(Interval i1, Interval i2)
          Build an intervals list containing two intervals.
IntervalsList(IntervalsList list)
          Copy constructor.
 
Method Summary
 int cardinality()
          Returns the cardinality (the number of elements).
 boolean contains(ComparableNumber x)
          Check if the list contains a point.
 boolean contains(Interval i)
          Check if the list contains an interval.
 boolean contains(java.lang.Object o)
          Check if contains the specified element in this set.
 boolean equals(java.lang.Object o)
          DOCUMENT ME!
 java.lang.Class getDomain()
           
 Interval getInterval(int i)
          Get an interval from the list.
 java.util.List getIntervals()
          Get the ordered list of disjoints intervals.
 int getSize()
          Get the number of intervals of the list.
 int hashCode()
          Returns the hash code value for this set.
 IntervalsList insert(ComparableNumber c)
          DOCUMENT ME!
 IntervalsList insert(Interval i)
          Add an interval to the instance.
 IntervalsList insert(IntervalsList list)
          Add an intervals list to the instance.
 boolean insert(java.lang.Object o)
          Inserts the specified element in this set if it is present.
 IntervalsList intersect(Interval i)
          Intersects the instance and an interval.
 IntervalsList intersect(IntervalsList list)
          Intersect the instance and another intervals list.
 Set intersection(Set set)
          DOCUMENT ME!
 boolean intersects(Interval i)
          Check if an interval intersects the instance.
 boolean isConnex()
          Check if the instance is connected.
 boolean isEmpty()
          Check if the instance is empty.
 java.util.Iterator iterator()
          Returns an iterator over the elements in this set.
 IntervalsList remove(ComparableNumber c)
          DOCUMENT ME!
 IntervalsList remove(Interval i)
          Remove an interval from the list.
 IntervalsList remove(IntervalsList list)
          Remove an intervals list from the instance.
 boolean remove(java.lang.Object o)
          Removes the specified element from this set if it is present (optional operation).
 Set subtraction(Set set)
          DOCUMENT ME!
 java.lang.Object[] toArray()
          Returns an array containing all of the elements in this set.
 java.lang.String toString()
          Returns a string representing this set.
 Set union(Set set)
          DOCUMENT ME!
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IntervalsList

public IntervalsList()
Build an empty intervals list.


IntervalsList

public IntervalsList(Interval i)
Build an intervals list containing only one interval.

Parameters:
i - interval

IntervalsList

public IntervalsList(Interval i1,
                     Interval i2)
Build an intervals list containing two intervals.

Parameters:
i1 - first interval
i2 - second interval
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

IntervalsList

public IntervalsList(IntervalsList list)
Copy constructor.

The copy operation is a deep copy: the underlying intervals are independant of the instances of the copied list.

Parameters:
list - intervals list to copy
Method Detail

isEmpty

public boolean isEmpty()
Check if the instance is empty.

Specified by:
isEmpty in interface Set
Returns:
true if the instance is empty

getDomain

public java.lang.Class getDomain()

isConnex

public boolean isConnex()
Check if the instance is connected.

An interval list is connected if it contains only one interval.

Returns:
true is the instance is connected

getSize

public int getSize()
Get the number of intervals of the list.

Returns:
number of intervals in the list

getInterval

public Interval getInterval(int i)
Get an interval from the list.

Parameters:
i - index of the interval
Returns:
interval at index i

getIntervals

public java.util.List getIntervals()
Get the ordered list of disjoints intervals.

Returns:
list of disjoints intervals in ascending order

cardinality

public int cardinality()
Returns the cardinality (the number of elements).

Specified by:
cardinality in interface Set
Returns:
DOCUMENT ME!

contains

public boolean contains(java.lang.Object o)
Check if contains the specified element in this set.

Specified by:
contains in interface Set
Parameters:
o - - object to be checked.
Returns:
true if the set contained the specified element.

contains

public boolean contains(ComparableNumber x)
Check if the list contains a point.

Parameters:
x - point to check
Returns:
true if the list contains x
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

contains

public boolean contains(Interval i)
Check if the list contains an interval.

Parameters:
i - interval to check
Returns:
true if i is completely included in the instance
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

intersects

public boolean intersects(Interval i)
Check if an interval intersects the instance.

Parameters:
i - interval to check
Returns:
true if i intersects the instance
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

insert

public boolean insert(java.lang.Object o)
Inserts the specified element in this set if it is present.

Parameters:
o - - object to be inserted from this set, if present.
Returns:
true if the set contained the specified element.
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

insert

public IntervalsList insert(ComparableNumber c)
DOCUMENT ME!

Parameters:
c - DOCUMENT ME!
Returns:
DOCUMENT ME!

insert

public IntervalsList insert(Interval i)
Add an interval to the instance.

This method expands the instance.

This operation is a union operation. The number of intervals in the list can decrease if the interval fills some holes between existing intervals in the list.

Parameters:
i - interval to add to the instance
Returns:
DOCUMENT ME!
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

remove

public boolean remove(java.lang.Object o)
Removes the specified element from this set if it is present (optional operation).

Specified by:
remove in interface Set
Parameters:
o - - object to be removed from this set, if present.
Returns:
true if the set contained the specified element.
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

remove

public IntervalsList remove(ComparableNumber c)
DOCUMENT ME!

Parameters:
c - DOCUMENT ME!
Returns:
DOCUMENT ME!

remove

public IntervalsList remove(Interval i)
Remove an interval from the list.

This method reduces the instance. This operation is defined in terms of points set operation. As an example, if the [2, 3] interval is subtracted from the list containing only the [0, 10] interval, the result will be the [0, 2[ U ]3, 10] intervals list.

Parameters:
i - interval to remove
Returns:
DOCUMENT ME!
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

intersect

public IntervalsList intersect(Interval i)
Intersects the instance and an interval.

Parameters:
i - interval
Returns:
DOCUMENT ME!
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

insert

public IntervalsList insert(IntervalsList list)
Add an intervals list to the instance.

This method expands the instance.

This operation is a union operation. The number of intervals in the list can decrease if the list fills some holes between existing intervals in the instance.

Parameters:
list - intervals list to add to the instance
Returns:
DOCUMENT ME!
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

remove

public IntervalsList remove(IntervalsList list)
Remove an intervals list from the instance.

Parameters:
list - intervals list to remove
Returns:
DOCUMENT ME!
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

intersect

public IntervalsList intersect(IntervalsList list)
Intersect the instance and another intervals list.

Parameters:
list - list to intersect with the instance
Returns:
DOCUMENT ME!
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

intersection

public Set intersection(Set set)
DOCUMENT ME!

Specified by:
intersection in interface Set
Parameters:
set - DOCUMENT ME!
Returns:
DOCUMENT ME!

union

public Set union(Set set)
DOCUMENT ME!

Specified by:
union in interface Set
Parameters:
set - DOCUMENT ME!
Returns:
DOCUMENT ME!

subtraction

public Set subtraction(Set set)
DOCUMENT ME!

Parameters:
set - DOCUMENT ME!
Returns:
DOCUMENT ME!

equals

public boolean equals(java.lang.Object o)
DOCUMENT ME!

Specified by:
equals in interface Set
Overrides:
equals in class java.lang.Object
Parameters:
o - DOCUMENT ME!
Returns:
DOCUMENT ME!

hashCode

public int hashCode()
Returns the hash code value for this set.

Specified by:
hashCode in interface Set
Overrides:
hashCode in class java.lang.Object
Returns:
the hash code value for this set.

toString

public java.lang.String toString()
Returns a string representing this set.

Overrides:
toString in class java.lang.Object
Returns:
DOCUMENT ME!

iterator

public java.util.Iterator iterator()
Returns an iterator over the elements in this set.

Specified by:
iterator in interface Set
Returns:
an iterator over the elements in this set.

toArray

public java.lang.Object[] toArray()
Returns an array containing all of the elements in this set.

Specified by:
toArray in interface Set
Returns:
an array containing all of the elements in this set.