negative steps supported
This commit is contained in:
@@ -37,7 +37,10 @@ public final class ByteRange implements Range<Byte>, ByteIterable, JetObject {
|
||||
}
|
||||
|
||||
public ByteIterator step(int step) {
|
||||
return new MyIterator(start, count, step);
|
||||
if(step < 0)
|
||||
return new MyIterator(getEnd(), -count, -step);
|
||||
else
|
||||
return new MyIterator(start, count, step);
|
||||
}
|
||||
|
||||
public ByteRange minus() {
|
||||
|
||||
@@ -41,7 +41,10 @@ public final class CharRange implements Range<Character>, CharIterable, JetObjec
|
||||
}
|
||||
|
||||
public CharIterator step(int step) {
|
||||
return new MyIterator(start, count, step);
|
||||
if(step < 0)
|
||||
return new MyIterator(getEnd(), -count, -step);
|
||||
else
|
||||
return new MyIterator(start, count, step);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,7 +21,10 @@ public final class IntRange implements Range<Integer>, IntIterable, JetObject {
|
||||
}
|
||||
|
||||
public IntIterator step(int step) {
|
||||
return new MyIterator(start, count, step);
|
||||
if(step < 0)
|
||||
return new MyIterator(getEnd(), -count, -step);
|
||||
else
|
||||
return new MyIterator(start, count, step);
|
||||
}
|
||||
|
||||
public boolean getIsReversed() {
|
||||
|
||||
@@ -12,7 +12,10 @@ public final class LongRange implements Range<Long>, LongIterable, JetObject {
|
||||
}
|
||||
|
||||
public LongIterator step(long step) {
|
||||
return new MyIterator(start, count, step);
|
||||
if(step < 0)
|
||||
return new MyIterator(getEnd(), -count, -step);
|
||||
else
|
||||
return new MyIterator(start, count, step);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,7 +12,10 @@ public final class ShortRange implements Range<Short>, ShortIterable, JetObject
|
||||
}
|
||||
|
||||
public ShortIterator step(int step) {
|
||||
return new MyIterator(start, count, step);
|
||||
if(step < 0)
|
||||
return new MyIterator(getEnd(), -count, -step);
|
||||
else
|
||||
return new MyIterator(start, count, step);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user