New structure of range classes.
This commit is contained in:
@@ -4,81 +4,67 @@ public trait Range<in T : Comparable<T>> {
|
||||
public fun contains(item : T) : Boolean
|
||||
}
|
||||
|
||||
public class IntRange(public val start : Int, public val size : Int) : Range<Int>, IntIterable {
|
||||
public class IntRange(public val start : Int, public val end : Int) : Range<Int>, IntIterable {
|
||||
public override fun iterator () : IntIterator
|
||||
|
||||
public override fun contains (elem: Int) : Boolean
|
||||
|
||||
public val end : Int
|
||||
|
||||
public class object {
|
||||
public val EMPTY: IntRange
|
||||
}
|
||||
}
|
||||
|
||||
public class LongRange(public val start : Long, public val size : Long) : Range<Long>, LongIterable {
|
||||
public class LongRange(public val start : Long, public val end : Long) : Range<Long>, LongIterable {
|
||||
public override fun iterator () : LongIterator
|
||||
|
||||
public override fun contains (elem: Long) : Boolean
|
||||
|
||||
public val end : Long
|
||||
|
||||
public class object {
|
||||
public val EMPTY: LongRange
|
||||
}
|
||||
}
|
||||
|
||||
public class ByteRange(public val start : Byte, public val size : Int) : Range<Byte>, ByteIterable {
|
||||
public class ByteRange(public val start : Byte, public val end : Byte) : Range<Byte>, ByteIterable {
|
||||
public override fun iterator () : ByteIterator
|
||||
|
||||
public override fun contains (elem: Byte) : Boolean
|
||||
|
||||
public val end : Byte
|
||||
|
||||
public class object {
|
||||
public val EMPTY: ByteRange
|
||||
}
|
||||
}
|
||||
|
||||
public class ShortRange(public val start : Short, public val size : Int) : Range<Short>, ShortIterable {
|
||||
public class ShortRange(public val start : Short, public val end : Short) : Range<Short>, ShortIterable {
|
||||
public override fun iterator () : ShortIterator
|
||||
|
||||
public override fun contains (elem: Short) : Boolean
|
||||
|
||||
public val end : Short
|
||||
|
||||
public class object {
|
||||
public val EMPTY: ShortRange
|
||||
}
|
||||
}
|
||||
|
||||
public class CharRange(public val start : Char, public val size : Int) : Range<Char>, CharIterable {
|
||||
public class CharRange(public val start : Char, public val end : Char) : Range<Char>, CharIterable {
|
||||
public override fun iterator () : CharIterator
|
||||
|
||||
public override fun contains (elem: Char) : Boolean
|
||||
|
||||
public val end : Char
|
||||
|
||||
public class object {
|
||||
public val EMPTY: CharRange
|
||||
}
|
||||
}
|
||||
|
||||
public class FloatRange(public val start : Float, public val size : Float) : Range<Float> {
|
||||
public class FloatRange(public val start : Float, public val end : Float) : Range<Float> {
|
||||
public override fun contains (elem: Float) : Boolean
|
||||
|
||||
public val end : Float
|
||||
|
||||
public class object {
|
||||
public val EMPTY: FloatRange
|
||||
}
|
||||
}
|
||||
|
||||
public class DoubleRange(public val start : Double, public val size : Double) : Range<Double> {
|
||||
public class DoubleRange(public val start : Double, public val end : Double) : Range<Double> {
|
||||
public override fun contains (elem: Double) : Boolean
|
||||
|
||||
public val end : Double
|
||||
|
||||
public class object {
|
||||
public val EMPTY: DoubleRange
|
||||
}
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
fun box(): String {
|
||||
if (IntRange(0, 0) != IntRange.EMPTY) {
|
||||
if (IntRange(1, 0) != IntRange.EMPTY) {
|
||||
return IntRange.EMPTY.toString()
|
||||
}
|
||||
if (CharRange(0.toChar(), 0) != CharRange.EMPTY) {
|
||||
if (CharRange(1.toChar(), 0.toChar()) != CharRange.EMPTY) {
|
||||
return CharRange.EMPTY.toString()
|
||||
}
|
||||
if (ByteRange(0, 0) != ByteRange.EMPTY) {
|
||||
if (ByteRange(1, 0) != ByteRange.EMPTY) {
|
||||
return ByteRange.EMPTY.toString()
|
||||
}
|
||||
if (ShortRange(0, 0) != ShortRange.EMPTY) {
|
||||
if (ShortRange(1, 0) != ShortRange.EMPTY) {
|
||||
return ShortRange.EMPTY.toString()
|
||||
}
|
||||
if (FloatRange(0.toFloat(), 0.toFloat()) != FloatRange.EMPTY) {
|
||||
if (FloatRange(1.toFloat(), 0.toFloat()) != FloatRange.EMPTY) {
|
||||
return FloatRange.EMPTY.toString()
|
||||
}
|
||||
if (LongRange(0, 0) != LongRange.EMPTY) {
|
||||
if (LongRange(1, 0) != LongRange.EMPTY) {
|
||||
return LongRange.EMPTY.toString()
|
||||
}
|
||||
if (DoubleRange(0.0, 0.0) != DoubleRange.EMPTY) {
|
||||
if (DoubleRange(1.0, 0.0) != DoubleRange.EMPTY) {
|
||||
return DoubleRange.EMPTY.toString()
|
||||
}
|
||||
return "OK"
|
||||
|
||||
@@ -5,4 +5,4 @@ fun box() : String {
|
||||
return "OK"
|
||||
}
|
||||
|
||||
val String?.indices : IntRange get() = IntRange(0, this!!.length)
|
||||
val String?.indices : IntRange get() = 0..(this!!.length - 1)
|
||||
@@ -16,7 +16,7 @@ fun box(): String {
|
||||
}
|
||||
sb.append(";")
|
||||
|
||||
for (i in IntRange(0, 1)) {
|
||||
for (i in IntRange(0, 0)) {
|
||||
ap(i)
|
||||
}
|
||||
sb.append(";")
|
||||
|
||||
Reference in New Issue
Block a user