Package groovy.lang
Class ObjectRange
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList
-
- groovy.lang.ObjectRange
-
- All Implemented Interfaces:
Range,java.lang.Iterable,java.util.Collection,java.util.List
public class ObjectRange extends java.util.AbstractList implements Range
Represents an inclusive list of objects from a value to a value using comparators. This class is similar toIntRange. If you make any changes to this class, you might consider making parallel changes toIntRange.- Version:
- $Revision$
- Author:
- James Strachan
-
-
Constructor Summary
Constructors Constructor Description ObjectRange(java.lang.Comparable from, java.lang.Comparable to)Creates a newObjectRange.ObjectRange(java.lang.Comparable from, java.lang.Comparable to, boolean reverse)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontains(java.lang.Object value)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.Objectget(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.Iteratoriterator()intsize()java.util.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.java.util.ListsubList(int fromIndex, int toIndex)java.lang.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
-
-
-
-
Method Detail
-
equals
public boolean equals(java.lang.Object that)
- Specified by:
equalsin interfacejava.util.Collection- Specified by:
equalsin interfacejava.util.List- Overrides:
equalsin classjava.util.AbstractList
-
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 java.lang.Comparable getFrom()
The lower value in the range.
-
getTo
public java.lang.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 java.lang.Object get(int index)
- Specified by:
getin interfacejava.util.List- Specified by:
getin classjava.util.AbstractList
-
iterator
public java.util.Iterator iterator()
- Specified by:
iteratorin interfacejava.util.Collection- Specified by:
iteratorin interfacejava.lang.Iterable- Specified by:
iteratorin interfacejava.util.List- Overrides:
iteratorin classjava.util.AbstractList
-
containsWithinBounds
public boolean containsWithinBounds(java.lang.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 interfacejava.util.Collection- Specified by:
sizein interfacejava.util.List- Specified by:
sizein classjava.util.AbstractCollection
-
subList
public java.util.List subList(int fromIndex, int toIndex)- Specified by:
subListin interfacejava.util.List- Overrides:
subListin classjava.util.AbstractList
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.util.AbstractCollection
-
inspect
public java.lang.String inspect()
-
contains
public boolean contains(java.lang.Object value)
- Specified by:
containsin interfacejava.util.Collection- Specified by:
containsin interfacejava.util.List- Overrides:
containsin classjava.util.AbstractCollection
-
step
public void step(int step, Closure closure)Steps through the range, calling a closure for each number.
-
step
public java.util.List step(int step)
Forms a list by stepping through the range by the indicated interval.
-
increment
protected java.lang.Object increment(java.lang.Object value)
Increments by one- Parameters:
value- the value to increment- Returns:
- the incremented value
-
decrement
protected java.lang.Object decrement(java.lang.Object value)
Decrements by one- Parameters:
value- the value to decrement- Returns:
- the decremented value
-
-