data
Class IntervalList

java.lang.Object
  extended by data.IntervalList
All Implemented Interfaces:
java.io.Serializable

public class IntervalList
extends java.lang.Object
implements java.io.Serializable

IntervalList

This class represents a list of intervals, i.e. a subset of the real numbers. An empty list is represented by an IntervalList of zero length (getLength() returns zero).

Copyright(c) 2005 Université Laval, LSFM research group.

Version:
1.0
Author:
Nicolas Richard
See Also:
Interval, Serialized Form

Constructor Summary
IntervalList()
          Constructor with no parameter... creates an empty list.
IntervalList(Interval i)
          Constructor with one interval as parameter...
IntervalList(IntervalList l)
          Copy constructor ...
IntervalList(java.lang.String s)
          Construct a list of interval from a string.
 
Method Summary
 void add(Interval i)
          Add the interval i to the current list, unifying if necessary.
 void add(java.lang.String interval)
          Add an interval in the form of a string.
 IntervalList copy()
          Returns a copy of the current list.
 boolean equals(java.lang.Object o)
          Returns true if the object is semantically equivalent to the current list.
 Interval getIntervalAt(int index)
          Returns the interval at the specified index.
 int getSize()
          Returns the number of intervals in the list.
 int indexOf(double v)
          This methods find the value v in the interval list and returns the index of the interval which contains the v value.
static IntervalList intersectionOf(IntervalList list1, IntervalList list2)
          Returns the intersection of two lists.
 boolean isEmpty()
          Returns 'True' if the list is empty.
 boolean isIn(double v)
          Returns 'True' should the value be part of an interval of the list
 boolean isIncluded(Interval smaller)
          Returns true if the interval is included or equal to the current list.
 boolean isIncluded(IntervalList smaller)
          Returns true if the smaller interval is included into the list or is equal
static IntervalList substract(IntervalList s, IntervalList l)
          This methods compute the negation of the division of the two sets
 java.lang.String toString()
          Convert the current list a string.
static IntervalList union(IntervalList list, Interval i)
          Compute the unification of an interval with a list.
static IntervalList union(IntervalList list1, IntervalList list2)
          Unify two list of intervals.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IntervalList

public IntervalList()
Constructor with no parameter... creates an empty list.


IntervalList

public IntervalList(Interval i)
Constructor with one interval as parameter... Creates a new list containing only i.

Parameters:
i - the interval to include in the list

IntervalList

public IntervalList(java.lang.String s)
             throws DataParserException
Construct a list of interval from a string. The string must include valid interval constructions separated by "U" for union.

For example : [0,5] U {6} U (-10,-3]
The intervals do not need to be sorted.

Parameters:
s - a valid chain representing an interval list
Throws:
DataParserException - should the string not respect the IntervalList format

IntervalList

public IntervalList(IntervalList l)
Copy constructor ...

Parameters:
l - the IntervalList to copy.
Method Detail

getIntervalAt

public Interval getIntervalAt(int index)
Returns the interval at the specified index.

Parameters:
index - the index of the interval to return
Returns:
the interval at the specified index
Throws:
java.lang.IndexOutOfBoundsException - if the index is out of bound (index < 0 || index >= size()).

getSize

public int getSize()
Returns the number of intervals in the list.

Returns:
the number of intervals

union

public static IntervalList union(IntervalList list1,
                                 IntervalList list2)
Unify two list of intervals.

Parameters:
list1 - the first list
list2 - the second list
Returns:
IntervalList
See Also:
IntervalList.copy()

union

public static IntervalList union(IntervalList list,
                                 Interval i)
Compute the unification of an interval with a list. In fact, union is called with a new IntervalList containing only the interval i.

Parameters:
i - the interval to unify with the list
list - the list to be unified
Returns:
the unified list
See Also:
(IntervalList, IntervalList)

add

public void add(Interval i)
Add the interval i to the current list, unifying if necessary.

Parameters:
i - the interval to add

add

public void add(java.lang.String interval)
         throws DataParserException
Add an interval in the form of a string. We will simply create the interval from the string, then add it.

Parameters:
interval - a string representing the interval
Throws:
DataParserException - should the string be malformed
See Also:
Interval.Interval(String), add(Interval)

intersectionOf

public static IntervalList intersectionOf(IntervalList list1,
                                          IntervalList list2)
Returns the intersection of two lists. If the list do not have any intersection, then a list with a size of zero is returned.

Parameters:
list1 - the first interval list
list2 - the second interval list
Returns:
the intersection of the two lists

substract

public static IntervalList substract(IntervalList s,
                                     IntervalList l)
This methods compute the negation of the division of the two sets

Parameters:
s - the first set
l - the second set
Returns:
the original interval with the elements removed

indexOf

public int indexOf(double v)
This methods find the value v in the interval list and returns the index of the interval which contains the v value. If the value v is not found, then -1 is returned. A dichotomic search is used.

Parameters:
v - the value to seek
Returns:
the index of the interval containing v, or -1 if not found.

isIn

public boolean isIn(double v)
Returns 'True' should the value be part of an interval of the list

Parameters:
v - a real number to seek
Returns:
'True' if the value has been found, 'False' otherwise
See Also:
indexOf(double)

isIncluded

public boolean isIncluded(IntervalList smaller)
Returns true if the smaller interval is included into the list or is equal

Parameters:
smaller - the smaller interval to seek
Returns:
'True' if the interval is indeed included into the list or equal

isIncluded

public boolean isIncluded(Interval smaller)
Returns true if the interval is included or equal to the current list. This method calls the isIncluded method with a freshly created IntervalList from the smaller interval.

Parameters:
smaller - the interval to check
Returns:
boolean 'True' if the interval is included or equal to the current list
See Also:
isIncluded(IntervalList)

isEmpty

public boolean isEmpty()
Returns 'True' if the list is empty.

Returns:
'True' if the list is empty, 'False' otherwise.

toString

public java.lang.String toString()
Convert the current list a string. Should the list be empty, the method will return "empty list", else all of the intervals separated with a "U" token will be returned. This is the exact same format accepted by the constructor with a string.

Overrides:
toString in class java.lang.Object
Returns:
a legal string representing the list
See Also:
IntervalList(String)

copy

public IntervalList copy()
Returns a copy of the current list.

Returns:
a copy of the current list.
See Also:
IntervalList(IntervalList)

equals

public boolean equals(java.lang.Object o)
Returns true if the object is semantically equivalent to the current list. If the object is an interval and that the current list contains only this interval, then true will also be returned. If the object is an IntervalList, it must contain the exact same interval of the current list to be considered equivalent.

Overrides:
equals in class java.lang.Object
Parameters:
o - the object to compare
Returns:
'True' if the object is equivalent to this list