edu.washington.cs.knowitall.commonlib
Class Range
java.lang.Object
edu.washington.cs.knowitall.commonlib.AbstractRange
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
|
Constructor Summary |
Range(int index)
|
Range(int start,
int length)
|
EMPTY
public static final Range EMPTY
Range
public Range(int start,
int length)
Range
public Range(int index)
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.