Move toString() from primitive ranges to Range

The same can't be done with progressions, because its toString() checks if an
increment is greater than zero, but Progression.increment is of type Number,
which is not Comparable<Int>
This commit is contained in:
Alexander Udalov
2014-01-15 18:19:36 +04:00
parent d88f76f438
commit ca565b9c19
4 changed files with 2 additions and 20 deletions
@@ -71,8 +71,6 @@ class GenerateRanges(val out: PrintWriter) {
fun hashCode()$hashCode
fun toString() = "${"\$start..\$end"}"
class object {
public val EMPTY: $range = $range($emptyBounds)
}
-4
View File
@@ -7,10 +7,6 @@ public data class ComparableRange<T: Comparable<T>> (
public override fun contains(item: T): Boolean {
return start <= item && item <= end
}
public fun toString(): String {
return "$start..$end"
}
}
public fun <T: Comparable<T>> T.rangeTo(that: T): ComparableRange<T> {
+2
View File
@@ -22,4 +22,6 @@ public trait Range<in T : Comparable<T>> {
public val end: T
public fun contains(item: T): Boolean
public fun toString(): String = "$start..$end"
}
-14
View File
@@ -15,8 +15,6 @@ public class ByteRange(public override val start: Byte, public override val end:
fun hashCode() = 31 * start.toInt() + end
fun toString() = "$start..$end"
class object {
public val EMPTY: ByteRange = ByteRange(1, 0)
}
@@ -35,8 +33,6 @@ public class CharRange(public override val start: Char, public override val end:
fun hashCode() = 31 * start.toInt() + end
fun toString() = "$start..$end"
class object {
public val EMPTY: CharRange = CharRange(1.toChar(), 0.toChar())
}
@@ -55,8 +51,6 @@ public class ShortRange(public override val start: Short, public override val en
fun hashCode() = 31 * start.toInt() + end
fun toString() = "$start..$end"
class object {
public val EMPTY: ShortRange = ShortRange(1, 0)
}
@@ -75,8 +69,6 @@ public class IntRange(public override val start: Int, public override val end: I
fun hashCode() = 31 * start + end
fun toString() = "$start..$end"
class object {
public val EMPTY: IntRange = IntRange(1, 0)
}
@@ -95,8 +87,6 @@ public class LongRange(public override val start: Long, public override val end:
fun hashCode() = (31 * (start xor (start ushr 32)) + (end xor (end ushr 32))).toInt()
fun toString() = "$start..$end"
class object {
public val EMPTY: LongRange = LongRange(1, 0)
}
@@ -115,8 +105,6 @@ public class FloatRange(public override val start: Float, public override val en
fun hashCode() = 31 * java.lang.Float.floatToIntBits(start) + java.lang.Float.floatToIntBits(end)
fun toString() = "$start..$end"
class object {
public val EMPTY: FloatRange = FloatRange(1.0f, 0.0f)
}
@@ -140,8 +128,6 @@ public class DoubleRange(public override val start: Double, public override val
return (31 * result + (temp xor (temp ushr 32))).toInt()
}
fun toString() = "$start..$end"
class object {
public val EMPTY: DoubleRange = DoubleRange(1.0, 0.0)
}