An Range is an object representing a range of integer values. A
range has a start index and a count. The count must be greater than or
equal to 0. Instances of this class are immutable, but subclasses may
introduce mutability. A mutable range will return true from
isMutable().
hashCode()
Overridden because equals() is overridden.
boolean
intersectsWithRange(Range otherRange)
Returns true if and only if otherRange intersects with this range.
boolean
isAdjacentToRange(Range otherRange)
Returns true if and only if otherRange is adjacent to this range;
two ranges are adjacent if the max of one range is equal to the start of
the other.
boolean
isAfterIndex(int index)
Returns true if and only if the start index of this range is
greater than index.
protected boolean
isAfterRange(Range otherRange)
Returns true if this range is after otherRange and the two
ranges do not overlap.
boolean
isBeforeIndex(int index)
Return true if and only if the end index of this range is less than
index.
boolean
isBeforeRange(Range otherRange)
Returns true if and only if this range is before otherRange
and the two ranges do not overlap.
boolean
isMutable()
Returns true only if this instance can change after it is created.
int
overlapWithRange(Range otherRange)
Returns the number of elements that are in both this range and
otherRange.
Returns true if and only if every element in otherRange is contained
in this range. If the receiver is a zero length range, then
this method will return false. Note that containment can apply to
zero length ranges; a non-zero-length range contains any zero-length
range. Contrast with range intersection.
Returns:
true if and only if every element in otherRange is
contained in this range
Throws:
java.lang.IllegalArgumentException - if otherRange is null
Returns the number of elements that are in both this range and
otherRange. A zero-length range has no overlapping elements
with any range.
Parameters:
a - range to check overlaps with this range
Returns:
number of elements in both this range and otherRange
Throws:
java.lang.IllegalArgumentException - if otherRange is null
isAdjacentToRange
public boolean isAdjacentToRange(Range otherRange)
Returns true if and only if otherRange is adjacent to this range;
two ranges are adjacent if the max of one range is equal to the start of
the other. A zero length range is adjacent to no range.
Returns:
true if and only if otherRange is adjacent to this range
Throws:
java.lang.IllegalArgumentException - if otherRange is null
Returns true if this range is after otherRange and the two
ranges do not overlap.
Returns:
true if this range is after otherRange and the two
ranges do not overlap.
Throws:
java.lang.IllegalArgumentException - if otherRange is null
rangeFromIntersection
public RangerangeFromIntersection(Range otherRange)
Returns the intersection of this range and otherRange. If the
ranges do not intersect then Range.ZeroRange is returned.
Note that a zero length range has no intersection with a non-zero
length range.
Returns:
the intersection of this range and otherRange
Throws:
java.lang.IllegalArgumentException - if otherRange is null
Returns the union of this range and otherRange.
Returns the other range if one of them are zero length range.
Returns Range.ZeroRange if both are zero length range.Note that the
union of a non-zero length range with a zero length range is merely the
non-zero length range.
Returns:
the union of this range and otherRange if both are
non-zero range
Throws:
java.lang.IllegalArgumentException - if otherRange is null
Returns this range, with its start shifted by offset.
Returns:
this range, with its start offset by offset.
toString
public java.lang.String toString()
Returns a String representation of this Range.
Overrides:
toString in class java.lang.Object
Returns:
string representation of this range
isMutable
public boolean isMutable()
Returns true only if this instance can change after it is created.
The default implementation returns false because instances of this
class can't change; subclasses that introduce mutability should
override this method to return true.
Returns:
true if and only if the range may change
clone
public java.lang.Object clone()
Creates and returns an Range that is identical to this one.
Overrides:
clone in class java.lang.Object
Returns:
a reference to the immutable instance or
a copy of the mutable instance
equals
public boolean equals(java.lang.Object otherRange)
Returns true if and only if otherRange is an Range
with the same start and count as this range.
Overrides:
equals in class java.lang.Object
Returns:
true if and only if otherRange equals this range
hashCode
public int hashCode()
Overridden because equals() is overridden. Returns a hash code
that is based on the start and count of this range.
Overrides:
hashCode in class java.lang.Object
Returns:
a hash code based on the start index and count of this range