MCPcopy Index your code
hub / github.com/apache/groovy / subList

Method subList

src/main/java/groovy/lang/NumberRange.java:553–587  ·  view source on GitHub ↗

{@inheritDoc}

(int fromIndex, int toIndex)

Source from the content-addressed store, hash-verified

551 * {@inheritDoc}
552 */
553 @Override
554 public List<Comparable> subList(int fromIndex, int toIndex) {
555 if (fromIndex < 0) {
556 throw new IndexOutOfBoundsException("fromIndex = " + fromIndex);
557 }
558 if (fromIndex > toIndex) {
559 throw new IllegalArgumentException("fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")");
560 }
561 if (fromIndex == toIndex) {
562 return new EmptyRange<Comparable>(from);
563 }
564
565 // Performance detail:
566 // not using get(fromIndex), get(toIndex) in the following to avoid stepping over elements twice
567 final Iterator<Comparable> iter = new StepIterator(this, stepSize);
568
569 Comparable value = iter.next();
570 int i = 0;
571 for (; i < fromIndex; i++) {
572 if (!iter.hasNext()) {
573 throw new IndexOutOfBoundsException("Index: " + i + " is too big for range: " + this);
574 }
575 value = iter.next();
576 }
577 final Comparable fromValue = value;
578 for (; i < toIndex - 1; i++) {
579 if (!iter.hasNext()) {
580 throw new IndexOutOfBoundsException("Index: " + i + " is too big for range: " + this);
581 }
582 value = iter.next();
583 }
584 final Comparable toValue = value;
585
586 return new NumberRange(comparableNumber(fromValue), comparableNumber(toValue), comparableNumber(stepSize), true);
587 }
588
589 /**
590 * {@inheritDoc}

Callers

nothing calls this directly

Calls 3

nextMethod · 0.95
hasNextMethod · 0.95
comparableNumberMethod · 0.95

Tested by

no test coverage detected