org.spaceroots.mantissa.utilities
Class IntervalsList

java.lang.Object
  extended byorg.spaceroots.mantissa.utilities.IntervalsList

public class IntervalsList
extends Object

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.

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

Version:
$Id: IntervalsList.java 1694 2006-09-03 19:53:48Z luc $
Author:
Luc Maisonobe
See Also:
Interval

Constructor Summary
IntervalsList()
          Build an empty intervals list.
IntervalsList(double a, double b)
          Build an intervals list containing only one interval.
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
static IntervalsList add(IntervalsList list, Interval i)
          Add an intervals list and an interval.
static IntervalsList add(IntervalsList list1, IntervalsList list2)
          Add two intervals lists.
 void addToSelf(Interval i)
          Add an interval to the instance.
 void addToSelf(IntervalsList list)
          Add an intervals list to the instance.
 boolean contains(double x)
          Check if the list contains a point.
 boolean contains(Interval i)
          Check if the list contains an interval.
 double getInf()
          Get the lower bound of the list.
 Interval getInterval(int i)
          Get an interval from the list.
 List getIntervals()
          Get the ordered list of disjoints intervals.
 int getSize()
          Get the number of intervals of the list.
 double getSup()
          Get the upper bound of the list.
static IntervalsList intersection(IntervalsList list, Interval i)
          Intersect a list and an interval.
static IntervalsList intersection(IntervalsList list1, IntervalsList list2)
          Intersect two intervals lists.
 boolean intersects(Interval i)
          Check if an interval intersects the instance.
 void intersectSelf(Interval i)
          Intersects the instance and an interval.
 void intersectSelf(IntervalsList list)
          Intersect the instance and another intervals list.
 boolean isConnex()
          Check if the instance is connected.
 boolean isEmpty()
          Check if the instance is empty.
static IntervalsList subtract(IntervalsList list, Interval i)
          Remove an interval from a list.
static IntervalsList subtract(IntervalsList list1, IntervalsList list2)
          Remove an intervals list from another one.
 void subtractFromSelf(Interval i)
          Remove an interval from the list.
 void subtractFromSelf(IntervalsList list)
          Remove an intervals list from the instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IntervalsList

public IntervalsList()
Build an empty intervals list.


IntervalsList

public IntervalsList(double a,
                     double b)
Build an intervals list containing only one interval.

Parameters:
a - first bound of the interval
b - second bound of the interval

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

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.

Returns:
true if the instance is empty

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

getInf

public double getInf()
Get the lower bound of the list.

Returns:
lower bound of the list or Double.NaN if the list does not contain any interval

getSup

public double getSup()
Get the upper bound of the list.

Returns:
upper bound of the list or Double.NaN if the list does not contain any interval

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 List getIntervals()
Get the ordered list of disjoints intervals.

Returns:
list of disjoints intervals in ascending order

contains

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

Parameters:
x - point to check
Returns:
true if the list contains x

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

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

addToSelf

public void addToSelf(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

add

public static IntervalsList add(IntervalsList list,
                                Interval i)
Add an intervals list and an interval.

Parameters:
list - intervals list
i - interval
Returns:
a new intervals list which is the union of list and i

subtractFromSelf

public void subtractFromSelf(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

subtract

public static IntervalsList subtract(IntervalsList list,
                                     Interval i)
Remove an interval from a list.

Parameters:
list - intervals list
i - interval to remove
Returns:
a new intervals list

intersectSelf

public void intersectSelf(Interval i)
Intersects the instance and an interval.

Parameters:
i - interval

intersection

public static IntervalsList intersection(IntervalsList list,
                                         Interval i)
Intersect a list and an interval.

Parameters:
list - intervals list
i - interval
Returns:
the intersection of list and i

addToSelf

public void addToSelf(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

add

public static IntervalsList add(IntervalsList list1,
                                IntervalsList list2)
Add two intervals lists.

Parameters:
list1 - first intervals list
list2 - second intervals list
Returns:
a new intervals list which is the union of list1 and list2

subtractFromSelf

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

Parameters:
list - intervals list to remove

subtract

public static IntervalsList subtract(IntervalsList list1,
                                     IntervalsList list2)
Remove an intervals list from another one.

Parameters:
list1 - intervals list
list2 - intervals list to remove
Returns:
a new intervals list

intersectSelf

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

Parameters:
list - list to intersect with the instance

intersection

public static IntervalsList intersection(IntervalsList list1,
                                         IntervalsList list2)
Intersect two intervals lists.

Parameters:
list1 - first intervals list
list2 - second intervals list
Returns:
a new list which is the intersection of list1 and list2


Copyright © 2001-2007 Luc Maisonobe. All Rights Reserved.