xxl.util
Class Interval1D

java.lang.Object
  |
  +--xxl.util.Interval1D

public class Interval1D
extends java.lang.Object
implements Tree.Descriptor

Class to implement one-dimensional intervals of any ordered data type. The order of the basic data type by means of comparators. The borders of an interval may or may not belong to the interval, as desired.


Field Summary
protected  java.lang.Object[] border
           
 java.util.Comparator comparator
           
protected  boolean[] inclusive
           
 
Constructor Summary
Interval1D(Interval1D interval)
          Copy-constructor.
Interval1D(java.lang.Object point)
          Constructs a new interval by providing a single point based on a Comparable data type.
Interval1D(java.lang.Object leftBorder, boolean leftInclusive, java.lang.Object rightBorder, boolean rightInclusive)
          Constructs a new interval by providing the left and right borders based on a Comparable data type.
Interval1D(java.lang.Object leftBorder, boolean leftInclusive, java.lang.Object rightBorder, boolean rightInclusive, java.util.Comparator comparator)
          Constructs a new interval by providing the left and right borders and a comparator.
Interval1D(java.lang.Object point, java.util.Comparator comparator)
          Constructs a new interval by providing a single point and a comparator.
Interval1D(java.lang.Object leftBorder, java.lang.Object rightBorder)
          Constructs a new closed interval by providing the left and right borders based on a Comparable data type.
Interval1D(java.lang.Object leftBorder, java.lang.Object rightBorder, java.util.Comparator comparator)
          Constructs a new closed interval by providing the left and right borders and a comparator.
Interval1D(Tree.Descriptor descriptor)
           
 
Method Summary
 java.lang.Object border(boolean rightBorder)
          Returns the desired border of this interval.
 java.lang.Object clone()
          Clones this interval.
 boolean contains(Interval1D interval)
          Checks whether an interval is contained by this interval.
 int contains(java.lang.Object point)
          Checks whether a point is contained by this interval.
 boolean contains(Tree.Descriptor descriptor)
           
 boolean equals(java.lang.Object object)
          Returns true iff the given object is an interval having the same border properties and comparators.
 boolean includes(boolean rightBorder)
          Returns true if the desired border belongs to this interval.
 Interval1D intersect(Interval1D interval)
          Shrinks this interval to reflect the intersection with a given interval.
 int overlaps(Interval1D interval)
          Checks whether an interval and this interval do overlap.
 boolean overlaps(Tree.Descriptor descriptor)
           
 java.lang.String toString()
          Returns a String representation of this interval.
 Interval1D union(Interval1D interval)
          Extends this interval to contain a given interval, too.
 Tree.Descriptor union(Tree.Descriptor descriptor)
           
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

border

protected java.lang.Object[] border

inclusive

protected boolean[] inclusive

comparator

public final java.util.Comparator comparator
Constructor Detail

Interval1D

public Interval1D(java.lang.Object leftBorder,
                  boolean leftInclusive,
                  java.lang.Object rightBorder,
                  boolean rightInclusive,
                  java.util.Comparator comparator)
           throws java.lang.IllegalArgumentException
Constructs a new interval by providing the left and right borders and a comparator.
Parameters:
leftBorder - The left border of the interval.
leftinclusive - True iff the left border belongs to the interval.
rightBorder - the right border of the interval.
rightInclusive - True iff the right border belongs to the interval.
comparator - The comparator defining the order on the basic data type.
Throws:
Throws - an IllegalArgumentException in case that the interval does not contain any point.

Interval1D

public Interval1D(java.lang.Object leftBorder,
                  boolean leftInclusive,
                  java.lang.Object rightBorder,
                  boolean rightInclusive)
           throws java.lang.IllegalArgumentException
Constructs a new interval by providing the left and right borders based on a Comparable data type.
Parameters:
leftBorder - The left border of the interval.
leftinclusive - True iff the left border belongs to the interval.
rightBorder - the right border of the interval.
rightInclusive - True iff the right border belongs to the interval.
Throws:
Throws - an IllegalArgumentException in case that the interval does not contain any point.

Interval1D

public Interval1D(java.lang.Object leftBorder,
                  java.lang.Object rightBorder,
                  java.util.Comparator comparator)
           throws java.lang.IllegalArgumentException
Constructs a new closed interval by providing the left and right borders and a comparator.
Parameters:
leftBorder - The left border of the interval.
rightBorder - the right border of the interval.
comparator - The comparator defining the order on the basic data type.
Throws:
Throws - an IllegalArgumentException in case that the interval does not contain any point.

Interval1D

public Interval1D(java.lang.Object leftBorder,
                  java.lang.Object rightBorder)
           throws java.lang.IllegalArgumentException
Constructs a new closed interval by providing the left and right borders based on a Comparable data type.
Parameters:
leftBorder - The left border of the interval.
rightBorder - the right border of the interval.
Throws:
Throws - an IllegalArgumentException in case that the interval does not contain any point.

Interval1D

public Interval1D(java.lang.Object point,
                  java.util.Comparator comparator)
Constructs a new interval by providing a single point and a comparator.
Parameters:
point - The only point the interval will contain.
comparator - The comparator defining the order on the basic data type.

Interval1D

public Interval1D(java.lang.Object point)
Constructs a new interval by providing a single point based on a Comparable data type.
Parameters:
point - The only point the interval will contain.

Interval1D

public Interval1D(Interval1D interval)
Copy-constructor.
Parameters:
interval - The interval to be cloned.

Interval1D

public Interval1D(Tree.Descriptor descriptor)
Method Detail

clone

public java.lang.Object clone()
Clones this interval.
Specified by:
clone in interface Tree.Descriptor
Overrides:
clone in class java.lang.Object

toString

public java.lang.String toString()
Returns a String representation of this interval.
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object object)
Returns true iff the given object is an interval having the same border properties and comparators.
Specified by:
equals in interface Tree.Descriptor
Overrides:
equals in class java.lang.Object

border

public java.lang.Object border(boolean rightBorder)
Returns the desired border of this interval.
Parameters:
rightBorder - Returns the right border if true.

includes

public boolean includes(boolean rightBorder)
Returns true if the desired border belongs to this interval.
Parameters:
rightBorder - Examines the right border if true.

contains

public int contains(java.lang.Object point)
             throws java.lang.IllegalArgumentException
Checks whether a point is contained by this interval.
Parameters:
point - The point to be tested.
Returns:
Returns 0 if the point is contained by this interval, else returns -1 if the point is located to the right of this interval, else 1.
Throws:
java.util.IllegalArgumentException - Thrown if the point cannot be tested properly.

contains

public boolean contains(Interval1D interval)
                 throws java.lang.IllegalArgumentException
Checks whether an interval is contained by this interval.
Parameters:
interval - The interval to be tested.
Throws:
java.util.IllegalArgumentException - Thrown if the interval cannot be tested properly.

contains

public boolean contains(Tree.Descriptor descriptor)
Specified by:
contains in interface Tree.Descriptor

overlaps

public int overlaps(Interval1D interval)
             throws java.lang.IllegalArgumentException
Checks whether an interval and this interval do overlap.
Parameters:
interval - The interval to be tested.
Returns:
Returns 0 if the interval and this interval do overlap, else returns -1 if the interval is located to the right of this interval, else 1.
Throws:
java.util.IllegalArgumentException - Thrown if the interval cannot be tested properly.

overlaps

public boolean overlaps(Tree.Descriptor descriptor)
Specified by:
overlaps in interface Tree.Descriptor

union

public Interval1D union(Interval1D interval)
                 throws java.lang.IllegalArgumentException
Extends this interval to contain a given interval, too.
Parameters:
interval - The interval which defines the extension of this interval.
Returns:
Returns this interval.
Throws:
java.util.IllegalArgumentException - Thrown if the union cannot be performed properly.

union

public Tree.Descriptor union(Tree.Descriptor descriptor)
Specified by:
union in interface Tree.Descriptor

intersect

public Interval1D intersect(Interval1D interval)
                     throws java.lang.IllegalArgumentException
Shrinks this interval to reflect the intersection with a given interval.
Parameters:
interval - The interval to be intersected with.
Returns:
This interval.
Throws:
java.util.IllegalArgumentException - Thrown if the intersection cannot be performed properly.