it.unipi.di.util
Class Range

java.lang.Object
  extended by it.unipi.di.util.Range
All Implemented Interfaces:
Comparable<Range>

public class Range
extends Object
implements Comparable<Range>

Defines a range [i, j], whose bounds are included.

Author:
Claudio Corsi, Paolo Ferragina

Constructor Summary
Range(int i, int j)
          Defines the range [i, j] (bounds included).
 
Method Summary
 int compareTo(Range r)
          Returns -1 if this range is before range r, +1 if it is after range r, or 0 if they are overlapping.
 boolean containsPoint(int p)
          Check if the input point is contained in this range.
 int getLowerBound()
           
 int getUpperBound()
           
 int length()
          The length of this range.
static Range parseRange(String str)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Range

public Range(int i,
             int j)
Defines the range [i, j] (bounds included). If j < i then the bounds are swapped and the range [j, i] is defined.

Parameters:
i - lower bound
j - upper bound
Method Detail

getLowerBound

public int getLowerBound()

getUpperBound

public int getUpperBound()

length

public int length()
The length of this range.

Returns:
the length of this range.

compareTo

public int compareTo(Range r)
Returns -1 if this range is before range r, +1 if it is after range r, or 0 if they are overlapping.

Specified by:
compareTo in interface Comparable<Range>

containsPoint

public boolean containsPoint(int p)
Check if the input point is contained in this range.

Parameters:
p - the point to check.
Returns:
true if the input point is contained in this range.

toString

public String toString()
Overrides:
toString in class Object

parseRange

public static Range parseRange(String str)