|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.vaadin.shared.ui.grid.Range
public final class Range
An immutable representation of a range, marked by start and end points.
The range is treated as inclusive at the start, and exclusive at the end. I.e. the range [0..1[ has the length 1, and represents one integer: 0.
The range is considered empty if the start is the same as
the end.
| Method Summary | |
|---|---|
static Range |
between(int start,
int end)
Creates a range between two integers. |
Range |
combineWith(Range other)
Combines two ranges to create a range containing all values in both ranges, provided there are no gaps between the ranges. |
boolean |
contains(int integer)
Checks whether an integer is found within this range. |
boolean |
endsAfter(Range other)
Checks whether this range ends after the end of another range. |
boolean |
endsBefore(Range other)
Checks whether this range ends before the start of another range. |
boolean |
equals(java.lang.Object obj)
|
Range |
expand(int startDelta,
int endDelta)
Creates a range that is expanded the given amounts in both ends. |
int |
getEnd()
Returns the exclusive end point of this range. |
int |
getStart()
Returns the inclusive start point of this range. |
int |
hashCode()
|
boolean |
intersects(Range other)
Checks whether this range and another range are at least partially covering the same values. |
boolean |
isEmpty()
Checks whether the range has no elements between the start and end. |
boolean |
isSubsetOf(Range other)
Checks whether this range is a subset of another range. |
int |
length()
The number of integers contained in the range. |
Range |
offsetBy(int offset)
Get a range that is based on this one, but offset by a number. |
Range[] |
partitionWith(Range other)
Overlay this range with another one, and partition the ranges according to how they position relative to each other. |
Range |
restrictTo(Range bounds)
Limits this range to be within the bounds of the provided range. |
Range[] |
splitAt(int integer)
Split the range into two at a certain integer. |
Range[] |
splitAtFromStart(int length)
Split the range into two after a certain number of integers into the range. |
boolean |
startsAfter(Range other)
Checks whether this range starts after the end of another range. |
boolean |
startsBefore(Range other)
Checks whether this range starts before the start of another range. |
java.lang.String |
toString()
|
static Range |
withLength(int start,
int length)
Creates a range from a start point, with a given length. |
static Range |
withOnly(int integer)
Creates a range object representing a single integer. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Method Detail |
|---|
public static Range withOnly(int integer)
integer - the number to represent as a range
integer
public static Range between(int start,
int end)
throws java.lang.IllegalArgumentException
The range start is inclusive and the end is exclusive. So, a range "between" 0 and 5 represents the numbers 0, 1, 2, 3 and 4, but not 5.
start - the start of the the range, inclusiveend - the end of the range, exclusive
[start..end[
java.lang.IllegalArgumentException - if start > end
public static Range withLength(int start,
int length)
throws java.lang.IllegalArgumentException
start - the first integer to include in the rangelength - the length of the resulting range
start, with
length number of integers following
java.lang.IllegalArgumentException - if length < 0public int getStart()
public int getEnd()
public int length()
public boolean isEmpty()
true iff the range contains no elements.public boolean intersects(Range other)
other - the other range to check against
true if this and other intersectpublic boolean contains(int integer)
integer - an integer to test for presence in this range
true iff integer is in this rangepublic boolean isSubsetOf(Range other)
true iff other completely wraps this
rangepublic Range[] partitionWith(Range other)
The three partitions are returned as a three-element Range array:
other.
other.
other - the other range to act as delimiters.
public Range offsetBy(int offset)
offset - the number to offset by
offsetpublic java.lang.String toString()
toString in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic boolean startsBefore(Range other)
other - the other range to compare against
true iff this range starts before the
otherpublic boolean endsBefore(Range other)
other - the other range to compare against
true iff this range ends before the
otherpublic boolean endsAfter(Range other)
other - the other range to compare against
true iff this range ends after the
otherpublic boolean startsAfter(Range other)
other - the other range to compare against
true iff this range starts after the
otherpublic Range[] splitAt(int integer)
Example: [5..10[.splitAt(7) == [5..7[, [7..10[
integer - the integer at which to split the range into two
[start..integer[ in the
first element, and [integer..end[ in the second
element.
If integer is less than start, [empty,
this ] is returned. if integer is equal to
or greater than end, [this, empty] is returned
instead.
public Range[] splitAtFromStart(int length)
Calling this method is equivalent to calling
splitAt(getStart()+length);
Example:
[5..10[.splitAtFromStart(2) == [5..7[, [7..10[
length - the length at which to split this range into two
length-first
elements of this range, and the second range having the rest. If
length ≤ 0, the first element will be empty, and
the second element will be this range. If length
≥ length(), the first element will be this range,
and the second element will be empty.
public Range combineWith(Range other)
throws java.lang.IllegalArgumentException
other - the range to combine with this range
java.lang.IllegalArgumentException - if the two ranges aren't connected
public Range expand(int startDelta,
int endDelta)
throws java.lang.IllegalArgumentException
startDelta - the amount to expand by in the beginning of the rangeendDelta - the amount to expand by in the end of the range
java.lang.IllegalArgumentException - if the new range would have start > endpublic Range restrictTo(Range bounds)
This is basically an optimized way of calculating
without the overhead of
defining the parts that do not overlap.
partitionWith(Range)[1]
If the two ranges do not intersect, an empty range is returned. There are no guarantees about the position of that range.
bounds - the bounds that the returned range should be limited to
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||