Package groovy.lang
Class ObjectRange
- All Implemented Interfaces:
Range<Comparable>,Iterable<Comparable>,Collection<Comparable>,List<Comparable>
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionObjectRange(Comparable from, Comparable to) Creates a newObjectRange.ObjectRange(Comparable smaller, Comparable larger, boolean reverse) Creates a newObjectRangeassumes smaller <= larger, else behavior is undefined. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidthrows IllegalArgumentException if to and from are incompatible, meaning they e.g.protected intcompareTo(Comparable first, Comparable second) booleanIterates 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 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 item.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
Creates a newObjectRangeassumes smaller <= larger, else behavior is undefined. Caution: Prefer the other constructor when in doubt.Optimized Constructor avoiding initial computation of comparison.
-
-
Method Details
-
checkBoundaryCompatibility
protected void checkBoundaryCompatibility()throws IllegalArgumentException if to and from are incompatible, meaning they e.g. (likely) produce infinite sequences. Called at construction time, subclasses may override cautiously (using only members to and from). -
equals
- Specified by:
equalsin interfaceCollection<Comparable>- Specified by:
equalsin interfaceList<Comparable>- Overrides:
equalsin classAbstractList<Comparable>
-
equals
Compares anObjectRangeto anotherObjectRange.- Parameters:
that- the object to check equality with- Returns:
trueif the ranges are equal
-
getFrom
Description copied from interface:RangeThe lower value in the range.- Specified by:
getFromin interfaceRange<Comparable>- Returns:
- the lower value in the range.
-
getTo
Description copied from interface:RangeThe upper value in the range.- Specified by:
getToin interfaceRange<Comparable>- Returns:
- the upper value in the range
-
isReverse
public boolean isReverse()Description copied from interface:RangeIndicates whether this is a reverse range which iterates backwards starting from the to value and ending on the from value- Specified by:
isReversein interfaceRange<Comparable>- Returns:
trueif this is a reverse range
-
get
- Specified by:
getin interfaceList<Comparable>- Specified by:
getin classAbstractList<Comparable>
-
containsWithinBounds
Checks whether a value is between the from and to values of a Range- Specified by:
containsWithinBoundsin interfaceRange<Comparable>- Parameters:
value- the value of interest- Returns:
- true if the value is within the bounds
-
compareTo
-
size
public int size()- Specified by:
sizein interfaceCollection<Comparable>- Specified by:
sizein interfaceList<Comparable>- Specified by:
sizein classAbstractCollection<Comparable>
-
subList
- Specified by:
subListin interfaceList<Comparable>- Overrides:
subListin classAbstractList<Comparable>
-
toString
- Overrides:
toStringin classAbstractCollection<Comparable>
-
inspect
-
contains
Iterates over all values and returns true if one value matches.- Specified by:
containsin interfaceCollection<Comparable>- Specified by:
containsin interfaceList<Comparable>- Overrides:
containsin classAbstractCollection<Comparable>- See Also:
-
step
Description copied from interface:RangeSteps through the range, calling a closure for each item.- Specified by:
stepin interfaceRange<Comparable>- Parameters:
step- the amount by which to step. If negative, steps through the range backwards.closure- theClosureto call
-
iterator
- Specified by:
iteratorin interfaceCollection<Comparable>- Specified by:
iteratorin interfaceIterable<Comparable>- Specified by:
iteratorin interfaceList<Comparable>- Overrides:
iteratorin classAbstractList<Comparable>
-
step
Description copied from interface:RangeForms a list by stepping through the range by the indicated interval.- Specified by:
stepin interfaceRange<Comparable>- Parameters:
step- the amount by which to step. If negative, steps through the range backwards.- Returns:
- the list formed 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
-