runtime: implement remaining boxing

This commit is contained in:
Svyatoslav Scherbina
2017-01-11 13:38:40 +07:00
committed by SvyatoslavScherbina
parent 7986598591
commit 92b462255c
@@ -20,6 +20,76 @@ class BooleanBox(val value: Boolean) : Comparable<Boolean> {
fun boxBoolean(value: Boolean) = BooleanBox(value)
class CharBox(val value: Char) : Comparable<Char> {
override fun equals(other: Any?): Boolean {
if (other !is CharBox) {
return false
}
return this.value == other.value
}
override fun hashCode() = value.hashCode()
override fun toString() = value.toString()
override fun compareTo(other: Char): Int = value.compareTo(other)
}
fun boxChar(value: Char) = CharBox(value)
class ByteBox(val value: Byte) : Number(), Comparable<Byte> {
override fun equals(other: Any?): Boolean {
if (other !is ByteBox) {
return false
}
return this.value == other.value
}
override fun hashCode() = value.hashCode()
override fun toString() = value.toString()
override fun compareTo(other: Byte): Int = value.compareTo(other)
override fun toByte() = value.toByte()
override fun toChar() = value.toChar()
override fun toShort() = value.toShort()
override fun toInt() = value.toInt()
override fun toLong() = value.toLong()
override fun toFloat() = value.toFloat()
override fun toDouble() = value.toDouble()
}
fun boxByte(value: Byte) = ByteBox(value)
class ShortBox(val value: Short) : Number(), Comparable<Short> {
override fun equals(other: Any?): Boolean {
if (other !is ShortBox) {
return false
}
return this.value == other.value
}
override fun hashCode() = value.hashCode()
override fun toString() = value.toString()
override fun compareTo(other: Short): Int = value.compareTo(other)
override fun toByte() = value.toByte()
override fun toChar() = value.toChar()
override fun toShort() = value.toShort()
override fun toInt() = value.toInt()
override fun toLong() = value.toLong()
override fun toFloat() = value.toFloat()
override fun toDouble() = value.toDouble()
}
fun boxShort(value: Short) = ShortBox(value)
class IntBox(val value: Int) : Number(), Comparable<Int> {
override fun equals(other: Any?): Boolean {
if (other !is IntBox) {
@@ -46,4 +116,80 @@ class IntBox(val value: Int) : Number(), Comparable<Int> {
fun boxInt(value: Int) = IntBox(value)
// TODO: support other boxes.
class LongBox(val value: Long) : Number(), Comparable<Long> {
override fun equals(other: Any?): Boolean {
if (other !is LongBox) {
return false
}
return this.value == other.value
}
override fun hashCode() = value.hashCode()
override fun toString() = value.toString()
override fun compareTo(other: Long): Int = value.compareTo(other)
override fun toByte() = value.toByte()
override fun toChar() = value.toChar()
override fun toShort() = value.toShort()
override fun toInt() = value.toInt()
override fun toLong() = value.toLong()
override fun toFloat() = value.toFloat()
override fun toDouble() = value.toDouble()
}
fun boxLong(value: Long) = LongBox(value)
class FloatBox(val value: Float) : Number(), Comparable<Float> {
override fun equals(other: Any?): Boolean {
if (other !is FloatBox) {
return false
}
return this.value == other.value
}
override fun hashCode() = value.hashCode()
override fun toString() = value.toString()
override fun compareTo(other: Float): Int = value.compareTo(other)
override fun toByte() = value.toByte()
override fun toChar() = value.toChar()
override fun toShort() = value.toShort()
override fun toInt() = value.toInt()
override fun toLong() = value.toLong()
override fun toFloat() = value.toFloat()
override fun toDouble() = value.toDouble()
}
fun boxFloat(value: Float) = FloatBox(value)
class DoubleBox(val value: Double) : Number(), Comparable<Double> {
override fun equals(other: Any?): Boolean {
if (other !is DoubleBox) {
return false
}
return this.value == other.value
}
override fun hashCode() = value.hashCode()
override fun toString() = value.toString()
override fun compareTo(other: Double): Int = value.compareTo(other)
override fun toByte() = value.toByte()
override fun toChar() = value.toChar()
override fun toShort() = value.toShort()
override fun toInt() = value.toInt()
override fun toLong() = value.toLong()
override fun toFloat() = value.toFloat()
override fun toDouble() = value.toDouble()
}
fun boxDouble(value: Double) = DoubleBox(value)