Package groovy.lang
Class ObjectRange
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList
groovy.lang.ObjectRange
- All Implemented Interfaces:
Range
,Iterable
,Collection
,List
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount
-
Constructor Summary
ConstructorDescriptionObjectRange
(Comparable from, Comparable to) Creates a newObjectRange
.ObjectRange
(Comparable from, Comparable to, boolean reverse) -
Method Summary
Modifier and TypeMethodDescriptionboolean
iterates over all values and returns true if one value matches.boolean
containsWithinBounds
(Object value) Checks whether a value is between the from and to values of a Rangeprotected Object
Decrements by oneboolean
equals
(ObjectRange that) Compares anObjectRange
to anotherObjectRange
.boolean
get
(int index) getFrom()
The lower value in the range.getTo()
The upper value in the range.protected Object
Increments by oneinspect()
boolean
Indicates whether this is a reverse range which iterates backwards starting from the to value and ending on the from valueiterator()
int
size()
step
(int step) Forms a list by stepping through the range by the indicated interval.void
Steps through the range, calling a closure for each number.subList
(int fromIndex, int toIndex) toString()
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, hashCode, indexOf, lastIndexOf, listIterator, listIterator, remove, removeRange, set
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.List
add, add, addAll, addAll, clear, containsAll, hashCode, indexOf, isEmpty, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, replaceAll, retainAll, set, sort, spliterator, toArray, toArray
-
Constructor Details
-
ObjectRange
- Parameters:
from
- the first value in the range.to
- the last value in the range.
-
ObjectRange
-
-
Method Details
-
equals
- Specified by:
equals
in interfaceCollection
- Specified by:
equals
in interfaceList
- Overrides:
equals
in classAbstractList
-
equals
Compares anObjectRange
to anotherObjectRange
.- Parameters:
that
- the object to check equality with- Returns:
true
if the ranges are equal
-
getFrom
The lower value in the range. -
getTo
The upper value in the range. -
isReverse
public boolean isReverse()Indicates whether this is a reverse range which iterates backwards starting from the to value and ending on the from value -
get
- Specified by:
get
in interfaceList
- Specified by:
get
in classAbstractList
-
iterator
- Specified by:
iterator
in interfaceCollection
- Specified by:
iterator
in interfaceIterable
- Specified by:
iterator
in interfaceList
- Overrides:
iterator
in classAbstractList
-
containsWithinBounds
Checks whether a value is between the from and to values of a Range- Specified by:
containsWithinBounds
in interfaceRange
- Parameters:
value
- the value of interest- Returns:
- true if the value is within the bounds
-
size
public int size()- Specified by:
size
in interfaceCollection
- Specified by:
size
in interfaceList
- Specified by:
size
in classAbstractCollection
-
subList
- Specified by:
subList
in interfaceList
- Overrides:
subList
in classAbstractList
-
toString
- Overrides:
toString
in classAbstractCollection
-
inspect
-
contains
iterates over all values and returns true if one value matches. Also see containsWithinBounds.- Specified by:
contains
in interfaceCollection
- Specified by:
contains
in interfaceList
- Overrides:
contains
in classAbstractCollection
-
step
Steps through the range, calling a closure for each number. -
step
Forms a list by stepping through the range by the indicated interval. -
increment
Increments by one- Parameters:
value
- the value to increment- Returns:
- the incremented value
-
decrement
Decrements by one- Parameters:
value
- the value to decrement- Returns:
- the decremented value
-