negative steps supported

This commit is contained in:
Alex Tkachman
2012-01-06 14:32:14 +02:00
parent 22afbed909
commit eba343dd84
5 changed files with 20 additions and 5 deletions
+4 -1
View File
@@ -37,7 +37,10 @@ public final class ByteRange implements Range<Byte>, ByteIterable, JetObject {
} }
public ByteIterator step(int step) { 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() { public ByteRange minus() {
+4 -1
View File
@@ -41,7 +41,10 @@ public final class CharRange implements Range<Character>, CharIterable, JetObjec
} }
public CharIterator step(int step) { 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 @Override
+4 -1
View File
@@ -21,7 +21,10 @@ public final class IntRange implements Range<Integer>, IntIterable, JetObject {
} }
public IntIterator step(int step) { 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() { public boolean getIsReversed() {
+4 -1
View File
@@ -12,7 +12,10 @@ public final class LongRange implements Range<Long>, LongIterable, JetObject {
} }
public LongIterator step(long step) { 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 @Override
+4 -1
View File
@@ -12,7 +12,10 @@ public final class ShortRange implements Range<Short>, ShortIterable, JetObject
} }
public ShortIterator step(int step) { 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 @Override