From d427fcc187c6ced105ffaa18448d12b8f65c4586 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 14 Jan 2014 22:24:54 +0400 Subject: [PATCH] Generate Kotlin sources of progressions The check in DoubleProgression "if (increment == 0.0 || increment == -0.0)" (and similar in FloatProgression) was simplified to "if (increment == 0.0)" because 0.0 == -0.0 on JVM --- .../jet/generators/runtime/common.kt | 18 +++ .../jet/generators/runtime/progressions.kt | 92 +++++++++++ .../jet/generators/runtime/ranges.kt | 16 +- runtime/kt/Progressions.kt | 148 ++++++++++++++++++ runtime/src/jet/ByteProgression.java | 87 ---------- runtime/src/jet/CharProgression.java | 87 ---------- runtime/src/jet/DoubleProgression.java | 95 ----------- runtime/src/jet/FloatProgression.java | 90 ----------- runtime/src/jet/IntProgression.java | 87 ---------- runtime/src/jet/LongProgression.java | 87 ---------- runtime/src/jet/ShortProgression.java | 87 ---------- 11 files changed, 260 insertions(+), 634 deletions(-) create mode 100644 generators/src/org/jetbrains/jet/generators/runtime/progressions.kt create mode 100644 runtime/kt/Progressions.kt delete mode 100644 runtime/src/jet/ByteProgression.java delete mode 100644 runtime/src/jet/CharProgression.java delete mode 100644 runtime/src/jet/DoubleProgression.java delete mode 100644 runtime/src/jet/FloatProgression.java delete mode 100644 runtime/src/jet/IntProgression.java delete mode 100644 runtime/src/jet/LongProgression.java delete mode 100644 runtime/src/jet/ShortProgression.java diff --git a/generators/src/org/jetbrains/jet/generators/runtime/common.kt b/generators/src/org/jetbrains/jet/generators/runtime/common.kt index a428a976b38..fc46ff52ad5 100644 --- a/generators/src/org/jetbrains/jet/generators/runtime/common.kt +++ b/generators/src/org/jetbrains/jet/generators/runtime/common.kt @@ -19,6 +19,7 @@ package org.jetbrains.jet.generators.runtime import java.io.File import kotlin.properties.Delegates import java.io.PrintWriter +import org.jetbrains.jet.generators.runtime.ProgressionKind.* enum class ProgressionKind { BYTE @@ -32,6 +33,23 @@ enum class ProgressionKind { val capitalized = name().toLowerCase().capitalize() } +fun progressionIncrementType(kind: ProgressionKind) = when (kind) { + BYTE, CHAR, SHORT -> "Int" + else -> kind.capitalized +} + +fun areEqualNumbers(kind: ProgressionKind, v: String) = when (kind) { + FLOAT, DOUBLE -> "java.lang.${kind.capitalized}.compare($v, other.$v) == 0" + else -> "$v == other.$v" +} + +fun hashLong(v: String) = "($v xor ($v ushr 32))" + +fun floatToIntBits(v: String) = "(if ($v != 0.0f) java.lang.Float.floatToIntBits($v) else 0)" + +fun doubleToLongBits(v: String) = "if ($v != 0.0) java.lang.Double.doubleToLongBits($v) else 0L" + + val OUTPUT_DIR: File by Delegates.lazy { val result = File("runtime/kt/") if (!result.exists()) { diff --git a/generators/src/org/jetbrains/jet/generators/runtime/progressions.kt b/generators/src/org/jetbrains/jet/generators/runtime/progressions.kt new file mode 100644 index 00000000000..0076f61941a --- /dev/null +++ b/generators/src/org/jetbrains/jet/generators/runtime/progressions.kt @@ -0,0 +1,92 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.generators.runtime.progressions + +import org.jetbrains.jet.generators.runtime.* +import org.jetbrains.jet.generators.runtime.ProgressionKind.* +import java.io.PrintWriter + +class GenerateProgressions(val out: PrintWriter) { + fun generate() { + generatedBy(out, javaClass.getName()) + for (kind in ProgressionKind.values()) { + val t = kind.capitalized + val progression = "${t}Progression" + + val incrementType = progressionIncrementType(kind) + + fun compare(v: String) = areEqualNumbers(kind, v) + + val zero = when (kind) { + FLOAT -> "0.0f" + DOUBLE -> "0.0" + LONG -> "0L" + else -> "0" + } + val checkNaN = + if (kind == FLOAT || kind == DOUBLE) + "if (java.lang.$t.isNaN(increment)) throw IllegalArgumentException(\"Increment must be not NaN\")\n " + else "" + val checkZero = "if (increment == $zero) throw IllegalArgumentException(\"Increment must be non-zero\")" + val constructor = checkNaN + checkZero + + val hashCode = when (kind) { + BYTE, CHAR, SHORT -> " = 31 * (31 * start.toInt() + end) + increment" + INT -> " = 31 * (31 * start + end) + increment" + LONG -> " = (31 * (31 * ${hashLong("start")} + ${hashLong("end")}) + ${hashLong("increment")}).toInt()" + FLOAT -> " = (31 * (31 * ${floatToIntBits("start")} +\n" + + " ${floatToIntBits("end")}) + \n" + + " ${floatToIntBits("increment")}).toInt()" + DOUBLE -> ": Int {\n" + + " var temp = ${doubleToLongBits("start")}\n" + + " var result = ${hashLong("temp")}\n" + + " temp = ${doubleToLongBits("end")}\n" + + " result = 31 * result + ${hashLong("temp")}\n" + + " temp = ${doubleToLongBits("increment")}\n" + + " return (31 * result + ${hashLong("temp")}).toInt()\n" + + " }" + } + + out.println( +"""public class $progression( + public override val start: $t, + public override val end: $t, + public override val increment: $incrementType +) : Progression<$t> { + { + $constructor + } + + override fun iterator(): ${t}Iterator = ${t}ProgressionIterator(start, end, increment) + + fun equals(other: Any?): Boolean = + other is $progression && ${compare("start")} && ${compare("end")} && ${compare("increment")} + + fun hashCode()$hashCode + + fun toString() = ${"if (increment > 0) \"\$start..\$end step \$increment\" else \"\$start downTo \$end step \${-increment}\""} +}""") + out.println() + } + } +} + +fun main(args: Array) { + generateRuntimeFile("Progressions.kt") { + GenerateProgressions(it).generate() + } +} diff --git a/generators/src/org/jetbrains/jet/generators/runtime/ranges.kt b/generators/src/org/jetbrains/jet/generators/runtime/ranges.kt index 3691bc1b559..d74ffd0114f 100644 --- a/generators/src/org/jetbrains/jet/generators/runtime/ranges.kt +++ b/generators/src/org/jetbrains/jet/generators/runtime/ranges.kt @@ -20,12 +20,6 @@ import org.jetbrains.jet.generators.runtime.* import org.jetbrains.jet.generators.runtime.ProgressionKind.* import java.io.PrintWriter -fun hashLong(v: String) = "($v xor ($v ushr 32))" - -fun floatToIntBits(v: String) = "(if ($v != 0.0f) java.lang.Float.floatToIntBits($v) else 0)" - -fun doubleToLongBits(v: String) = "if ($v != 0.0) java.lang.Double.doubleToLongBits($v) else 0L" - class GenerateRanges(val out: PrintWriter) { fun generate() { generatedBy(out, javaClass.getName()) @@ -33,10 +27,7 @@ class GenerateRanges(val out: PrintWriter) { val t = kind.capitalized val range = "${t}Range" - val incrementType = when (kind) { - BYTE, CHAR, SHORT -> "Int" - else -> kind.capitalized - } + val incrementType = progressionIncrementType(kind) val increment = when (kind) { FLOAT -> "1.0f" @@ -51,10 +42,7 @@ class GenerateRanges(val out: PrintWriter) { else -> "1, 0" } - fun compare(v: String) = when (kind) { - FLOAT, DOUBLE -> "java.lang.${kind.capitalized}.compare($v, other.$v) == 0" - else -> "$v == other.$v" - } + fun compare(v: String) = areEqualNumbers(kind, v) val hashCode = when (kind) { BYTE, CHAR, SHORT -> " = 31 * start.toInt() + end" diff --git a/runtime/kt/Progressions.kt b/runtime/kt/Progressions.kt new file mode 100644 index 00000000000..43b93d7d896 --- /dev/null +++ b/runtime/kt/Progressions.kt @@ -0,0 +1,148 @@ +// Generated by org.jetbrains.jet.generators.runtime.progressions.GenerateProgressions + +package jet + +public class ByteProgression( + public override val start: Byte, + public override val end: Byte, + public override val increment: Int +) : Progression { + { + if (increment == 0) throw IllegalArgumentException("Increment must be non-zero") + } + + override fun iterator(): ByteIterator = ByteProgressionIterator(start, end, increment) + + fun equals(other: Any?): Boolean = + other is ByteProgression && start == other.start && end == other.end && increment == other.increment + + fun hashCode() = 31 * (31 * start.toInt() + end) + increment + + fun toString() = if (increment > 0) "$start..$end step $increment" else "$start downTo $end step ${-increment}" +} + +public class CharProgression( + public override val start: Char, + public override val end: Char, + public override val increment: Int +) : Progression { + { + if (increment == 0) throw IllegalArgumentException("Increment must be non-zero") + } + + override fun iterator(): CharIterator = CharProgressionIterator(start, end, increment) + + fun equals(other: Any?): Boolean = + other is CharProgression && start == other.start && end == other.end && increment == other.increment + + fun hashCode() = 31 * (31 * start.toInt() + end) + increment + + fun toString() = if (increment > 0) "$start..$end step $increment" else "$start downTo $end step ${-increment}" +} + +public class ShortProgression( + public override val start: Short, + public override val end: Short, + public override val increment: Int +) : Progression { + { + if (increment == 0) throw IllegalArgumentException("Increment must be non-zero") + } + + override fun iterator(): ShortIterator = ShortProgressionIterator(start, end, increment) + + fun equals(other: Any?): Boolean = + other is ShortProgression && start == other.start && end == other.end && increment == other.increment + + fun hashCode() = 31 * (31 * start.toInt() + end) + increment + + fun toString() = if (increment > 0) "$start..$end step $increment" else "$start downTo $end step ${-increment}" +} + +public class IntProgression( + public override val start: Int, + public override val end: Int, + public override val increment: Int +) : Progression { + { + if (increment == 0) throw IllegalArgumentException("Increment must be non-zero") + } + + override fun iterator(): IntIterator = IntProgressionIterator(start, end, increment) + + fun equals(other: Any?): Boolean = + other is IntProgression && start == other.start && end == other.end && increment == other.increment + + fun hashCode() = 31 * (31 * start + end) + increment + + fun toString() = if (increment > 0) "$start..$end step $increment" else "$start downTo $end step ${-increment}" +} + +public class LongProgression( + public override val start: Long, + public override val end: Long, + public override val increment: Long +) : Progression { + { + if (increment == 0L) throw IllegalArgumentException("Increment must be non-zero") + } + + override fun iterator(): LongIterator = LongProgressionIterator(start, end, increment) + + fun equals(other: Any?): Boolean = + other is LongProgression && start == other.start && end == other.end && increment == other.increment + + fun hashCode() = (31 * (31 * (start xor (start ushr 32)) + (end xor (end ushr 32))) + (increment xor (increment ushr 32))).toInt() + + fun toString() = if (increment > 0) "$start..$end step $increment" else "$start downTo $end step ${-increment}" +} + +public class FloatProgression( + public override val start: Float, + public override val end: Float, + public override val increment: Float +) : Progression { + { + if (java.lang.Float.isNaN(increment)) throw IllegalArgumentException("Increment must be not NaN") + if (increment == 0.0f) throw IllegalArgumentException("Increment must be non-zero") + } + + override fun iterator(): FloatIterator = FloatProgressionIterator(start, end, increment) + + fun equals(other: Any?): Boolean = + other is FloatProgression && java.lang.Float.compare(start, other.start) == 0 && java.lang.Float.compare(end, other.end) == 0 && java.lang.Float.compare(increment, other.increment) == 0 + + fun hashCode() = (31 * (31 * (if (start != 0.0f) java.lang.Float.floatToIntBits(start) else 0) + + (if (end != 0.0f) java.lang.Float.floatToIntBits(end) else 0)) + + (if (increment != 0.0f) java.lang.Float.floatToIntBits(increment) else 0)).toInt() + + fun toString() = if (increment > 0) "$start..$end step $increment" else "$start downTo $end step ${-increment}" +} + +public class DoubleProgression( + public override val start: Double, + public override val end: Double, + public override val increment: Double +) : Progression { + { + if (java.lang.Double.isNaN(increment)) throw IllegalArgumentException("Increment must be not NaN") + if (increment == 0.0) throw IllegalArgumentException("Increment must be non-zero") + } + + override fun iterator(): DoubleIterator = DoubleProgressionIterator(start, end, increment) + + fun equals(other: Any?): Boolean = + other is DoubleProgression && java.lang.Double.compare(start, other.start) == 0 && java.lang.Double.compare(end, other.end) == 0 && java.lang.Double.compare(increment, other.increment) == 0 + + fun hashCode(): Int { + var temp = if (start != 0.0) java.lang.Double.doubleToLongBits(start) else 0L + var result = (temp xor (temp ushr 32)) + temp = if (end != 0.0) java.lang.Double.doubleToLongBits(end) else 0L + result = 31 * result + (temp xor (temp ushr 32)) + temp = if (increment != 0.0) java.lang.Double.doubleToLongBits(increment) else 0L + return (31 * result + (temp xor (temp ushr 32))).toInt() + } + + fun toString() = if (increment > 0) "$start..$end step $increment" else "$start downTo $end step ${-increment}" +} + diff --git a/runtime/src/jet/ByteProgression.java b/runtime/src/jet/ByteProgression.java deleted file mode 100644 index 7a1d133417a..00000000000 --- a/runtime/src/jet/ByteProgression.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2010-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jet; - -import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver; - -@AssertInvisibleInResolver -public class ByteProgression implements Progression { - private final byte start; - private final byte end; - private final int increment; - - public ByteProgression(byte start, byte end, int increment) { - if (increment == 0) { - throw new IllegalArgumentException("Increment must be non-zero: " + increment); - } - this.start = start; - this.end = end; - this.increment = increment; - } - - @Override - public Byte getStart() { - return start; - } - - @Override - public Byte getEnd() { - return end; - } - - @Override - public Integer getIncrement() { - return increment; - } - - @Override - public ByteIterator iterator() { - return new ByteProgressionIterator(start, end, increment); - } - - @Override - public String toString() { - if (increment > 0) { - return start + ".." + end + " step " + increment; - } - else { - return start + " downTo " + end + " step " + -increment; - } - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - ByteProgression bytes = (ByteProgression) o; - - if (end != bytes.end) return false; - if (increment != bytes.increment) return false; - if (start != bytes.start) return false; - - return true; - } - - @Override - public int hashCode() { - int result = (int) start; - result = 31 * result + (int) end; - result = 31 * result + increment; - return result; - } -} diff --git a/runtime/src/jet/CharProgression.java b/runtime/src/jet/CharProgression.java deleted file mode 100644 index 21f13ad1f86..00000000000 --- a/runtime/src/jet/CharProgression.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2010-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jet; - -import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver; - -@AssertInvisibleInResolver -public class CharProgression implements Progression { - private final char start; - private final char end; - private final int increment; - - public CharProgression(char start, char end, int increment) { - if (increment == 0) { - throw new IllegalArgumentException("Increment must be non-zero: " + increment); - } - this.start = start; - this.end = end; - this.increment = increment; - } - - @Override - public Character getStart() { - return start; - } - - @Override - public Character getEnd() { - return end; - } - - @Override - public Integer getIncrement() { - return increment; - } - - @Override - public CharIterator iterator() { - return new CharProgressionIterator(start, end, increment); - } - - @Override - public String toString() { - if (increment > 0) { - return start + ".." + end + " step " + increment; - } - else { - return start + " downTo " + end + " step " + -increment; - } - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - CharProgression that = (CharProgression) o; - - if (end != that.end) return false; - if (increment != that.increment) return false; - if (start != that.start) return false; - - return true; - } - - @Override - public int hashCode() { - int result = (int) start; - result = 31 * result + (int) end; - result = 31 * result + increment; - return result; - } -} diff --git a/runtime/src/jet/DoubleProgression.java b/runtime/src/jet/DoubleProgression.java deleted file mode 100644 index bd99e549ef3..00000000000 --- a/runtime/src/jet/DoubleProgression.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2010-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jet; - -import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver; - -@AssertInvisibleInResolver -public class DoubleProgression implements Progression { - private final double start; - private final double end; - private final double increment; - - public DoubleProgression(double start, double end, double increment) { - if (Double.isNaN(increment)) { - throw new IllegalArgumentException("Increment must be not NaN"); - } - if (increment == 0.0 || increment == -0.0) { - throw new IllegalArgumentException("Increment must be non-zero: " + increment); - } - this.start = start; - this.end = end; - this.increment = increment; - } - - @Override - public Double getStart() { - return start; - } - - @Override - public Double getEnd() { - return end; - } - - @Override - public Double getIncrement() { - return increment; - } - - @Override - public DoubleIterator iterator() { - return new DoubleProgressionIterator(start, end, increment); - } - - @Override - public String toString() { - if (increment > 0) { - return start + ".." + end + " step " + increment; - } - else { - return start + " downTo " + end + " step " + -increment; - } - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - DoubleProgression doubles = (DoubleProgression) o; - - if (Double.compare(doubles.end, end) != 0) return false; - if (Double.compare(doubles.increment, increment) != 0) return false; - if (Double.compare(doubles.start, start) != 0) return false; - - return true; - } - - @Override - public int hashCode() { - int result; - long temp; - temp = start != +0.0d ? Double.doubleToLongBits(start) : 0L; - result = (int) (temp ^ (temp >>> 32)); - temp = end != +0.0d ? Double.doubleToLongBits(end) : 0L; - result = 31 * result + (int) (temp ^ (temp >>> 32)); - temp = increment != +0.0d ? Double.doubleToLongBits(increment) : 0L; - result = 31 * result + (int) (temp ^ (temp >>> 32)); - return result; - } -} diff --git a/runtime/src/jet/FloatProgression.java b/runtime/src/jet/FloatProgression.java deleted file mode 100644 index 6035b7bff8c..00000000000 --- a/runtime/src/jet/FloatProgression.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2010-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jet; - -import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver; - -@AssertInvisibleInResolver -public class FloatProgression implements Progression { - private final float start; - private final float end; - private final float increment; - - public FloatProgression(float start, float end, float increment) { - if (Float.isNaN(increment)) { - throw new IllegalArgumentException("Increment must be not NaN"); - } - if (increment == 0.0f || increment == -0.0f) { - throw new IllegalArgumentException("Increment must be non-zero: " + increment); - } - this.start = start; - this.end = end; - this.increment = increment; - } - - @Override - public Float getStart() { - return start; - } - - @Override - public Float getEnd() { - return end; - } - - @Override - public Float getIncrement() { - return increment; - } - - @Override - public FloatIterator iterator() { - return new FloatProgressionIterator(start, end, increment); - } - - @Override - public String toString() { - if (increment > 0) { - return start + ".." + end + " step " + increment; - } - else { - return start + " downTo " + end + " step " + -increment; - } - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - FloatProgression floats = (FloatProgression) o; - - if (Float.compare(floats.end, end) != 0) return false; - if (Float.compare(floats.increment, increment) != 0) return false; - if (Float.compare(floats.start, start) != 0) return false; - - return true; - } - - @Override - public int hashCode() { - int result = (start != +0.0f ? Float.floatToIntBits(start) : 0); - result = 31 * result + (end != +0.0f ? Float.floatToIntBits(end) : 0); - result = 31 * result + (increment != +0.0f ? Float.floatToIntBits(increment) : 0); - return result; - } -} diff --git a/runtime/src/jet/IntProgression.java b/runtime/src/jet/IntProgression.java deleted file mode 100644 index 254c962695a..00000000000 --- a/runtime/src/jet/IntProgression.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2010-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jet; - -import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver; - -@AssertInvisibleInResolver -public class IntProgression implements Progression { - private final int start; - private final int end; - private final int increment; - - public IntProgression(int start, int end, int increment) { - if (increment == 0) { - throw new IllegalArgumentException("Increment must be non-zero: " + increment); - } - this.start = start; - this.end = end; - this.increment = increment; - } - - @Override - public Integer getStart() { - return start; - } - - @Override - public Integer getEnd() { - return end; - } - - @Override - public Integer getIncrement() { - return increment; - } - - @Override - public IntIterator iterator() { - return new IntProgressionIterator(start, end, increment); - } - - @Override - public String toString() { - if (increment > 0) { - return start + ".." + end + " step " + increment; - } - else { - return start + " downTo " + end + " step " + -increment; - } - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - IntProgression sequence = (IntProgression) o; - - if (end != sequence.end) return false; - if (increment != sequence.increment) return false; - if (start != sequence.start) return false; - - return true; - } - - @Override - public int hashCode() { - int result = start; - result = 31 * result + end; - result = 31 * result + increment; - return result; - } -} diff --git a/runtime/src/jet/LongProgression.java b/runtime/src/jet/LongProgression.java deleted file mode 100644 index 73387a87a09..00000000000 --- a/runtime/src/jet/LongProgression.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2010-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jet; - -import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver; - -@AssertInvisibleInResolver -public class LongProgression implements Progression { - private final long start; - private final long end; - private final long increment; - - public LongProgression(long start, long end, long increment) { - if (increment == 0) { - throw new IllegalArgumentException("Increment must be non-zero: " + increment); - } - this.start = start; - this.end = end; - this.increment = increment; - } - - @Override - public Long getStart() { - return start; - } - - @Override - public Long getEnd() { - return end; - } - - @Override - public Long getIncrement() { - return increment; - } - - @Override - public LongIterator iterator() { - return new LongProgressionIterator(start, end, increment); - } - - @Override - public String toString() { - if (increment > 0) { - return start + ".." + end + " step " + increment; - } - else { - return start + " downTo " + end + " step " + -increment; - } - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - LongProgression longs = (LongProgression) o; - - if (end != longs.end) return false; - if (increment != longs.increment) return false; - if (start != longs.start) return false; - - return true; - } - - @Override - public int hashCode() { - int result = (int) (start ^ (start >>> 32)); - result = 31 * result + (int) (end ^ (end >>> 32)); - result = 31 * result + (int) (increment ^ (increment >>> 32)); - return result; - } -} diff --git a/runtime/src/jet/ShortProgression.java b/runtime/src/jet/ShortProgression.java deleted file mode 100644 index 1dece308400..00000000000 --- a/runtime/src/jet/ShortProgression.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2010-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jet; - -import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver; - -@AssertInvisibleInResolver -public class ShortProgression implements Progression { - private final short start; - private final short end; - private final int increment; - - public ShortProgression(short start, short end, int increment) { - if (increment == 0) { - throw new IllegalArgumentException("Increment must be non-zero: " + increment); - } - this.start = start; - this.end = end; - this.increment = increment; - } - - @Override - public Short getStart() { - return start; - } - - @Override - public Short getEnd() { - return end; - } - - @Override - public Integer getIncrement() { - return increment; - } - - @Override - public ShortIterator iterator() { - return new ShortProgressionIterator(start, end, increment); - } - - @Override - public String toString() { - if (increment > 0) { - return start + ".." + end + " step " + increment; - } - else { - return start + " downTo " + end + " step " + -increment; - } - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - ShortProgression shorts = (ShortProgression) o; - - if (end != shorts.end) return false; - if (increment != shorts.increment) return false; - if (start != shorts.start) return false; - - return true; - } - - @Override - public int hashCode() { - int result = (int) start; - result = 31 * result + (int) end; - result = 31 * result + increment; - return result; - } -}