MCPcopy Create free account
hub / github.com/apache/groovy / ObjectRange

Class ObjectRange

src/main/java/groovy/lang/ObjectRange.java:43–591  ·  view source on GitHub ↗

Represents an inclusive list of objects from a value to a value using comparators. Note: This class is similar to IntRange. If you make any changes to this class, you might consider making parallel changes to IntRange.

Source from the content-addressed store, hash-verified

41 * class, you might consider making parallel changes to {@link IntRange}.
42 */
43public class ObjectRange extends AbstractList<Comparable> implements Range<Comparable> {
44 /**
45 * The first value in the range.
46 */
47 private final Comparable from;
48
49 /**
50 * The last value in the range.
51 */
52 private final Comparable to;
53
54 /**
55 * The cached size, or -1 if not yet computed
56 */
57 private int size = -1;
58
59 /**
60 * <code>true</code> if the range counts backwards from <code>to</code> to <code>from</code>.
61 */
62 private final boolean reverse;
63
64 /**
65 * Creates a new {@link ObjectRange}. Creates a reversed range if
66 * <code>from</code> &lt; <code>to</code>.
67 *
68 * @param from the first value in the range.
69 * @param to the last value in the range.
70 */
71 public ObjectRange(Comparable from, Comparable to) {
72 this(from, to, null);
73 }
74
75 /**
76 * Creates a new {@link ObjectRange} assumes smaller &lt;&#61; larger, else behavior is undefined.
77 * Caution: Prefer the other constructor when in doubt.
78 * <p>
79 * Optimized Constructor avoiding initial computation of comparison.
80 */
81 public ObjectRange(Comparable smaller, Comparable larger, boolean reverse) {
82 this(smaller, larger, (Boolean) reverse);
83 }
84
85 /**
86 * Constructs a Range, computing reverse if not provided. When providing reverse,
87 * 'smaller' must not be larger than 'larger'.
88 *
89 * @param smaller start of the range, must no be larger than to when reverse != null
90 * @param larger end of the range, must be larger than from when reverse != null
91 * @param reverse direction of the range. If null, causes direction to be computed (can be expensive).
92 */
93 private ObjectRange(Comparable smaller, Comparable larger, Boolean reverse) {
94 if (smaller == null) {
95 throw new IllegalArgumentException("Must specify a non-null value for the 'from' index in a Range");
96 }
97 if (larger == null) {
98 throw new IllegalArgumentException("Must specify a non-null value for the 'to' index in a Range");
99 }
100 if (reverse == null) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected