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
+3
View File
@@ -37,6 +37,9 @@ public final class ByteRange implements Range<Byte>, ByteIterable, JetObject {
} }
public ByteIterator step(int step) { public ByteIterator step(int step) {
if(step < 0)
return new MyIterator(getEnd(), -count, -step);
else
return new MyIterator(start, count, step); return new MyIterator(start, count, step);
} }
+3
View File
@@ -41,6 +41,9 @@ public final class CharRange implements Range<Character>, CharIterable, JetObjec
} }
public CharIterator step(int step) { public CharIterator step(int step) {
if(step < 0)
return new MyIterator(getEnd(), -count, -step);
else
return new MyIterator(start, count, step); return new MyIterator(start, count, step);
} }
+3
View File
@@ -21,6 +21,9 @@ public final class IntRange implements Range<Integer>, IntIterable, JetObject {
} }
public IntIterator step(int step) { public IntIterator step(int step) {
if(step < 0)
return new MyIterator(getEnd(), -count, -step);
else
return new MyIterator(start, count, step); return new MyIterator(start, count, step);
} }
+3
View File
@@ -12,6 +12,9 @@ public final class LongRange implements Range<Long>, LongIterable, JetObject {
} }
public LongIterator step(long step) { public LongIterator step(long step) {
if(step < 0)
return new MyIterator(getEnd(), -count, -step);
else
return new MyIterator(start, count, step); return new MyIterator(start, count, step);
} }
+3
View File
@@ -12,6 +12,9 @@ public final class ShortRange implements Range<Short>, ShortIterable, JetObject
} }
public ShortIterator step(int step) { public ShortIterator step(int step) {
if(step < 0)
return new MyIterator(getEnd(), -count, -step);
else
return new MyIterator(start, count, step); return new MyIterator(start, count, step);
} }