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
This commit is contained in:
@@ -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()) {
|
||||
|
||||
@@ -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<String>) {
|
||||
generateRuntimeFile("Progressions.kt") {
|
||||
GenerateProgressions(it).generate()
|
||||
}
|
||||
}
|
||||
@@ -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"
|
||||
|
||||
@@ -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<Byte> {
|
||||
{
|
||||
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<Char> {
|
||||
{
|
||||
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<Short> {
|
||||
{
|
||||
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<Int> {
|
||||
{
|
||||
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<Long> {
|
||||
{
|
||||
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<Float> {
|
||||
{
|
||||
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<Double> {
|
||||
{
|
||||
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}"
|
||||
}
|
||||
|
||||
@@ -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<Byte> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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<Character> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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<Double> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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<Float> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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<Integer> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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<Long> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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<Short> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user