Moved *Range.step() functions to stdlib.

This commit is contained in:
Evgeny Gerashchenko
2013-01-23 20:05:35 +04:00
parent 9b866b2e12
commit 0ff3589bb9
13 changed files with 85 additions and 74 deletions
-14
View File
@@ -11,8 +11,6 @@ public class IntRange(public val start : Int, public val size : Int) : Range<Int
public val end : Int
public fun step(step: Int) : IntIterator
public class object {
public val EMPTY: IntRange
}
@@ -25,8 +23,6 @@ public class LongRange(public val start : Long, public val size : Long) : Range<
public val end : Long
public fun step(step: Long) : LongIterator
public class object {
public val EMPTY: LongRange
}
@@ -39,8 +35,6 @@ public class ByteRange(public val start : Byte, public val size : Int) : Range<B
public val end : Byte
public fun step(step: Int) : ByteIterator
public class object {
public val EMPTY: ByteRange
}
@@ -53,8 +47,6 @@ public class ShortRange(public val start : Short, public val size : Int) : Range
public val end : Short
public fun step(step: Int) : ShortIterator
public class object {
public val EMPTY: ShortRange
}
@@ -67,8 +59,6 @@ public class CharRange(public val start : Char, public val size : Int) : Range<C
public val end : Char
public fun step(step: Int) : CharIterator
public class object {
public val EMPTY: CharRange
}
@@ -79,8 +69,6 @@ public class FloatRange(public val start : Float, public val size : Float) : Ran
public val end : Float
public fun step(step: Float) : FloatIterator
public class object {
public val EMPTY: FloatRange
}
@@ -91,8 +79,6 @@ public class DoubleRange(public val start : Double, public val size : Double) :
public val end : Double
public fun step(step: Double) : DoubleIterator
public class object {
public val EMPTY: DoubleRange
}
@@ -320,6 +320,14 @@ public class StdlibTest extends CodegenTestCase {
blackBoxFile("uptoDownto.kt");
}
public void testKt765 () {
blackBoxFile("regressions/kt765.kt");
}
public void testKt925 () {
blackBoxFile("regressions/kt925.kt");
}
public void testKt930 () {
blackBoxFile("regressions/kt930.kt");
}
@@ -2837,11 +2837,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
blackBoxFileByFullPath("compiler/testData/codegen/box/primitiveTypes/kt757.kt");
}
@TestMetadata("kt765.kt")
public void testKt765() throws Exception {
blackBoxFileByFullPath("compiler/testData/codegen/box/primitiveTypes/kt765.kt");
}
@TestMetadata("kt821.kt")
public void testKt821() throws Exception {
blackBoxFileByFullPath("compiler/testData/codegen/box/primitiveTypes/kt821.kt");
@@ -2867,11 +2862,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
blackBoxFileByFullPath("compiler/testData/codegen/box/primitiveTypes/kt887.kt");
}
@TestMetadata("kt925.kt")
public void testKt925() throws Exception {
blackBoxFileByFullPath("compiler/testData/codegen/box/primitiveTypes/kt925.kt");
}
@TestMetadata("kt935.kt")
public void testKt935() throws Exception {
blackBoxFileByFullPath("compiler/testData/codegen/box/primitiveTypes/kt935.kt");
+77 -1
View File
@@ -23,7 +23,7 @@ public fun FloatSequence.reversed(): FloatSequence {
public fun LongSequence.reversed(): LongSequence {
return LongSequence(end, start, -increment)
}
public fun DoubleSequence.reversed(): DoubleSequence {
return DoubleSequence(end, start, -increment)
}
@@ -57,3 +57,79 @@ public fun DoubleRange.reversed(): DoubleSequence {
return DoubleSequence(end, start, -1.0)
}
public fun IntSequence.step(step: Int): IntSequence {
checkStepIsPositive(step > 0, step)
return IntSequence(start, end, if (increment > 0) step else -step)
}
public fun CharacterSequence.step(step: Int): CharacterSequence {
checkStepIsPositive(step > 0, step)
return CharacterSequence(start, end, if (increment > 0) step else -step)
}
public fun ByteSequence.step(step: Int): ByteSequence {
checkStepIsPositive(step > 0, step)
return ByteSequence(start, end, if (increment > 0) step else -step)
}
public fun ShortSequence.step(step: Int): ShortSequence {
checkStepIsPositive(step > 0, step)
return ShortSequence(start, end, if (increment > 0) step else -step)
}
public fun LongSequence.step(step: Long): LongSequence {
checkStepIsPositive(step > 0, step)
return LongSequence(start, end, if (increment > 0) step else -step)
}
public fun FloatSequence.step(step: Float): FloatSequence {
checkStepIsPositive(step > 0, step)
return FloatSequence(start, end, if (increment > 0) step else -step)
}
public fun DoubleSequence.step(step: Double): DoubleSequence {
checkStepIsPositive(step > 0, step)
return DoubleSequence(start, end, if (increment > 0) step else -step)
}
public fun IntRange.step(step: Int): IntSequence {
checkStepIsPositive(step > 0, step)
return IntSequence(start, end, step)
}
public fun CharRange.step(step: Int): CharacterSequence {
checkStepIsPositive(step > 0, step)
return CharacterSequence(start, end, step)
}
public fun ByteRange.step(step: Int): ByteSequence {
checkStepIsPositive(step > 0, step)
return ByteSequence(start, end, step)
}
public fun ShortRange.step(step: Int): ShortSequence {
checkStepIsPositive(step > 0, step)
return ShortSequence(start, end, step)
}
public fun LongRange.step(step: Long): LongSequence {
checkStepIsPositive(step > 0, step)
return LongSequence(start, end, step)
}
public fun FloatRange.step(step: Float): FloatSequence {
checkStepIsPositive(step > 0, step)
return FloatSequence(start, end, step)
}
public fun DoubleRange.step(step: Double): DoubleSequence {
checkStepIsPositive(step > 0, step)
return DoubleSequence(start, end, step)
}
private fun checkStepIsPositive(isPositive: Boolean, step: Number) {
if (!isPositive) throw IllegalArgumentException("Step must be positive, was: $step")
}
-7
View File
@@ -79,13 +79,6 @@ public final class ByteRange implements Range<Byte>, ByteIterable {
return result;
}
public ByteIterator step(int step) {
if (step < 0)
return new ByteSequenceIterator(getEnd(), getStart(), step);
else
return new ByteSequenceIterator(getStart(), getEnd(), step);
}
public byte getStart() {
return start;
}
-7
View File
@@ -79,13 +79,6 @@ public final class CharRange implements Range<Character>, CharIterable {
return result;
}
public CharIterator step(int step) {
if (step < 0)
return new CharacterSequenceIterator(getEnd(), getStart(), step);
else
return new CharacterSequenceIterator(getStart(), getEnd(), step);
}
public char getStart() {
return start;
}
-7
View File
@@ -77,13 +77,6 @@ public final class DoubleRange implements Range<Double> {
return result;
}
public DoubleIterator step(double step) {
if (step < 0)
return new DoubleSequenceIterator(getEnd(), getStart(), step);
else
return new DoubleSequenceIterator(getStart(), getEnd(), step);
}
public double getStart() {
return start;
}
-7
View File
@@ -73,13 +73,6 @@ public final class FloatRange implements Range<Float> {
return result;
}
public FloatIterator step(float step) {
if (step < 0)
return new FloatSequenceIterator(getEnd(), getStart(), step);
else
return new FloatSequenceIterator(getStart(), getEnd(), step);
}
public float getStart() {
return start;
}
-7
View File
@@ -79,13 +79,6 @@ public final class IntRange implements Range<Integer>, IntIterable {
return result;
}
public IntIterator step(int step) {
if (step < 0)
return new IntSequenceIterator(getEnd(), getStart(), step);
else
return new IntSequenceIterator(getStart(), getEnd(), step);
}
public int getStart() {
return start;
}
-7
View File
@@ -80,13 +80,6 @@ public final class LongRange implements Range<Long>, LongIterable {
return result;
}
public LongIterator step(long step) {
if (step < 0)
return new LongSequenceIterator(getEnd(), getStart(), step);
else
return new LongSequenceIterator(getStart(), getEnd(), step);
}
public long getStart() {
return start;
}
-7
View File
@@ -79,13 +79,6 @@ public final class ShortRange implements Range<Short>, ShortIterable {
return result;
}
public ShortIterator step(int step) {
if (step < 0)
return new ShortSequenceIterator(getEnd(), getStart(), step);
else
return new ShortSequenceIterator(getStart(), getEnd(), step);
}
public short getStart() {
return start;
}