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
Represents an inclusive list of objects from a value to a value using
comparators.
This class is similar to
IntRange. If you make any changes to this
class, you might consider making parallel changes to IntRange.- Version:
- $Revision$
- Author:
- James Strachan
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionObjectRange(Comparable from, Comparable to) Creates a newObjectRange.ObjectRange(Comparable from, Comparable to, boolean reverse) -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleancontainsWithinBounds(Object value) Checks whether a value is between the from and to values of a Rangeprotected ObjectDecrements by onebooleanequals(ObjectRange that) Compares anObjectRangeto anotherObjectRange.booleanget(int index) getFrom()The lower value in the range.getTo()The upper value in the range.protected ObjectIncrements by oneinspect()booleanIndicates whether this is a reverse range which iterates backwards starting from the to value and ending on the from valueiterator()intsize()step(int step) Forms a list by stepping through the range by the indicated interval.voidSteps 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, setMethods inherited from class java.util.AbstractCollection
addAll, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArrayMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods 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:
equalsin interfaceCollection- Specified by:
equalsin interfaceList- Overrides:
equalsin classAbstractList
-
equals
Compares anObjectRangeto anotherObjectRange.- Parameters:
that- the object to check equality with- Returns:
trueif 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:
getin interfaceList- Specified by:
getin classAbstractList
-
iterator
- Specified by:
iteratorin interfaceCollection- Specified by:
iteratorin interfaceIterable- Specified by:
iteratorin interfaceList- Overrides:
iteratorin classAbstractList
-
containsWithinBounds
Checks whether a value is between the from and to values of a Range- Specified by:
containsWithinBoundsin interfaceRange- Parameters:
value- the value of interest- Returns:
- true if the value is within the bounds
-
size
public int size()- Specified by:
sizein interfaceCollection- Specified by:
sizein interfaceList- Specified by:
sizein classAbstractCollection
-
subList
- Specified by:
subListin interfaceList- Overrides:
subListin classAbstractList
-
toString
- Overrides:
toStringin classAbstractCollection
-
inspect
-
contains
- Specified by:
containsin interfaceCollection- Specified by:
containsin interfaceList- Overrides:
containsin 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
-