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
public class ObjectRange extends AbstractList implements Range
-
-
Field Summary
-
Fields inherited from class java.util.AbstractList
modCount
-
-
Constructor Summary
Constructors Constructor Description ObjectRange(Comparable from, Comparable to)Creates a newObjectRange.ObjectRange(Comparable from, Comparable to, boolean reverse)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontains(Object value)iterates over all values and returns true if one value matches.booleancontainsWithinBounds(Object value)Checks whether a value is between the from and to values of a Rangeprotected Objectdecrement(Object value)Decrements by onebooleanequals(ObjectRange that)Compares anObjectRangeto anotherObjectRange.booleanequals(Object that)Objectget(int index)ComparablegetFrom()The lower value in the range.ComparablegetTo()The upper value in the range.protected Objectincrement(Object value)Increments by oneStringinspect()booleanisReverse()Indicates whether this is a reverse range which iterates backwards starting from the to value and ending on the from valueIteratoriterator()intsize()Liststep(int step)Forms a list by stepping through the range by the indicated interval.voidstep(int step, Closure closure)Steps through the range, calling a closure for each number.ListsubList(int fromIndex, int toIndex)StringtoString()-
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 Detail
-
ObjectRange
public ObjectRange(Comparable from, Comparable to)
- Parameters:
from- the first value in the range.to- the last value in the range.
-
ObjectRange
public ObjectRange(Comparable from, Comparable to, boolean reverse)
-
-
Method Detail
-
equals
public boolean equals(Object that)
- Specified by:
equalsin interfaceCollection- Specified by:
equalsin interfaceList- Overrides:
equalsin classAbstractList
-
equals
public boolean equals(ObjectRange that)
Compares anObjectRangeto anotherObjectRange.- Parameters:
that- the object to check equality with- Returns:
trueif the ranges are equal
-
getFrom
public Comparable getFrom()
The lower value in the range.
-
getTo
public Comparable 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
public Object get(int index)
- Specified by:
getin interfaceList- Specified by:
getin classAbstractList
-
iterator
public Iterator iterator()
- Specified by:
iteratorin interfaceCollection- Specified by:
iteratorin interfaceIterable- Specified by:
iteratorin interfaceList- Overrides:
iteratorin classAbstractList
-
containsWithinBounds
public boolean containsWithinBounds(Object value)
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
public List subList(int fromIndex, int toIndex)
- Specified by:
subListin interfaceList- Overrides:
subListin classAbstractList
-
toString
public String toString()
- Overrides:
toStringin classAbstractCollection
-
inspect
public String inspect()
-
contains
public boolean contains(Object value)
iterates over all values and returns true if one value matches. Also see containsWithinBounds.- Specified by:
containsin interfaceCollection- Specified by:
containsin interfaceList- Overrides:
containsin classAbstractCollection
-
step
public void step(int step, Closure closure)Steps through the range, calling a closure for each number.
-
step
public List step(int step)
Forms a list by stepping through the range by the indicated interval.
-
increment
protected Object increment(Object value)
Increments by one- Parameters:
value- the value to increment- Returns:
- the incremented value
-
-