Package groovy.lang
Class ObjectRange
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<java.lang.Comparable>
groovy.lang.ObjectRange
- All Implemented Interfaces:
- Range<java.lang.Comparable>,- java.lang.Iterable<java.lang.Comparable>,- java.util.Collection<java.lang.Comparable>,- java.util.List<java.lang.Comparable>
public class ObjectRange extends java.util.AbstractList<java.lang.Comparable> implements Range<java.lang.Comparable>
- 
Field SummaryFields inherited from class java.util.AbstractListmodCount
- 
Constructor SummaryConstructors Constructor Description ObjectRange(java.lang.Comparable from, java.lang.Comparable to)Creates a newObjectRange.ObjectRange(java.lang.Comparable smaller, java.lang.Comparable larger, boolean reverse)Creates a newObjectRangeassumes smaller <= larger, else behavior is undefined.
- 
Method SummaryModifier and Type Method Description protected voidcheckBoundaryCompatibility()throws IllegalArgumentException if to and from are incompatible, meaning they e.g.protected intcompareTo(java.lang.Comparable first, java.lang.Comparable second)booleancontains(java.lang.Object value)Iterates over all values and returns true if one value matches.booleancontainsWithinBounds(java.lang.Object value)Checks whether a value is between the from and to values of a Rangeprotected java.lang.Objectdecrement(java.lang.Object value)Decrements by onebooleanequals(ObjectRange that)Compares anObjectRangeto anotherObjectRange.booleanequals(java.lang.Object that)java.lang.Comparableget(int index)java.lang.ComparablegetFrom()The lower value in the range.java.lang.ComparablegetTo()The upper value in the range.protected java.lang.Objectincrement(java.lang.Object value)Increments by onejava.lang.Stringinspect()booleanisReverse()Indicates whether this is a reverse range which iterates backwards starting from the to value and ending on the from valuejava.util.Iterator<java.lang.Comparable>iterator()intsize()java.util.List<java.lang.Comparable>step(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 item.java.util.List<java.lang.Comparable>subList(int fromIndex, int toIndex)java.lang.StringtoString()Methods inherited from class java.util.AbstractListadd, add, addAll, clear, hashCode, indexOf, lastIndexOf, listIterator, listIterator, remove, removeRange, setMethods inherited from class java.util.AbstractCollectionaddAll, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArrayMethods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.CollectionparallelStream, removeIf, stream, toArrayMethods inherited from interface java.lang.IterableforEachMethods inherited from interface java.util.Listadd, add, addAll, addAll, clear, containsAll, hashCode, indexOf, isEmpty, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, replaceAll, retainAll, set, sort, spliterator, toArray, toArray
- 
Constructor Details- 
ObjectRangepublic ObjectRange(java.lang.Comparable from, java.lang.Comparable to)- Parameters:
- from- the first value in the range.
- to- the last value in the range.
 
- 
ObjectRangepublic ObjectRange(java.lang.Comparable smaller, java.lang.Comparable larger, boolean reverse)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- 
checkBoundaryCompatibilityprotected 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).
- 
equalspublic boolean equals(java.lang.Object that)- Specified by:
- equalsin interface- java.util.Collection<java.lang.Comparable>
- Specified by:
- equalsin interface- java.util.List<java.lang.Comparable>
- Overrides:
- equalsin class- java.util.AbstractList<java.lang.Comparable>
 
- 
equalsCompares anObjectRangeto anotherObjectRange.- Parameters:
- that- the object to check equality with
- Returns:
- trueif the ranges are equal
 
- 
getFrompublic java.lang.Comparable getFrom()Description copied from interface:RangeThe lower value in the range.
- 
getTopublic java.lang.Comparable getTo()Description copied from interface:RangeThe upper value in the range.
- 
isReversepublic 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
- 
getpublic java.lang.Comparable get(int index)- Specified by:
- getin interface- java.util.List<java.lang.Comparable>
- Specified by:
- getin class- java.util.AbstractList<java.lang.Comparable>
 
- 
containsWithinBoundspublic boolean containsWithinBounds(java.lang.Object value)Checks whether a value is between the from and to values of a Range- Specified by:
- containsWithinBoundsin interface- Range<java.lang.Comparable>
- Parameters:
- value- the value of interest
- Returns:
- true if the value is within the bounds
 
- 
compareToprotected int compareTo(java.lang.Comparable first, java.lang.Comparable second)
- 
sizepublic int size()- Specified by:
- sizein interface- java.util.Collection<java.lang.Comparable>
- Specified by:
- sizein interface- java.util.List<java.lang.Comparable>
- Specified by:
- sizein class- java.util.AbstractCollection<java.lang.Comparable>
 
- 
subListpublic java.util.List<java.lang.Comparable> subList(int fromIndex, int toIndex)- Specified by:
- subListin interface- java.util.List<java.lang.Comparable>
- Overrides:
- subListin class- java.util.AbstractList<java.lang.Comparable>
 
- 
toStringpublic java.lang.String toString()- Overrides:
- toStringin class- java.util.AbstractCollection<java.lang.Comparable>
 
- 
inspectpublic java.lang.String inspect()
- 
containspublic boolean contains(java.lang.Object value)Iterates over all values and returns true if one value matches.- Specified by:
- containsin interface- java.util.Collection<java.lang.Comparable>
- Specified by:
- containsin interface- java.util.List<java.lang.Comparable>
- Overrides:
- containsin class- java.util.AbstractCollection<java.lang.Comparable>
- See Also:
- containsWithinBounds(Object)
 
- 
stepDescription copied from interface:RangeSteps through the range, calling a closure for each item.
- 
iteratorpublic java.util.Iterator<java.lang.Comparable> iterator()- Specified by:
- iteratorin interface- java.util.Collection<java.lang.Comparable>
- Specified by:
- iteratorin interface- java.lang.Iterable<java.lang.Comparable>
- Specified by:
- iteratorin interface- java.util.List<java.lang.Comparable>
- Overrides:
- iteratorin class- java.util.AbstractList<java.lang.Comparable>
 
- 
steppublic java.util.List<java.lang.Comparable> step(int step)Description copied from interface:RangeForms a list by stepping through the range by the indicated interval.
- 
incrementprotected java.lang.Object increment(java.lang.Object value)Increments by one- Parameters:
- value- the value to increment
- Returns:
- the incremented value
 
- 
decrementprotected java.lang.Object decrement(java.lang.Object value)Decrements by one- Parameters:
- value- the value to decrement
- Returns:
- the decremented value
 
 
-