Constructor and Description |
---|
ObjectRange(java.lang.Comparable from,
java.lang.Comparable to)
Creates a new
ObjectRange . |
ObjectRange(java.lang.Comparable smaller,
java.lang.Comparable larger,
boolean reverse)
Creates a new
ObjectRange assumes smaller <= larger, else behavior is undefined. |
Modifier and Type | Method and Description |
---|---|
protected void |
checkBoundaryCompatibility()
throws IllegalArgumentException if to and from are incompatible, meaning they e.g.
|
protected int |
compareTo(java.lang.Comparable first,
java.lang.Comparable second) |
boolean |
contains(java.lang.Object value)
Iterates over all values and returns true if one value matches.
|
boolean |
containsWithinBounds(java.lang.Object value)
Checks whether a value is between the from and to values of a Range
|
protected java.lang.Object |
decrement(java.lang.Object value)
Decrements by one
|
boolean |
equals(java.lang.Object that) |
boolean |
equals(ObjectRange that)
Compares an
ObjectRange to another ObjectRange . |
java.lang.Comparable |
get(int index) |
java.lang.Comparable |
getFrom()
The lower value in the range.
|
java.lang.Comparable |
getTo()
The upper value in the range.
|
protected java.lang.Object |
increment(java.lang.Object value)
Increments by one
|
java.lang.String |
inspect() |
boolean |
isReverse()
Indicates whether this is a reverse range which iterates backwards
starting from the to value and ending on the from value
|
java.util.Iterator<java.lang.Comparable> |
iterator() |
int |
size() |
java.util.List<java.lang.Comparable> |
step(int step)
Forms a list by stepping through the range by the indicated interval.
|
void |
step(int step,
Closure closure)
Steps through the range, calling a closure for each item.
|
java.util.List<java.lang.Comparable> |
subList(int fromIndex,
int toIndex) |
java.lang.String |
toString() |
add, add, addAll, clear, hashCode, indexOf, lastIndexOf, listIterator, listIterator, remove, removeRange, set
addAll, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
public ObjectRange(java.lang.Comparable from, java.lang.Comparable to)
from
- the first value in the range.to
- the last value in the range.public ObjectRange(java.lang.Comparable smaller, java.lang.Comparable larger, boolean reverse)
ObjectRange
assumes smaller <= larger, else behavior is undefined.
Caution: Prefer the other constructor when in doubt.
Optimized Constructor avoiding initial computation of comparison.
protected void checkBoundaryCompatibility()
public boolean equals(java.lang.Object that)
equals
in interface java.util.Collection<java.lang.Comparable>
equals
in interface java.util.List<java.lang.Comparable>
equals
in class java.util.AbstractList<java.lang.Comparable>
public boolean equals(ObjectRange that)
ObjectRange
to another ObjectRange
.that
- the object to check equality withtrue
if the ranges are equalpublic java.lang.Comparable getFrom()
Range
public java.lang.Comparable getTo()
Range
public boolean isReverse()
Range
public java.lang.Comparable get(int index)
get
in interface java.util.List<java.lang.Comparable>
get
in class java.util.AbstractList<java.lang.Comparable>
public boolean containsWithinBounds(java.lang.Object value)
containsWithinBounds
in interface Range<java.lang.Comparable>
value
- the value of interestprotected int compareTo(java.lang.Comparable first, java.lang.Comparable second)
public int size()
size
in interface java.util.Collection<java.lang.Comparable>
size
in interface java.util.List<java.lang.Comparable>
size
in class java.util.AbstractCollection<java.lang.Comparable>
public java.util.List<java.lang.Comparable> subList(int fromIndex, int toIndex)
subList
in interface java.util.List<java.lang.Comparable>
subList
in class java.util.AbstractList<java.lang.Comparable>
public java.lang.String toString()
toString
in class java.util.AbstractCollection<java.lang.Comparable>
public java.lang.String inspect()
public boolean contains(java.lang.Object value)
contains
in interface java.util.Collection<java.lang.Comparable>
contains
in interface java.util.List<java.lang.Comparable>
contains
in class java.util.AbstractCollection<java.lang.Comparable>
containsWithinBounds(Object)
public void step(int step, Closure closure)
Range
public java.util.Iterator<java.lang.Comparable> iterator()
iterator
in interface java.lang.Iterable<java.lang.Comparable>
iterator
in interface java.util.Collection<java.lang.Comparable>
iterator
in interface java.util.List<java.lang.Comparable>
iterator
in class java.util.AbstractList<java.lang.Comparable>
public java.util.List<java.lang.Comparable> step(int step)
Range
protected java.lang.Object increment(java.lang.Object value)
value
- the value to incrementprotected java.lang.Object decrement(java.lang.Object value)
value
- the value to decrement