edu.washington.cs.knowitall.commonlib
Class Range

java.lang.Object
  extended by edu.washington.cs.knowitall.commonlib.AbstractRange
      extended by edu.washington.cs.knowitall.commonlib.Range
All Implemented Interfaces:
Serializable, Comparable<Range>, Iterable<Integer>

public class Range
extends AbstractRange
implements Iterable<Integer>, Comparable<Range>, Serializable

An immutable class that represent an interval.

Author:
afader, schmmd
See Also:
Serialized Form

Field Summary
static Range EMPTY
           
 
Constructor Summary
Range(int index)
           
Range(int start, int length)
           
 
Method Summary
static int compareStarts(Range r1, Range r2)
           
 int compareTo(Range o)
           
 boolean contains(int i)
           
 boolean contains(Range range)
           
 boolean equals(Object obj)
           
 boolean equals(Range r)
           
 Range extend(int i)
          Extends a range by one unit on either end.
 Range extend(Range range)
           
static Range fromInterval(int start, int end)
          Returns a new range over the specified interval.
 int getEnd()
           
 int getLastIndex()
           
static Range getLeft(Range range1, Range range2)
           
 int getLength()
           
static Range getRight(Range range1, Range range2)
           
 int getStart()
           
static Comparator<Range> getStartComparator()
           
 int hashCode()
           
 boolean isAdjacentOrOverlaps(Range range)
           
 boolean isAdjacentTo(Range range)
           
static boolean isDisjoint(Collection<Range> ranges)
          Checks weather the given set of ranges are disjoint, i.e.
 boolean isEmpty()
           
 Iterator<Integer> iterator()
           
 Range join(Range range)
           
 int overlap(Range range)
           
 boolean overlapsWith(Range range)
           
 Range removeOverlap(Range range)
           
 Range shift(int n)
           
 int size()
           
 boolean subset(Range range)
           
 String toString()
           
 String toString(List<Object> parts)
           
 
Methods inherited from class edu.washington.cs.knowitall.commonlib.AbstractRange
isLeftOf, isRightOf, startsLeftOf, startsRightOf
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY

public static final Range EMPTY
Constructor Detail

Range

public Range(int start,
             int length)

Range

public Range(int index)
Method Detail

fromInterval

public static Range fromInterval(int start,
                                 int end)
Returns a new range over the specified interval.

Parameters:
start - The first item in the range (inclusive).
end - The end of the range (exclusive).
Returns:
a new range over the interval.

size

public int size()

shift

public Range shift(int n)

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in class AbstractRange

getStart

public int getStart()
Specified by:
getStart in class AbstractRange

getEnd

public int getEnd()
Specified by:
getEnd in class AbstractRange

getLength

public int getLength()

getLastIndex

public int getLastIndex()

contains

public boolean contains(int i)
Specified by:
contains in class AbstractRange

contains

public boolean contains(Range range)
Specified by:
contains in class AbstractRange

subset

public boolean subset(Range range)

extend

public Range extend(int i)
Extends a range by one unit on either end.

Parameters:
i - the index to extend to
Returns:

getLeft

public static Range getLeft(Range range1,
                            Range range2)

getRight

public static Range getRight(Range range1,
                             Range range2)

overlapsWith

public boolean overlapsWith(Range range)

overlap

public int overlap(Range range)

isAdjacentTo

public boolean isAdjacentTo(Range range)

isAdjacentOrOverlaps

public boolean isAdjacentOrOverlaps(Range range)

join

public Range join(Range range)

extend

public Range extend(Range range)

removeOverlap

public Range removeOverlap(Range range)

equals

public boolean equals(Range r)

toString

public String toString()
Overrides:
toString in class Object

toString

public String toString(List<Object> parts)

getStartComparator

public static Comparator<Range> getStartComparator()

compareStarts

public static int compareStarts(Range r1,
                                Range r2)

isDisjoint

public static boolean isDisjoint(Collection<Range> ranges)
Checks weather the given set of ranges are disjoint, i.e. none of the ranges overlap.

Parameters:
ranges -

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

iterator

public Iterator<Integer> iterator()
Specified by:
iterator in interface Iterable<Integer>

compareTo

public int compareTo(Range o)
Specified by:
compareTo in interface Comparable<Range>


Copyright © 2012 University of Washington CSE. All Rights Reserved.