|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.sf.sido.array.Range
public final class Range
The Range class defines a range between two integers. It can also
be a singleton (single-value range) or empty (nil). A Range
is immutable.
| Field Summary | |
|---|---|
static Range |
NIL
Empty range |
static Pattern |
REGEX
Regular expression pattern used to parse a Range from
a String. |
| Constructor Summary | |
|---|---|
Range(int value)
Singleton constructor |
|
Range(int from,
int to)
Constructor using two boundaries. |
|
| Method Summary | ||
|---|---|---|
boolean |
contains(int index)
Tests if this range contains a given value |
|
boolean |
equals(Object obj)
Compares two ranges. |
|
Range |
expand(int target)
Returns a range that has been expanded to include the given target. |
|
static Range |
from(Collection<?> collection)
Creates a range from the boundaries of a collection. |
|
static Range |
from(int offset,
Collection<?> collection)
Creates a range from the boundaries of a collection, and offsets it. |
|
int |
getFrom()
Returns the minimum boundary. |
|
int |
getTo()
Returns the maximum boundary. |
|
int |
hashCode()
The hash code is computed from the boundaries |
|
static int[] |
indexes(Collection<?> collection)
Gets a range from a collection and returns the corresponding indexes. |
|
static int[] |
indexes(int offset,
Collection<?> collection)
Gets a range from a collection, offsets it and returns the corresponding indexes. |
|
boolean |
isNil()
Checks if this range is nil or not. |
|
boolean |
isSingleton()
Checks if this range is a singleton. |
|
static Range |
nil()
Returns the nil range |
|
Range |
offset(int offset)
Creates a new range that is offset from this range. |
|
int |
size()
Returns the size of this range. |
|
Array<Integer> |
toArray()
Converts this range into an Array of Integer that contains all the indexes defined by this range. |
|
static Array<Integer> |
toArray(int from,
int to)
Utility method that creates an Array from a range. |
|
static
|
toArray(int from,
int to,
com.google.common.base.Function<Integer,T> creator)
Utility method that creates an Array from a range. |
|
static
|
toIndexedArray(int from,
int to,
com.google.common.base.Function<Integer,T> creator,
com.google.common.base.Function<T,K> indexer)
|
|
int[] |
toIndexes()
Returns the list of integers included in this range. |
|
static
|
toList(int from,
int to,
com.google.common.base.Function<Integer,T> creator)
|
|
String |
toString()
Returns a representation string for this range. |
|
static Range |
valueOf(String value)
Parses a Range from a String. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final Pattern REGEX
Range from
a String.
valueOf(String)public static final Range NIL
| Constructor Detail |
|---|
public Range(int value)
public Range(int from,
int to)
from - Minimum boundaryto - Maximum boundary
IllegalArgumentException - If from is greater than to| Method Detail |
|---|
public static Range from(Collection<?> collection)
null collection will return the nil
range.
collection - Reference collection
public static Range from(int offset,
Collection<?> collection)
null collection will return the nil
range.
offset - Offset to apply to the rangecollection - Reference collection
from(java.util.Collection)public static int[] indexes(Collection<?> collection)
collection - Reference collection
from(java.util.Collection),
toIndexes()
public static int[] indexes(int offset,
Collection<?> collection)
offset - Offset to applycollection - Reference collection
from(int, java.util.Collection),
toIndexes()public static Range nil()
nil range
nil range
public static Array<Integer> toArray(int from,
int to)
Array from a range.
from - From boundaryto - To boundary
Range(int, int),
toArray()
public static <T> Array<T> toArray(int from,
int to,
com.google.common.base.Function<Integer,T> creator)
Array from a range.
from - From boundaryto - To boundarycreator - Creates the item from an integer
Range(int, int),
toArray()public static Range valueOf(String value)
Range from a String. The input
string must be formatted like:
[from{..to}]
If the input string is null, empty or equal to "[]", the
returned range is nil.
value - Input string
public boolean contains(int index)
index - Value to test
true if index is included
into this range, false otherwise.public boolean equals(Object obj)
null and if
their boundaries are equal.
equals in class Objectobj - Object to compare against
public Range expand(int target)
nil,
the returned range will be the single-value range that includes the target. If this range contains the target,
it is returned unchanged.
target - Target to expand to
public int getFrom()
nil range.
public int getTo()
nil range.
public int hashCode()
hashCode in class Objectpublic boolean isNil()
nil or not.
true if this range is nil, false otherwise.public boolean isSingleton()
nil and if the two
boundaries are equal to each other.
public Range offset(int offset)
nil range is returned unchanged.
Examples:
new Range(0,5).offset(0) ==> [0,5] new Range(0,5).offset(2) ==> [2,7] new Range(0,5).offset(-2) ==> [-2,3]
offset -
public int size()
nil range has a size of zero.
Examples:
Range.nil().size() ==> 0 new Range(1).size() ==> 1 new Range(1,2).size() ==> 2 new Range(1,10).size() ==> 10 new Range(5,15).size() ==> 11
public Array<Integer> toArray()
nil range is converted into an empty Array.
public int[] toIndexes()
Range.nil().toIndexes() ==> [] new Range(1).toIndexes() ==> [1] new Range(1,2).toIndexes() ==> [1,2] new Range(5,10).toIndexes() ==> [5,6,7,8,9,10]
public String toString()
Range.nil().toString() ==> "[]" new Range(1).toString() ==> "[1]" new Range(1,2).toString() ==> "[1..2]" new Range(5,10).toString() ==> "[5..10]"
toString in class Object
public static <T,K> IndexedArray<T,K> toIndexedArray(int from,
int to,
com.google.common.base.Function<Integer,T> creator,
com.google.common.base.Function<T,K> indexer)
public static <T> List<T> toList(int from,
int to,
com.google.common.base.Function<Integer,T> creator)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||