diff options
Diffstat (limited to 'src/library')
29 files changed, 1009 insertions, 836 deletions
diff --git a/src/library/scala/AnyVal.scala b/src/library/scala/AnyVal.scala index 393f0899f4..d637527b30 100644 --- a/src/library/scala/AnyVal.scala +++ b/src/library/scala/AnyVal.scala @@ -26,7 +26,5 @@ package scala * The ''floating point types'' are [[scala.Float]] and [[scala.Double]]. */ abstract class AnyVal extends Any with NotNull { - // disabled for now to make the standard build go through. - // Once we have a new strap we can uncomment this and delete the AnyVal_getClass entry in Definitions. - def getClass(): Class[_ <: AnyVal] = ??? + def getClass(): Class[_ <: AnyVal] = null } diff --git a/src/library/scala/Boolean.scala b/src/library/scala/Boolean.scala index edb82b33fe..014928d986 100644 --- a/src/library/scala/Boolean.scala +++ b/src/library/scala/Boolean.scala @@ -10,6 +10,8 @@ package scala +import language.implicitConversions + /** `Boolean` (equivalent to Java's `boolean` primitive type) is a * subtype of [[scala.AnyVal]]. Instances of `Boolean` are not * represented by an object in the underlying runtime system. @@ -17,7 +19,7 @@ package scala * There is an implicit conversion from [[scala.Boolean]] => [[scala.runtime.RichBoolean]] * which provides useful non-primitive operations. */ -final class Boolean private extends AnyVal { +final abstract class Boolean private extends AnyVal { /** * Negates a Boolean expression. * @@ -26,7 +28,7 @@ final class Boolean private extends AnyVal { * * @return the negated expression */ - def unary_! : Boolean = sys.error("stub") + def unary_! : Boolean /** * Compares two Boolean expressions and returns `true` if they evaluate to the same value. @@ -35,7 +37,7 @@ final class Boolean private extends AnyVal { * - `a` and `b` are `true` or * - `a` and `b` are `false`. */ - def ==(x: Boolean): Boolean = sys.error("stub") + def ==(x: Boolean): Boolean /** * Compares two Boolean expressions and returns `true` if they evaluate to a different value. @@ -44,7 +46,7 @@ final class Boolean private extends AnyVal { * - `a` is `true` and `b` is `false` or * - `a` is `false` and `b` is `true`. */ - def !=(x: Boolean): Boolean = sys.error("stub") + def !=(x: Boolean): Boolean /** * Compares two Boolean expressions and returns `true` if one or both of them evaluate to true. @@ -58,7 +60,7 @@ final class Boolean private extends AnyVal { * behaves as if it was declared as `def ||(x: => Boolean): Boolean`. * If `a` evaluates to `true`, `true` is returned without evaluating `b`. */ - def ||(x: Boolean): Boolean = sys.error("stub") + def ||(x: Boolean): Boolean /** * Compares two Boolean expressions and returns `true` if both of them evaluate to true. @@ -70,11 +72,11 @@ final class Boolean private extends AnyVal { * behaves as if it was declared as `def &&(x: => Boolean): Boolean`. * If `a` evaluates to `false`, `false` is returned without evaluating `b`. */ - def &&(x: Boolean): Boolean = sys.error("stub") + def &&(x: Boolean): Boolean // Compiler won't build with these seemingly more accurate signatures - // def ||(x: => Boolean): Boolean = sys.error("stub") - // def &&(x: => Boolean): Boolean = sys.error("stub") + // def ||(x: => Boolean): Boolean + // def &&(x: => Boolean): Boolean /** * Compares two Boolean expressions and returns `true` if one or both of them evaluate to true. @@ -86,7 +88,7 @@ final class Boolean private extends AnyVal { * * @note This method evaluates both `a` and `b`, even if the result is already determined after evaluating `a`. */ - def |(x: Boolean): Boolean = sys.error("stub") + def |(x: Boolean): Boolean /** * Compares two Boolean expressions and returns `true` if both of them evaluate to true. @@ -96,7 +98,7 @@ final class Boolean private extends AnyVal { * * @note This method evaluates both `a` and `b`, even if the result is already determined after evaluating `a`. */ - def &(x: Boolean): Boolean = sys.error("stub") + def &(x: Boolean): Boolean /** * Compares two Boolean expressions and returns `true` if they evaluate to a different value. @@ -105,12 +107,12 @@ final class Boolean private extends AnyVal { * - `a` is `true` and `b` is `false` or * - `a` is `false` and `b` is `true`. */ - def ^(x: Boolean): Boolean = sys.error("stub") + def ^(x: Boolean): Boolean - override def getClass(): Class[Boolean] = sys.error("stub") + override def getClass(): Class[Boolean] = null } -object Boolean extends AnyValCompanion { +object Boolean extends AnyValCompanion { /** Transform a value type into a boxed reference type. * @@ -132,5 +134,6 @@ object Boolean extends AnyValCompanion { /** The String representation of the scala.Boolean companion object. */ override def toString = "object scala.Boolean" + } diff --git a/src/library/scala/Byte.scala b/src/library/scala/Byte.scala index b5b3d88e3f..6f54f6cedf 100644 --- a/src/library/scala/Byte.scala +++ b/src/library/scala/Byte.scala @@ -10,6 +10,8 @@ package scala +import language.implicitConversions + /** `Byte`, a 8-bit signed integer (equivalent to Java's `byte` primitive type) is a * subtype of [[scala.AnyVal]]. Instances of `Byte` are not * represented by an object in the underlying runtime system. @@ -17,14 +19,14 @@ package scala * There is an implicit conversion from [[scala.Byte]] => [[scala.runtime.RichByte]] * which provides useful non-primitive operations. */ -final class Byte private extends AnyVal { - def toByte: Byte = sys.error("stub") - def toShort: Short = sys.error("stub") - def toChar: Char = sys.error("stub") - def toInt: Int = sys.error("stub") - def toLong: Long = sys.error("stub") - def toFloat: Float = sys.error("stub") - def toDouble: Double = sys.error("stub") +final abstract class Byte private extends AnyVal { + def toByte: Byte + def toShort: Short + def toChar: Char + def toInt: Int + def toLong: Long + def toFloat: Float + def toDouble: Double /** * Returns the bitwise negation of this value. @@ -34,30 +36,30 @@ final class Byte private extends AnyVal { * // 11111010 * }}} */ - def unary_~ : Int = sys.error("stub") + def unary_~ : Int /** * Returns this value, unmodified. */ - def unary_+ : Int = sys.error("stub") + def unary_+ : Int /** * Returns the negation of this value. */ - def unary_- : Int = sys.error("stub") + def unary_- : Int - def +(x: String): String = sys.error("stub") + def +(x: String): String /** * Returns this value bit-shifted left by the specified number of bits, * filling in the new right bits with zeroes. * @example {{{ 6 << 3 == 48 // in binary: 0110 << 3 == 0110000 }}} */ - def <<(x: Int): Int = sys.error("stub") + def <<(x: Int): Int /** * Returns this value bit-shifted left by the specified number of bits, * filling in the new right bits with zeroes. * @example {{{ 6 << 3 == 48 // in binary: 0110 << 3 == 0110000 }}} */ - def <<(x: Long): Int = sys.error("stub") + def <<(x: Long): Int /** * Returns this value bit-shifted right by the specified number of bits, * filling the new left bits with zeroes. @@ -68,7 +70,7 @@ final class Byte private extends AnyVal { * // 00011111 11111111 11111111 11111101 * }}} */ - def >>>(x: Int): Int = sys.error("stub") + def >>>(x: Int): Int /** * Returns this value bit-shifted right by the specified number of bits, * filling the new left bits with zeroes. @@ -79,7 +81,7 @@ final class Byte private extends AnyVal { * // 00011111 11111111 11111111 11111101 * }}} */ - def >>>(x: Long): Int = sys.error("stub") + def >>>(x: Long): Int /** * Returns this value bit-shifted left by the specified number of bits, * filling in the right bits with the same value as the left-most bit of this. @@ -90,7 +92,7 @@ final class Byte private extends AnyVal { * // 11111111 11111111 11111111 11111101 * }}} */ - def >>(x: Int): Int = sys.error("stub") + def >>(x: Int): Int /** * Returns this value bit-shifted left by the specified number of bits, * filling in the right bits with the same value as the left-most bit of this. @@ -101,181 +103,181 @@ final class Byte private extends AnyVal { * // 11111111 11111111 11111111 11111101 * }}} */ - def >>(x: Long): Int = sys.error("stub") + def >>(x: Long): Int /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Byte): Boolean = sys.error("stub") + def ==(x: Byte): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Short): Boolean = sys.error("stub") + def ==(x: Short): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Char): Boolean = sys.error("stub") + def ==(x: Char): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Int): Boolean = sys.error("stub") + def ==(x: Int): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Long): Boolean = sys.error("stub") + def ==(x: Long): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Float): Boolean = sys.error("stub") + def ==(x: Float): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Double): Boolean = sys.error("stub") + def ==(x: Double): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Byte): Boolean = sys.error("stub") + def !=(x: Byte): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Short): Boolean = sys.error("stub") + def !=(x: Short): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Char): Boolean = sys.error("stub") + def !=(x: Char): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Int): Boolean = sys.error("stub") + def !=(x: Int): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Long): Boolean = sys.error("stub") + def !=(x: Long): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Float): Boolean = sys.error("stub") + def !=(x: Float): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Double): Boolean = sys.error("stub") + def !=(x: Double): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Byte): Boolean = sys.error("stub") + def <(x: Byte): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Short): Boolean = sys.error("stub") + def <(x: Short): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Char): Boolean = sys.error("stub") + def <(x: Char): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Int): Boolean = sys.error("stub") + def <(x: Int): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Long): Boolean = sys.error("stub") + def <(x: Long): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Float): Boolean = sys.error("stub") + def <(x: Float): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Double): Boolean = sys.error("stub") + def <(x: Double): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Byte): Boolean = sys.error("stub") + def <=(x: Byte): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Short): Boolean = sys.error("stub") + def <=(x: Short): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Char): Boolean = sys.error("stub") + def <=(x: Char): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Int): Boolean = sys.error("stub") + def <=(x: Int): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Long): Boolean = sys.error("stub") + def <=(x: Long): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Float): Boolean = sys.error("stub") + def <=(x: Float): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Double): Boolean = sys.error("stub") + def <=(x: Double): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Byte): Boolean = sys.error("stub") + def >(x: Byte): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Short): Boolean = sys.error("stub") + def >(x: Short): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Char): Boolean = sys.error("stub") + def >(x: Char): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Int): Boolean = sys.error("stub") + def >(x: Int): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Long): Boolean = sys.error("stub") + def >(x: Long): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Float): Boolean = sys.error("stub") + def >(x: Float): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Double): Boolean = sys.error("stub") + def >(x: Double): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Byte): Boolean = sys.error("stub") + def >=(x: Byte): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Short): Boolean = sys.error("stub") + def >=(x: Short): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Char): Boolean = sys.error("stub") + def >=(x: Char): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Int): Boolean = sys.error("stub") + def >=(x: Int): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Long): Boolean = sys.error("stub") + def >=(x: Long): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Float): Boolean = sys.error("stub") + def >=(x: Float): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Double): Boolean = sys.error("stub") + def >=(x: Double): Boolean /** * Returns the bitwise OR of this value and `x`. @@ -287,7 +289,7 @@ final class Byte private extends AnyVal { * // 11111010 * }}} */ - def |(x: Byte): Int = sys.error("stub") + def |(x: Byte): Int /** * Returns the bitwise OR of this value and `x`. * @example {{{ @@ -298,7 +300,7 @@ final class Byte private extends AnyVal { * // 11111010 * }}} */ - def |(x: Short): Int = sys.error("stub") + def |(x: Short): Int /** * Returns the bitwise OR of this value and `x`. * @example {{{ @@ -309,7 +311,7 @@ final class Byte private extends AnyVal { * // 11111010 * }}} */ - def |(x: Char): Int = sys.error("stub") + def |(x: Char): Int /** * Returns the bitwise OR of this value and `x`. * @example {{{ @@ -320,7 +322,7 @@ final class Byte private extends AnyVal { * // 11111010 * }}} */ - def |(x: Int): Int = sys.error("stub") + def |(x: Int): Int /** * Returns the bitwise OR of this value and `x`. * @example {{{ @@ -331,7 +333,7 @@ final class Byte private extends AnyVal { * // 11111010 * }}} */ - def |(x: Long): Long = sys.error("stub") + def |(x: Long): Long /** * Returns the bitwise AND of this value and `x`. @@ -343,7 +345,7 @@ final class Byte private extends AnyVal { * // 10100000 * }}} */ - def &(x: Byte): Int = sys.error("stub") + def &(x: Byte): Int /** * Returns the bitwise AND of this value and `x`. * @example {{{ @@ -354,7 +356,7 @@ final class Byte private extends AnyVal { * // 10100000 * }}} */ - def &(x: Short): Int = sys.error("stub") + def &(x: Short): Int /** * Returns the bitwise AND of this value and `x`. * @example {{{ @@ -365,7 +367,7 @@ final class Byte private extends AnyVal { * // 10100000 * }}} */ - def &(x: Char): Int = sys.error("stub") + def &(x: Char): Int /** * Returns the bitwise AND of this value and `x`. * @example {{{ @@ -376,7 +378,7 @@ final class Byte private extends AnyVal { * // 10100000 * }}} */ - def &(x: Int): Int = sys.error("stub") + def &(x: Int): Int /** * Returns the bitwise AND of this value and `x`. * @example {{{ @@ -387,7 +389,7 @@ final class Byte private extends AnyVal { * // 10100000 * }}} */ - def &(x: Long): Long = sys.error("stub") + def &(x: Long): Long /** * Returns the bitwise XOR of this value and `x`. @@ -399,7 +401,7 @@ final class Byte private extends AnyVal { * // 01011010 * }}} */ - def ^(x: Byte): Int = sys.error("stub") + def ^(x: Byte): Int /** * Returns the bitwise XOR of this value and `x`. * @example {{{ @@ -410,7 +412,7 @@ final class Byte private extends AnyVal { * // 01011010 * }}} */ - def ^(x: Short): Int = sys.error("stub") + def ^(x: Short): Int /** * Returns the bitwise XOR of this value and `x`. * @example {{{ @@ -421,7 +423,7 @@ final class Byte private extends AnyVal { * // 01011010 * }}} */ - def ^(x: Char): Int = sys.error("stub") + def ^(x: Char): Int /** * Returns the bitwise XOR of this value and `x`. * @example {{{ @@ -432,7 +434,7 @@ final class Byte private extends AnyVal { * // 01011010 * }}} */ - def ^(x: Int): Int = sys.error("stub") + def ^(x: Int): Int /** * Returns the bitwise XOR of this value and `x`. * @example {{{ @@ -443,157 +445,157 @@ final class Byte private extends AnyVal { * // 01011010 * }}} */ - def ^(x: Long): Long = sys.error("stub") + def ^(x: Long): Long /** * Returns the sum of this value and `x`. */ - def +(x: Byte): Int = sys.error("stub") + def +(x: Byte): Int /** * Returns the sum of this value and `x`. */ - def +(x: Short): Int = sys.error("stub") + def +(x: Short): Int /** * Returns the sum of this value and `x`. */ - def +(x: Char): Int = sys.error("stub") + def +(x: Char): Int /** * Returns the sum of this value and `x`. */ - def +(x: Int): Int = sys.error("stub") + def +(x: Int): Int /** * Returns the sum of this value and `x`. */ - def +(x: Long): Long = sys.error("stub") + def +(x: Long): Long /** * Returns the sum of this value and `x`. */ - def +(x: Float): Float = sys.error("stub") + def +(x: Float): Float /** * Returns the sum of this value and `x`. */ - def +(x: Double): Double = sys.error("stub") + def +(x: Double): Double /** * Returns the difference of this value and `x`. */ - def -(x: Byte): Int = sys.error("stub") + def -(x: Byte): Int /** * Returns the difference of this value and `x`. */ - def -(x: Short): Int = sys.error("stub") + def -(x: Short): Int /** * Returns the difference of this value and `x`. */ - def -(x: Char): Int = sys.error("stub") + def -(x: Char): Int /** * Returns the difference of this value and `x`. */ - def -(x: Int): Int = sys.error("stub") + def -(x: Int): Int /** * Returns the difference of this value and `x`. */ - def -(x: Long): Long = sys.error("stub") + def -(x: Long): Long /** * Returns the difference of this value and `x`. */ - def -(x: Float): Float = sys.error("stub") + def -(x: Float): Float /** * Returns the difference of this value and `x`. */ - def -(x: Double): Double = sys.error("stub") + def -(x: Double): Double /** * Returns the product of this value and `x`. */ - def *(x: Byte): Int = sys.error("stub") + def *(x: Byte): Int /** * Returns the product of this value and `x`. */ - def *(x: Short): Int = sys.error("stub") + def *(x: Short): Int /** * Returns the product of this value and `x`. */ - def *(x: Char): Int = sys.error("stub") + def *(x: Char): Int /** * Returns the product of this value and `x`. */ - def *(x: Int): Int = sys.error("stub") + def *(x: Int): Int /** * Returns the product of this value and `x`. */ - def *(x: Long): Long = sys.error("stub") + def *(x: Long): Long /** * Returns the product of this value and `x`. */ - def *(x: Float): Float = sys.error("stub") + def *(x: Float): Float /** * Returns the product of this value and `x`. */ - def *(x: Double): Double = sys.error("stub") + def *(x: Double): Double /** * Returns the quotient of this value and `x`. */ - def /(x: Byte): Int = sys.error("stub") + def /(x: Byte): Int /** * Returns the quotient of this value and `x`. */ - def /(x: Short): Int = sys.error("stub") + def /(x: Short): Int /** * Returns the quotient of this value and `x`. */ - def /(x: Char): Int = sys.error("stub") + def /(x: Char): Int /** * Returns the quotient of this value and `x`. */ - def /(x: Int): Int = sys.error("stub") + def /(x: Int): Int /** * Returns the quotient of this value and `x`. */ - def /(x: Long): Long = sys.error("stub") + def /(x: Long): Long /** * Returns the quotient of this value and `x`. */ - def /(x: Float): Float = sys.error("stub") + def /(x: Float): Float /** * Returns the quotient of this value and `x`. */ - def /(x: Double): Double = sys.error("stub") + def /(x: Double): Double /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Byte): Int = sys.error("stub") + def %(x: Byte): Int /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Short): Int = sys.error("stub") + def %(x: Short): Int /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Char): Int = sys.error("stub") + def %(x: Char): Int /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Int): Int = sys.error("stub") + def %(x: Int): Int /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Long): Long = sys.error("stub") + def %(x: Long): Long /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Float): Float = sys.error("stub") + def %(x: Float): Float /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Double): Double = sys.error("stub") + def %(x: Double): Double - override def getClass(): Class[Byte] = sys.error("stub") + override def getClass(): Class[Byte] = null } -object Byte extends AnyValCompanion { +object Byte extends AnyValCompanion { /** The smallest value representable as a Byte. */ final val MinValue = java.lang.Byte.MIN_VALUE @@ -622,6 +624,9 @@ object Byte extends AnyValCompanion { /** The String representation of the scala.Byte companion object. */ override def toString = "object scala.Byte" + + /** Language mandated coercions from Byte to "wider" types. + */ implicit def byte2short(x: Byte): Short = x.toShort implicit def byte2int(x: Byte): Int = x.toInt implicit def byte2long(x: Byte): Long = x.toLong diff --git a/src/library/scala/Char.scala b/src/library/scala/Char.scala index e0ac9a2550..b681ae1693 100644 --- a/src/library/scala/Char.scala +++ b/src/library/scala/Char.scala @@ -10,6 +10,8 @@ package scala +import language.implicitConversions + /** `Char`, a 16-bit unsigned integer (equivalent to Java's `char` primitive type) is a * subtype of [[scala.AnyVal]]. Instances of `Char` are not * represented by an object in the underlying runtime system. @@ -17,14 +19,14 @@ package scala * There is an implicit conversion from [[scala.Char]] => [[scala.runtime.RichChar]] * which provides useful non-primitive operations. */ -final class Char private extends AnyVal { - def toByte: Byte = sys.error("stub") - def toShort: Short = sys.error("stub") - def toChar: Char = sys.error("stub") - def toInt: Int = sys.error("stub") - def toLong: Long = sys.error("stub") - def toFloat: Float = sys.error("stub") - def toDouble: Double = sys.error("stub") +final abstract class Char private extends AnyVal { + def toByte: Byte + def toShort: Short + def toChar: Char + def toInt: Int + def toLong: Long + def toFloat: Float + def toDouble: Double /** * Returns the bitwise negation of this value. @@ -34,30 +36,30 @@ final class Char private extends AnyVal { * // 11111010 * }}} */ - def unary_~ : Int = sys.error("stub") + def unary_~ : Int /** * Returns this value, unmodified. */ - def unary_+ : Int = sys.error("stub") + def unary_+ : Int /** * Returns the negation of this value. */ - def unary_- : Int = sys.error("stub") + def unary_- : Int - def +(x: String): String = sys.error("stub") + def +(x: String): String /** * Returns this value bit-shifted left by the specified number of bits, * filling in the new right bits with zeroes. * @example {{{ 6 << 3 == 48 // in binary: 0110 << 3 == 0110000 }}} */ - def <<(x: Int): Int = sys.error("stub") + def <<(x: Int): Int /** * Returns this value bit-shifted left by the specified number of bits, * filling in the new right bits with zeroes. * @example {{{ 6 << 3 == 48 // in binary: 0110 << 3 == 0110000 }}} */ - def <<(x: Long): Int = sys.error("stub") + def <<(x: Long): Int /** * Returns this value bit-shifted right by the specified number of bits, * filling the new left bits with zeroes. @@ -68,7 +70,7 @@ final class Char private extends AnyVal { * // 00011111 11111111 11111111 11111101 * }}} */ - def >>>(x: Int): Int = sys.error("stub") + def >>>(x: Int): Int /** * Returns this value bit-shifted right by the specified number of bits, * filling the new left bits with zeroes. @@ -79,7 +81,7 @@ final class Char private extends AnyVal { * // 00011111 11111111 11111111 11111101 * }}} */ - def >>>(x: Long): Int = sys.error("stub") + def >>>(x: Long): Int /** * Returns this value bit-shifted left by the specified number of bits, * filling in the right bits with the same value as the left-most bit of this. @@ -90,7 +92,7 @@ final class Char private extends AnyVal { * // 11111111 11111111 11111111 11111101 * }}} */ - def >>(x: Int): Int = sys.error("stub") + def >>(x: Int): Int /** * Returns this value bit-shifted left by the specified number of bits, * filling in the right bits with the same value as the left-most bit of this. @@ -101,181 +103,181 @@ final class Char private extends AnyVal { * // 11111111 11111111 11111111 11111101 * }}} */ - def >>(x: Long): Int = sys.error("stub") + def >>(x: Long): Int /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Byte): Boolean = sys.error("stub") + def ==(x: Byte): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Short): Boolean = sys.error("stub") + def ==(x: Short): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Char): Boolean = sys.error("stub") + def ==(x: Char): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Int): Boolean = sys.error("stub") + def ==(x: Int): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Long): Boolean = sys.error("stub") + def ==(x: Long): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Float): Boolean = sys.error("stub") + def ==(x: Float): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Double): Boolean = sys.error("stub") + def ==(x: Double): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Byte): Boolean = sys.error("stub") + def !=(x: Byte): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Short): Boolean = sys.error("stub") + def !=(x: Short): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Char): Boolean = sys.error("stub") + def !=(x: Char): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Int): Boolean = sys.error("stub") + def !=(x: Int): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Long): Boolean = sys.error("stub") + def !=(x: Long): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Float): Boolean = sys.error("stub") + def !=(x: Float): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Double): Boolean = sys.error("stub") + def !=(x: Double): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Byte): Boolean = sys.error("stub") + def <(x: Byte): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Short): Boolean = sys.error("stub") + def <(x: Short): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Char): Boolean = sys.error("stub") + def <(x: Char): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Int): Boolean = sys.error("stub") + def <(x: Int): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Long): Boolean = sys.error("stub") + def <(x: Long): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Float): Boolean = sys.error("stub") + def <(x: Float): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Double): Boolean = sys.error("stub") + def <(x: Double): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Byte): Boolean = sys.error("stub") + def <=(x: Byte): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Short): Boolean = sys.error("stub") + def <=(x: Short): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Char): Boolean = sys.error("stub") + def <=(x: Char): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Int): Boolean = sys.error("stub") + def <=(x: Int): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Long): Boolean = sys.error("stub") + def <=(x: Long): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Float): Boolean = sys.error("stub") + def <=(x: Float): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Double): Boolean = sys.error("stub") + def <=(x: Double): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Byte): Boolean = sys.error("stub") + def >(x: Byte): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Short): Boolean = sys.error("stub") + def >(x: Short): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Char): Boolean = sys.error("stub") + def >(x: Char): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Int): Boolean = sys.error("stub") + def >(x: Int): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Long): Boolean = sys.error("stub") + def >(x: Long): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Float): Boolean = sys.error("stub") + def >(x: Float): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Double): Boolean = sys.error("stub") + def >(x: Double): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Byte): Boolean = sys.error("stub") + def >=(x: Byte): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Short): Boolean = sys.error("stub") + def >=(x: Short): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Char): Boolean = sys.error("stub") + def >=(x: Char): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Int): Boolean = sys.error("stub") + def >=(x: Int): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Long): Boolean = sys.error("stub") + def >=(x: Long): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Float): Boolean = sys.error("stub") + def >=(x: Float): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Double): Boolean = sys.error("stub") + def >=(x: Double): Boolean /** * Returns the bitwise OR of this value and `x`. @@ -287,7 +289,7 @@ final class Char private extends AnyVal { * // 11111010 * }}} */ - def |(x: Byte): Int = sys.error("stub") + def |(x: Byte): Int /** * Returns the bitwise OR of this value and `x`. * @example {{{ @@ -298,7 +300,7 @@ final class Char private extends AnyVal { * // 11111010 * }}} */ - def |(x: Short): Int = sys.error("stub") + def |(x: Short): Int /** * Returns the bitwise OR of this value and `x`. * @example {{{ @@ -309,7 +311,7 @@ final class Char private extends AnyVal { * // 11111010 * }}} */ - def |(x: Char): Int = sys.error("stub") + def |(x: Char): Int /** * Returns the bitwise OR of this value and `x`. * @example {{{ @@ -320,7 +322,7 @@ final class Char private extends AnyVal { * // 11111010 * }}} */ - def |(x: Int): Int = sys.error("stub") + def |(x: Int): Int /** * Returns the bitwise OR of this value and `x`. * @example {{{ @@ -331,7 +333,7 @@ final class Char private extends AnyVal { * // 11111010 * }}} */ - def |(x: Long): Long = sys.error("stub") + def |(x: Long): Long /** * Returns the bitwise AND of this value and `x`. @@ -343,7 +345,7 @@ final class Char private extends AnyVal { * // 10100000 * }}} */ - def &(x: Byte): Int = sys.error("stub") + def &(x: Byte): Int /** * Returns the bitwise AND of this value and `x`. * @example {{{ @@ -354,7 +356,7 @@ final class Char private extends AnyVal { * // 10100000 * }}} */ - def &(x: Short): Int = sys.error("stub") + def &(x: Short): Int /** * Returns the bitwise AND of this value and `x`. * @example {{{ @@ -365,7 +367,7 @@ final class Char private extends AnyVal { * // 10100000 * }}} */ - def &(x: Char): Int = sys.error("stub") + def &(x: Char): Int /** * Returns the bitwise AND of this value and `x`. * @example {{{ @@ -376,7 +378,7 @@ final class Char private extends AnyVal { * // 10100000 * }}} */ - def &(x: Int): Int = sys.error("stub") + def &(x: Int): Int /** * Returns the bitwise AND of this value and `x`. * @example {{{ @@ -387,7 +389,7 @@ final class Char private extends AnyVal { * // 10100000 * }}} */ - def &(x: Long): Long = sys.error("stub") + def &(x: Long): Long /** * Returns the bitwise XOR of this value and `x`. @@ -399,7 +401,7 @@ final class Char private extends AnyVal { * // 01011010 * }}} */ - def ^(x: Byte): Int = sys.error("stub") + def ^(x: Byte): Int /** * Returns the bitwise XOR of this value and `x`. * @example {{{ @@ -410,7 +412,7 @@ final class Char private extends AnyVal { * // 01011010 * }}} */ - def ^(x: Short): Int = sys.error("stub") + def ^(x: Short): Int /** * Returns the bitwise XOR of this value and `x`. * @example {{{ @@ -421,7 +423,7 @@ final class Char private extends AnyVal { * // 01011010 * }}} */ - def ^(x: Char): Int = sys.error("stub") + def ^(x: Char): Int /** * Returns the bitwise XOR of this value and `x`. * @example {{{ @@ -432,7 +434,7 @@ final class Char private extends AnyVal { * // 01011010 * }}} */ - def ^(x: Int): Int = sys.error("stub") + def ^(x: Int): Int /** * Returns the bitwise XOR of this value and `x`. * @example {{{ @@ -443,157 +445,157 @@ final class Char private extends AnyVal { * // 01011010 * }}} */ - def ^(x: Long): Long = sys.error("stub") + def ^(x: Long): Long /** * Returns the sum of this value and `x`. */ - def +(x: Byte): Int = sys.error("stub") + def +(x: Byte): Int /** * Returns the sum of this value and `x`. */ - def +(x: Short): Int = sys.error("stub") + def +(x: Short): Int /** * Returns the sum of this value and `x`. */ - def +(x: Char): Int = sys.error("stub") + def +(x: Char): Int /** * Returns the sum of this value and `x`. */ - def +(x: Int): Int = sys.error("stub") + def +(x: Int): Int /** * Returns the sum of this value and `x`. */ - def +(x: Long): Long = sys.error("stub") + def +(x: Long): Long /** * Returns the sum of this value and `x`. */ - def +(x: Float): Float = sys.error("stub") + def +(x: Float): Float /** * Returns the sum of this value and `x`. */ - def +(x: Double): Double = sys.error("stub") + def +(x: Double): Double /** * Returns the difference of this value and `x`. */ - def -(x: Byte): Int = sys.error("stub") + def -(x: Byte): Int /** * Returns the difference of this value and `x`. */ - def -(x: Short): Int = sys.error("stub") + def -(x: Short): Int /** * Returns the difference of this value and `x`. */ - def -(x: Char): Int = sys.error("stub") + def -(x: Char): Int /** * Returns the difference of this value and `x`. */ - def -(x: Int): Int = sys.error("stub") + def -(x: Int): Int /** * Returns the difference of this value and `x`. */ - def -(x: Long): Long = sys.error("stub") + def -(x: Long): Long /** * Returns the difference of this value and `x`. */ - def -(x: Float): Float = sys.error("stub") + def -(x: Float): Float /** * Returns the difference of this value and `x`. */ - def -(x: Double): Double = sys.error("stub") + def -(x: Double): Double /** * Returns the product of this value and `x`. */ - def *(x: Byte): Int = sys.error("stub") + def *(x: Byte): Int /** * Returns the product of this value and `x`. */ - def *(x: Short): Int = sys.error("stub") + def *(x: Short): Int /** * Returns the product of this value and `x`. */ - def *(x: Char): Int = sys.error("stub") + def *(x: Char): Int /** * Returns the product of this value and `x`. */ - def *(x: Int): Int = sys.error("stub") + def *(x: Int): Int /** * Returns the product of this value and `x`. */ - def *(x: Long): Long = sys.error("stub") + def *(x: Long): Long /** * Returns the product of this value and `x`. */ - def *(x: Float): Float = sys.error("stub") + def *(x: Float): Float /** * Returns the product of this value and `x`. */ - def *(x: Double): Double = sys.error("stub") + def *(x: Double): Double /** * Returns the quotient of this value and `x`. */ - def /(x: Byte): Int = sys.error("stub") + def /(x: Byte): Int /** * Returns the quotient of this value and `x`. */ - def /(x: Short): Int = sys.error("stub") + def /(x: Short): Int /** * Returns the quotient of this value and `x`. */ - def /(x: Char): Int = sys.error("stub") + def /(x: Char): Int /** * Returns the quotient of this value and `x`. */ - def /(x: Int): Int = sys.error("stub") + def /(x: Int): Int /** * Returns the quotient of this value and `x`. */ - def /(x: Long): Long = sys.error("stub") + def /(x: Long): Long /** * Returns the quotient of this value and `x`. */ - def /(x: Float): Float = sys.error("stub") + def /(x: Float): Float /** * Returns the quotient of this value and `x`. */ - def /(x: Double): Double = sys.error("stub") + def /(x: Double): Double /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Byte): Int = sys.error("stub") + def %(x: Byte): Int /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Short): Int = sys.error("stub") + def %(x: Short): Int /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Char): Int = sys.error("stub") + def %(x: Char): Int /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Int): Int = sys.error("stub") + def %(x: Int): Int /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Long): Long = sys.error("stub") + def %(x: Long): Long /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Float): Float = sys.error("stub") + def %(x: Float): Float /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Double): Double = sys.error("stub") + def %(x: Double): Double - override def getClass(): Class[Char] = sys.error("stub") + override def getClass(): Class[Char] = null } -object Char extends AnyValCompanion { +object Char extends AnyValCompanion { /** The smallest value representable as a Char. */ final val MinValue = java.lang.Character.MIN_VALUE @@ -622,6 +624,9 @@ object Char extends AnyValCompanion { /** The String representation of the scala.Char companion object. */ override def toString = "object scala.Char" + + /** Language mandated coercions from Char to "wider" types. + */ implicit def char2int(x: Char): Int = x.toInt implicit def char2long(x: Char): Long = x.toLong implicit def char2float(x: Char): Float = x.toFloat diff --git a/src/library/scala/Double.scala b/src/library/scala/Double.scala index bb659b963a..2ff46c433d 100644 --- a/src/library/scala/Double.scala +++ b/src/library/scala/Double.scala @@ -10,6 +10,8 @@ package scala +import language.implicitConversions + /** `Double`, a 64-bit IEEE-754 floating point number (equivalent to Java's `double` primitive type) is a * subtype of [[scala.AnyVal]]. Instances of `Double` are not * represented by an object in the underlying runtime system. @@ -17,349 +19,349 @@ package scala * There is an implicit conversion from [[scala.Double]] => [[scala.runtime.RichDouble]] * which provides useful non-primitive operations. */ -final class Double private extends AnyVal { - def toByte: Byte = sys.error("stub") - def toShort: Short = sys.error("stub") - def toChar: Char = sys.error("stub") - def toInt: Int = sys.error("stub") - def toLong: Long = sys.error("stub") - def toFloat: Float = sys.error("stub") - def toDouble: Double = sys.error("stub") +final abstract class Double private extends AnyVal { + def toByte: Byte + def toShort: Short + def toChar: Char + def toInt: Int + def toLong: Long + def toFloat: Float + def toDouble: Double /** * Returns this value, unmodified. */ - def unary_+ : Double = sys.error("stub") + def unary_+ : Double /** * Returns the negation of this value. */ - def unary_- : Double = sys.error("stub") + def unary_- : Double - def +(x: String): String = sys.error("stub") + def +(x: String): String /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Byte): Boolean = sys.error("stub") + def ==(x: Byte): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Short): Boolean = sys.error("stub") + def ==(x: Short): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Char): Boolean = sys.error("stub") + def ==(x: Char): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Int): Boolean = sys.error("stub") + def ==(x: Int): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Long): Boolean = sys.error("stub") + def ==(x: Long): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Float): Boolean = sys.error("stub") + def ==(x: Float): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Double): Boolean = sys.error("stub") + def ==(x: Double): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Byte): Boolean = sys.error("stub") + def !=(x: Byte): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Short): Boolean = sys.error("stub") + def !=(x: Short): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Char): Boolean = sys.error("stub") + def !=(x: Char): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Int): Boolean = sys.error("stub") + def !=(x: Int): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Long): Boolean = sys.error("stub") + def !=(x: Long): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Float): Boolean = sys.error("stub") + def !=(x: Float): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Double): Boolean = sys.error("stub") + def !=(x: Double): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Byte): Boolean = sys.error("stub") + def <(x: Byte): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Short): Boolean = sys.error("stub") + def <(x: Short): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Char): Boolean = sys.error("stub") + def <(x: Char): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Int): Boolean = sys.error("stub") + def <(x: Int): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Long): Boolean = sys.error("stub") + def <(x: Long): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Float): Boolean = sys.error("stub") + def <(x: Float): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Double): Boolean = sys.error("stub") + def <(x: Double): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Byte): Boolean = sys.error("stub") + def <=(x: Byte): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Short): Boolean = sys.error("stub") + def <=(x: Short): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Char): Boolean = sys.error("stub") + def <=(x: Char): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Int): Boolean = sys.error("stub") + def <=(x: Int): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Long): Boolean = sys.error("stub") + def <=(x: Long): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Float): Boolean = sys.error("stub") + def <=(x: Float): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Double): Boolean = sys.error("stub") + def <=(x: Double): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Byte): Boolean = sys.error("stub") + def >(x: Byte): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Short): Boolean = sys.error("stub") + def >(x: Short): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Char): Boolean = sys.error("stub") + def >(x: Char): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Int): Boolean = sys.error("stub") + def >(x: Int): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Long): Boolean = sys.error("stub") + def >(x: Long): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Float): Boolean = sys.error("stub") + def >(x: Float): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Double): Boolean = sys.error("stub") + def >(x: Double): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Byte): Boolean = sys.error("stub") + def >=(x: Byte): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Short): Boolean = sys.error("stub") + def >=(x: Short): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Char): Boolean = sys.error("stub") + def >=(x: Char): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Int): Boolean = sys.error("stub") + def >=(x: Int): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Long): Boolean = sys.error("stub") + def >=(x: Long): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Float): Boolean = sys.error("stub") + def >=(x: Float): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Double): Boolean = sys.error("stub") + def >=(x: Double): Boolean /** * Returns the sum of this value and `x`. */ - def +(x: Byte): Double = sys.error("stub") + def +(x: Byte): Double /** * Returns the sum of this value and `x`. */ - def +(x: Short): Double = sys.error("stub") + def +(x: Short): Double /** * Returns the sum of this value and `x`. */ - def +(x: Char): Double = sys.error("stub") + def +(x: Char): Double /** * Returns the sum of this value and `x`. */ - def +(x: Int): Double = sys.error("stub") + def +(x: Int): Double /** * Returns the sum of this value and `x`. */ - def +(x: Long): Double = sys.error("stub") + def +(x: Long): Double /** * Returns the sum of this value and `x`. */ - def +(x: Float): Double = sys.error("stub") + def +(x: Float): Double /** * Returns the sum of this value and `x`. */ - def +(x: Double): Double = sys.error("stub") + def +(x: Double): Double /** * Returns the difference of this value and `x`. */ - def -(x: Byte): Double = sys.error("stub") + def -(x: Byte): Double /** * Returns the difference of this value and `x`. */ - def -(x: Short): Double = sys.error("stub") + def -(x: Short): Double /** * Returns the difference of this value and `x`. */ - def -(x: Char): Double = sys.error("stub") + def -(x: Char): Double /** * Returns the difference of this value and `x`. */ - def -(x: Int): Double = sys.error("stub") + def -(x: Int): Double /** * Returns the difference of this value and `x`. */ - def -(x: Long): Double = sys.error("stub") + def -(x: Long): Double /** * Returns the difference of this value and `x`. */ - def -(x: Float): Double = sys.error("stub") + def -(x: Float): Double /** * Returns the difference of this value and `x`. */ - def -(x: Double): Double = sys.error("stub") + def -(x: Double): Double /** * Returns the product of this value and `x`. */ - def *(x: Byte): Double = sys.error("stub") + def *(x: Byte): Double /** * Returns the product of this value and `x`. */ - def *(x: Short): Double = sys.error("stub") + def *(x: Short): Double /** * Returns the product of this value and `x`. */ - def *(x: Char): Double = sys.error("stub") + def *(x: Char): Double /** * Returns the product of this value and `x`. */ - def *(x: Int): Double = sys.error("stub") + def *(x: Int): Double /** * Returns the product of this value and `x`. */ - def *(x: Long): Double = sys.error("stub") + def *(x: Long): Double /** * Returns the product of this value and `x`. */ - def *(x: Float): Double = sys.error("stub") + def *(x: Float): Double /** * Returns the product of this value and `x`. */ - def *(x: Double): Double = sys.error("stub") + def *(x: Double): Double /** * Returns the quotient of this value and `x`. */ - def /(x: Byte): Double = sys.error("stub") + def /(x: Byte): Double /** * Returns the quotient of this value and `x`. */ - def /(x: Short): Double = sys.error("stub") + def /(x: Short): Double /** * Returns the quotient of this value and `x`. */ - def /(x: Char): Double = sys.error("stub") + def /(x: Char): Double /** * Returns the quotient of this value and `x`. */ - def /(x: Int): Double = sys.error("stub") + def /(x: Int): Double /** * Returns the quotient of this value and `x`. */ - def /(x: Long): Double = sys.error("stub") + def /(x: Long): Double /** * Returns the quotient of this value and `x`. */ - def /(x: Float): Double = sys.error("stub") + def /(x: Float): Double /** * Returns the quotient of this value and `x`. */ - def /(x: Double): Double = sys.error("stub") + def /(x: Double): Double /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Byte): Double = sys.error("stub") + def %(x: Byte): Double /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Short): Double = sys.error("stub") + def %(x: Short): Double /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Char): Double = sys.error("stub") + def %(x: Char): Double /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Int): Double = sys.error("stub") + def %(x: Int): Double /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Long): Double = sys.error("stub") + def %(x: Long): Double /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Float): Double = sys.error("stub") + def %(x: Float): Double /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Double): Double = sys.error("stub") + def %(x: Double): Double - override def getClass(): Class[Double] = sys.error("stub") + override def getClass(): Class[Double] = null } -object Double extends AnyValCompanion { +object Double extends AnyValCompanion { /** The smallest positive value greater than 0.0d which is * representable as a Double. */ diff --git a/src/library/scala/Float.scala b/src/library/scala/Float.scala index bb03581062..bd7a07fece 100644 --- a/src/library/scala/Float.scala +++ b/src/library/scala/Float.scala @@ -10,6 +10,8 @@ package scala +import language.implicitConversions + /** `Float`, a 32-bit IEEE-754 floating point number (equivalent to Java's `float` primitive type) is a * subtype of [[scala.AnyVal]]. Instances of `Float` are not * represented by an object in the underlying runtime system. @@ -17,349 +19,349 @@ package scala * There is an implicit conversion from [[scala.Float]] => [[scala.runtime.RichFloat]] * which provides useful non-primitive operations. */ -final class Float private extends AnyVal { - def toByte: Byte = sys.error("stub") - def toShort: Short = sys.error("stub") - def toChar: Char = sys.error("stub") - def toInt: Int = sys.error("stub") - def toLong: Long = sys.error("stub") - def toFloat: Float = sys.error("stub") - def toDouble: Double = sys.error("stub") +final abstract class Float private extends AnyVal { + def toByte: Byte + def toShort: Short + def toChar: Char + def toInt: Int + def toLong: Long + def toFloat: Float + def toDouble: Double /** * Returns this value, unmodified. */ - def unary_+ : Float = sys.error("stub") + def unary_+ : Float /** * Returns the negation of this value. */ - def unary_- : Float = sys.error("stub") + def unary_- : Float - def +(x: String): String = sys.error("stub") + def +(x: String): String /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Byte): Boolean = sys.error("stub") + def ==(x: Byte): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Short): Boolean = sys.error("stub") + def ==(x: Short): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Char): Boolean = sys.error("stub") + def ==(x: Char): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Int): Boolean = sys.error("stub") + def ==(x: Int): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Long): Boolean = sys.error("stub") + def ==(x: Long): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Float): Boolean = sys.error("stub") + def ==(x: Float): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Double): Boolean = sys.error("stub") + def ==(x: Double): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Byte): Boolean = sys.error("stub") + def !=(x: Byte): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Short): Boolean = sys.error("stub") + def !=(x: Short): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Char): Boolean = sys.error("stub") + def !=(x: Char): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Int): Boolean = sys.error("stub") + def !=(x: Int): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Long): Boolean = sys.error("stub") + def !=(x: Long): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Float): Boolean = sys.error("stub") + def !=(x: Float): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Double): Boolean = sys.error("stub") + def !=(x: Double): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Byte): Boolean = sys.error("stub") + def <(x: Byte): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Short): Boolean = sys.error("stub") + def <(x: Short): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Char): Boolean = sys.error("stub") + def <(x: Char): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Int): Boolean = sys.error("stub") + def <(x: Int): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Long): Boolean = sys.error("stub") + def <(x: Long): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Float): Boolean = sys.error("stub") + def <(x: Float): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Double): Boolean = sys.error("stub") + def <(x: Double): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Byte): Boolean = sys.error("stub") + def <=(x: Byte): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Short): Boolean = sys.error("stub") + def <=(x: Short): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Char): Boolean = sys.error("stub") + def <=(x: Char): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Int): Boolean = sys.error("stub") + def <=(x: Int): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Long): Boolean = sys.error("stub") + def <=(x: Long): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Float): Boolean = sys.error("stub") + def <=(x: Float): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Double): Boolean = sys.error("stub") + def <=(x: Double): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Byte): Boolean = sys.error("stub") + def >(x: Byte): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Short): Boolean = sys.error("stub") + def >(x: Short): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Char): Boolean = sys.error("stub") + def >(x: Char): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Int): Boolean = sys.error("stub") + def >(x: Int): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Long): Boolean = sys.error("stub") + def >(x: Long): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Float): Boolean = sys.error("stub") + def >(x: Float): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Double): Boolean = sys.error("stub") + def >(x: Double): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Byte): Boolean = sys.error("stub") + def >=(x: Byte): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Short): Boolean = sys.error("stub") + def >=(x: Short): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Char): Boolean = sys.error("stub") + def >=(x: Char): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Int): Boolean = sys.error("stub") + def >=(x: Int): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Long): Boolean = sys.error("stub") + def >=(x: Long): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Float): Boolean = sys.error("stub") + def >=(x: Float): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Double): Boolean = sys.error("stub") + def >=(x: Double): Boolean /** * Returns the sum of this value and `x`. */ - def +(x: Byte): Float = sys.error("stub") + def +(x: Byte): Float /** * Returns the sum of this value and `x`. */ - def +(x: Short): Float = sys.error("stub") + def +(x: Short): Float /** * Returns the sum of this value and `x`. */ - def +(x: Char): Float = sys.error("stub") + def +(x: Char): Float /** * Returns the sum of this value and `x`. */ - def +(x: Int): Float = sys.error("stub") + def +(x: Int): Float /** * Returns the sum of this value and `x`. */ - def +(x: Long): Float = sys.error("stub") + def +(x: Long): Float /** * Returns the sum of this value and `x`. */ - def +(x: Float): Float = sys.error("stub") + def +(x: Float): Float /** * Returns the sum of this value and `x`. */ - def +(x: Double): Double = sys.error("stub") + def +(x: Double): Double /** * Returns the difference of this value and `x`. */ - def -(x: Byte): Float = sys.error("stub") + def -(x: Byte): Float /** * Returns the difference of this value and `x`. */ - def -(x: Short): Float = sys.error("stub") + def -(x: Short): Float /** * Returns the difference of this value and `x`. */ - def -(x: Char): Float = sys.error("stub") + def -(x: Char): Float /** * Returns the difference of this value and `x`. */ - def -(x: Int): Float = sys.error("stub") + def -(x: Int): Float /** * Returns the difference of this value and `x`. */ - def -(x: Long): Float = sys.error("stub") + def -(x: Long): Float /** * Returns the difference of this value and `x`. */ - def -(x: Float): Float = sys.error("stub") + def -(x: Float): Float /** * Returns the difference of this value and `x`. */ - def -(x: Double): Double = sys.error("stub") + def -(x: Double): Double /** * Returns the product of this value and `x`. */ - def *(x: Byte): Float = sys.error("stub") + def *(x: Byte): Float /** * Returns the product of this value and `x`. */ - def *(x: Short): Float = sys.error("stub") + def *(x: Short): Float /** * Returns the product of this value and `x`. */ - def *(x: Char): Float = sys.error("stub") + def *(x: Char): Float /** * Returns the product of this value and `x`. */ - def *(x: Int): Float = sys.error("stub") + def *(x: Int): Float /** * Returns the product of this value and `x`. */ - def *(x: Long): Float = sys.error("stub") + def *(x: Long): Float /** * Returns the product of this value and `x`. */ - def *(x: Float): Float = sys.error("stub") + def *(x: Float): Float /** * Returns the product of this value and `x`. */ - def *(x: Double): Double = sys.error("stub") + def *(x: Double): Double /** * Returns the quotient of this value and `x`. */ - def /(x: Byte): Float = sys.error("stub") + def /(x: Byte): Float /** * Returns the quotient of this value and `x`. */ - def /(x: Short): Float = sys.error("stub") + def /(x: Short): Float /** * Returns the quotient of this value and `x`. */ - def /(x: Char): Float = sys.error("stub") + def /(x: Char): Float /** * Returns the quotient of this value and `x`. */ - def /(x: Int): Float = sys.error("stub") + def /(x: Int): Float /** * Returns the quotient of this value and `x`. */ - def /(x: Long): Float = sys.error("stub") + def /(x: Long): Float /** * Returns the quotient of this value and `x`. */ - def /(x: Float): Float = sys.error("stub") + def /(x: Float): Float /** * Returns the quotient of this value and `x`. */ - def /(x: Double): Double = sys.error("stub") + def /(x: Double): Double /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Byte): Float = sys.error("stub") + def %(x: Byte): Float /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Short): Float = sys.error("stub") + def %(x: Short): Float /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Char): Float = sys.error("stub") + def %(x: Char): Float /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Int): Float = sys.error("stub") + def %(x: Int): Float /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Long): Float = sys.error("stub") + def %(x: Long): Float /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Float): Float = sys.error("stub") + def %(x: Float): Float /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Double): Double = sys.error("stub") + def %(x: Double): Double - override def getClass(): Class[Float] = sys.error("stub") + override def getClass(): Class[Float] = null } -object Float extends AnyValCompanion { +object Float extends AnyValCompanion { /** The smallest positive value greater than 0.0f which is * representable as a Float. */ @@ -401,6 +403,9 @@ object Float extends AnyValCompanion { /** The String representation of the scala.Float companion object. */ override def toString = "object scala.Float" + + /** Language mandated coercions from Float to "wider" types. + */ implicit def float2double(x: Float): Double = x.toDouble } diff --git a/src/library/scala/Int.scala b/src/library/scala/Int.scala index d5d7ef011d..b2a4f93253 100644 --- a/src/library/scala/Int.scala +++ b/src/library/scala/Int.scala @@ -10,6 +10,8 @@ package scala +import language.implicitConversions + /** `Int`, a 32-bit signed integer (equivalent to Java's `int` primitive type) is a * subtype of [[scala.AnyVal]]. Instances of `Int` are not * represented by an object in the underlying runtime system. @@ -17,14 +19,14 @@ package scala * There is an implicit conversion from [[scala.Int]] => [[scala.runtime.RichInt]] * which provides useful non-primitive operations. */ -final class Int private extends AnyVal { - def toByte: Byte = sys.error("stub") - def toShort: Short = sys.error("stub") - def toChar: Char = sys.error("stub") - def toInt: Int = sys.error("stub") - def toLong: Long = sys.error("stub") - def toFloat: Float = sys.error("stub") - def toDouble: Double = sys.error("stub") +final abstract class Int private extends AnyVal { + def toByte: Byte + def toShort: Short + def toChar: Char + def toInt: Int + def toLong: Long + def toFloat: Float + def toDouble: Double /** * Returns the bitwise negation of this value. @@ -34,30 +36,30 @@ final class Int private extends AnyVal { * // 11111010 * }}} */ - def unary_~ : Int = sys.error("stub") + def unary_~ : Int /** * Returns this value, unmodified. */ - def unary_+ : Int = sys.error("stub") + def unary_+ : Int /** * Returns the negation of this value. */ - def unary_- : Int = sys.error("stub") + def unary_- : Int - def +(x: String): String = sys.error("stub") + def +(x: String): String /** * Returns this value bit-shifted left by the specified number of bits, * filling in the new right bits with zeroes. * @example {{{ 6 << 3 == 48 // in binary: 0110 << 3 == 0110000 }}} */ - def <<(x: Int): Int = sys.error("stub") + def <<(x: Int): Int /** * Returns this value bit-shifted left by the specified number of bits, * filling in the new right bits with zeroes. * @example {{{ 6 << 3 == 48 // in binary: 0110 << 3 == 0110000 }}} */ - def <<(x: Long): Int = sys.error("stub") + def <<(x: Long): Int /** * Returns this value bit-shifted right by the specified number of bits, * filling the new left bits with zeroes. @@ -68,7 +70,7 @@ final class Int private extends AnyVal { * // 00011111 11111111 11111111 11111101 * }}} */ - def >>>(x: Int): Int = sys.error("stub") + def >>>(x: Int): Int /** * Returns this value bit-shifted right by the specified number of bits, * filling the new left bits with zeroes. @@ -79,7 +81,7 @@ final class Int private extends AnyVal { * // 00011111 11111111 11111111 11111101 * }}} */ - def >>>(x: Long): Int = sys.error("stub") + def >>>(x: Long): Int /** * Returns this value bit-shifted left by the specified number of bits, * filling in the right bits with the same value as the left-most bit of this. @@ -90,7 +92,7 @@ final class Int private extends AnyVal { * // 11111111 11111111 11111111 11111101 * }}} */ - def >>(x: Int): Int = sys.error("stub") + def >>(x: Int): Int /** * Returns this value bit-shifted left by the specified number of bits, * filling in the right bits with the same value as the left-most bit of this. @@ -101,181 +103,181 @@ final class Int private extends AnyVal { * // 11111111 11111111 11111111 11111101 * }}} */ - def >>(x: Long): Int = sys.error("stub") + def >>(x: Long): Int /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Byte): Boolean = sys.error("stub") + def ==(x: Byte): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Short): Boolean = sys.error("stub") + def ==(x: Short): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Char): Boolean = sys.error("stub") + def ==(x: Char): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Int): Boolean = sys.error("stub") + def ==(x: Int): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Long): Boolean = sys.error("stub") + def ==(x: Long): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Float): Boolean = sys.error("stub") + def ==(x: Float): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Double): Boolean = sys.error("stub") + def ==(x: Double): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Byte): Boolean = sys.error("stub") + def !=(x: Byte): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Short): Boolean = sys.error("stub") + def !=(x: Short): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Char): Boolean = sys.error("stub") + def !=(x: Char): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Int): Boolean = sys.error("stub") + def !=(x: Int): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Long): Boolean = sys.error("stub") + def !=(x: Long): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Float): Boolean = sys.error("stub") + def !=(x: Float): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Double): Boolean = sys.error("stub") + def !=(x: Double): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Byte): Boolean = sys.error("stub") + def <(x: Byte): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Short): Boolean = sys.error("stub") + def <(x: Short): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Char): Boolean = sys.error("stub") + def <(x: Char): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Int): Boolean = sys.error("stub") + def <(x: Int): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Long): Boolean = sys.error("stub") + def <(x: Long): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Float): Boolean = sys.error("stub") + def <(x: Float): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Double): Boolean = sys.error("stub") + def <(x: Double): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Byte): Boolean = sys.error("stub") + def <=(x: Byte): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Short): Boolean = sys.error("stub") + def <=(x: Short): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Char): Boolean = sys.error("stub") + def <=(x: Char): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Int): Boolean = sys.error("stub") + def <=(x: Int): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Long): Boolean = sys.error("stub") + def <=(x: Long): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Float): Boolean = sys.error("stub") + def <=(x: Float): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Double): Boolean = sys.error("stub") + def <=(x: Double): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Byte): Boolean = sys.error("stub") + def >(x: Byte): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Short): Boolean = sys.error("stub") + def >(x: Short): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Char): Boolean = sys.error("stub") + def >(x: Char): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Int): Boolean = sys.error("stub") + def >(x: Int): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Long): Boolean = sys.error("stub") + def >(x: Long): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Float): Boolean = sys.error("stub") + def >(x: Float): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Double): Boolean = sys.error("stub") + def >(x: Double): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Byte): Boolean = sys.error("stub") + def >=(x: Byte): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Short): Boolean = sys.error("stub") + def >=(x: Short): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Char): Boolean = sys.error("stub") + def >=(x: Char): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Int): Boolean = sys.error("stub") + def >=(x: Int): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Long): Boolean = sys.error("stub") + def >=(x: Long): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Float): Boolean = sys.error("stub") + def >=(x: Float): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Double): Boolean = sys.error("stub") + def >=(x: Double): Boolean /** * Returns the bitwise OR of this value and `x`. @@ -287,7 +289,7 @@ final class Int private extends AnyVal { * // 11111010 * }}} */ - def |(x: Byte): Int = sys.error("stub") + def |(x: Byte): Int /** * Returns the bitwise OR of this value and `x`. * @example {{{ @@ -298,7 +300,7 @@ final class Int private extends AnyVal { * // 11111010 * }}} */ - def |(x: Short): Int = sys.error("stub") + def |(x: Short): Int /** * Returns the bitwise OR of this value and `x`. * @example {{{ @@ -309,7 +311,7 @@ final class Int private extends AnyVal { * // 11111010 * }}} */ - def |(x: Char): Int = sys.error("stub") + def |(x: Char): Int /** * Returns the bitwise OR of this value and `x`. * @example {{{ @@ -320,7 +322,7 @@ final class Int private extends AnyVal { * // 11111010 * }}} */ - def |(x: Int): Int = sys.error("stub") + def |(x: Int): Int /** * Returns the bitwise OR of this value and `x`. * @example {{{ @@ -331,7 +333,7 @@ final class Int private extends AnyVal { * // 11111010 * }}} */ - def |(x: Long): Long = sys.error("stub") + def |(x: Long): Long /** * Returns the bitwise AND of this value and `x`. @@ -343,7 +345,7 @@ final class Int private extends AnyVal { * // 10100000 * }}} */ - def &(x: Byte): Int = sys.error("stub") + def &(x: Byte): Int /** * Returns the bitwise AND of this value and `x`. * @example {{{ @@ -354,7 +356,7 @@ final class Int private extends AnyVal { * // 10100000 * }}} */ - def &(x: Short): Int = sys.error("stub") + def &(x: Short): Int /** * Returns the bitwise AND of this value and `x`. * @example {{{ @@ -365,7 +367,7 @@ final class Int private extends AnyVal { * // 10100000 * }}} */ - def &(x: Char): Int = sys.error("stub") + def &(x: Char): Int /** * Returns the bitwise AND of this value and `x`. * @example {{{ @@ -376,7 +378,7 @@ final class Int private extends AnyVal { * // 10100000 * }}} */ - def &(x: Int): Int = sys.error("stub") + def &(x: Int): Int /** * Returns the bitwise AND of this value and `x`. * @example {{{ @@ -387,7 +389,7 @@ final class Int private extends AnyVal { * // 10100000 * }}} */ - def &(x: Long): Long = sys.error("stub") + def &(x: Long): Long /** * Returns the bitwise XOR of this value and `x`. @@ -399,7 +401,7 @@ final class Int private extends AnyVal { * // 01011010 * }}} */ - def ^(x: Byte): Int = sys.error("stub") + def ^(x: Byte): Int /** * Returns the bitwise XOR of this value and `x`. * @example {{{ @@ -410,7 +412,7 @@ final class Int private extends AnyVal { * // 01011010 * }}} */ - def ^(x: Short): Int = sys.error("stub") + def ^(x: Short): Int /** * Returns the bitwise XOR of this value and `x`. * @example {{{ @@ -421,7 +423,7 @@ final class Int private extends AnyVal { * // 01011010 * }}} */ - def ^(x: Char): Int = sys.error("stub") + def ^(x: Char): Int /** * Returns the bitwise XOR of this value and `x`. * @example {{{ @@ -432,7 +434,7 @@ final class Int private extends AnyVal { * // 01011010 * }}} */ - def ^(x: Int): Int = sys.error("stub") + def ^(x: Int): Int /** * Returns the bitwise XOR of this value and `x`. * @example {{{ @@ -443,157 +445,157 @@ final class Int private extends AnyVal { * // 01011010 * }}} */ - def ^(x: Long): Long = sys.error("stub") + def ^(x: Long): Long /** * Returns the sum of this value and `x`. */ - def +(x: Byte): Int = sys.error("stub") + def +(x: Byte): Int /** * Returns the sum of this value and `x`. */ - def +(x: Short): Int = sys.error("stub") + def +(x: Short): Int /** * Returns the sum of this value and `x`. */ - def +(x: Char): Int = sys.error("stub") + def +(x: Char): Int /** * Returns the sum of this value and `x`. */ - def +(x: Int): Int = sys.error("stub") + def +(x: Int): Int /** * Returns the sum of this value and `x`. */ - def +(x: Long): Long = sys.error("stub") + def +(x: Long): Long /** * Returns the sum of this value and `x`. */ - def +(x: Float): Float = sys.error("stub") + def +(x: Float): Float /** * Returns the sum of this value and `x`. */ - def +(x: Double): Double = sys.error("stub") + def +(x: Double): Double /** * Returns the difference of this value and `x`. */ - def -(x: Byte): Int = sys.error("stub") + def -(x: Byte): Int /** * Returns the difference of this value and `x`. */ - def -(x: Short): Int = sys.error("stub") + def -(x: Short): Int /** * Returns the difference of this value and `x`. */ - def -(x: Char): Int = sys.error("stub") + def -(x: Char): Int /** * Returns the difference of this value and `x`. */ - def -(x: Int): Int = sys.error("stub") + def -(x: Int): Int /** * Returns the difference of this value and `x`. */ - def -(x: Long): Long = sys.error("stub") + def -(x: Long): Long /** * Returns the difference of this value and `x`. */ - def -(x: Float): Float = sys.error("stub") + def -(x: Float): Float /** * Returns the difference of this value and `x`. */ - def -(x: Double): Double = sys.error("stub") + def -(x: Double): Double /** * Returns the product of this value and `x`. */ - def *(x: Byte): Int = sys.error("stub") + def *(x: Byte): Int /** * Returns the product of this value and `x`. */ - def *(x: Short): Int = sys.error("stub") + def *(x: Short): Int /** * Returns the product of this value and `x`. */ - def *(x: Char): Int = sys.error("stub") + def *(x: Char): Int /** * Returns the product of this value and `x`. */ - def *(x: Int): Int = sys.error("stub") + def *(x: Int): Int /** * Returns the product of this value and `x`. */ - def *(x: Long): Long = sys.error("stub") + def *(x: Long): Long /** * Returns the product of this value and `x`. */ - def *(x: Float): Float = sys.error("stub") + def *(x: Float): Float /** * Returns the product of this value and `x`. */ - def *(x: Double): Double = sys.error("stub") + def *(x: Double): Double /** * Returns the quotient of this value and `x`. */ - def /(x: Byte): Int = sys.error("stub") + def /(x: Byte): Int /** * Returns the quotient of this value and `x`. */ - def /(x: Short): Int = sys.error("stub") + def /(x: Short): Int /** * Returns the quotient of this value and `x`. */ - def /(x: Char): Int = sys.error("stub") + def /(x: Char): Int /** * Returns the quotient of this value and `x`. */ - def /(x: Int): Int = sys.error("stub") + def /(x: Int): Int /** * Returns the quotient of this value and `x`. */ - def /(x: Long): Long = sys.error("stub") + def /(x: Long): Long /** * Returns the quotient of this value and `x`. */ - def /(x: Float): Float = sys.error("stub") + def /(x: Float): Float /** * Returns the quotient of this value and `x`. */ - def /(x: Double): Double = sys.error("stub") + def /(x: Double): Double /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Byte): Int = sys.error("stub") + def %(x: Byte): Int /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Short): Int = sys.error("stub") + def %(x: Short): Int /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Char): Int = sys.error("stub") + def %(x: Char): Int /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Int): Int = sys.error("stub") + def %(x: Int): Int /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Long): Long = sys.error("stub") + def %(x: Long): Long /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Float): Float = sys.error("stub") + def %(x: Float): Float /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Double): Double = sys.error("stub") + def %(x: Double): Double - override def getClass(): Class[Int] = sys.error("stub") + override def getClass(): Class[Int] = null } -object Int extends AnyValCompanion { +object Int extends AnyValCompanion { /** The smallest value representable as a Int. */ final val MinValue = java.lang.Integer.MIN_VALUE @@ -622,6 +624,9 @@ object Int extends AnyValCompanion { /** The String representation of the scala.Int companion object. */ override def toString = "object scala.Int" + + /** Language mandated coercions from Int to "wider" types. + */ implicit def int2long(x: Int): Long = x.toLong implicit def int2float(x: Int): Float = x.toFloat implicit def int2double(x: Int): Double = x.toDouble diff --git a/src/library/scala/Long.scala b/src/library/scala/Long.scala index 85131b4f54..40932a65a7 100644 --- a/src/library/scala/Long.scala +++ b/src/library/scala/Long.scala @@ -10,6 +10,8 @@ package scala +import language.implicitConversions + /** `Long`, a 64-bit signed integer (equivalent to Java's `long` primitive type) is a * subtype of [[scala.AnyVal]]. Instances of `Long` are not * represented by an object in the underlying runtime system. @@ -17,14 +19,14 @@ package scala * There is an implicit conversion from [[scala.Long]] => [[scala.runtime.RichLong]] * which provides useful non-primitive operations. */ -final class Long private extends AnyVal { - def toByte: Byte = sys.error("stub") - def toShort: Short = sys.error("stub") - def toChar: Char = sys.error("stub") - def toInt: Int = sys.error("stub") - def toLong: Long = sys.error("stub") - def toFloat: Float = sys.error("stub") - def toDouble: Double = sys.error("stub") +final abstract class Long private extends AnyVal { + def toByte: Byte + def toShort: Short + def toChar: Char + def toInt: Int + def toLong: Long + def toFloat: Float + def toDouble: Double /** * Returns the bitwise negation of this value. @@ -34,30 +36,30 @@ final class Long private extends AnyVal { * // 11111010 * }}} */ - def unary_~ : Long = sys.error("stub") + def unary_~ : Long /** * Returns this value, unmodified. */ - def unary_+ : Long = sys.error("stub") + def unary_+ : Long /** * Returns the negation of this value. */ - def unary_- : Long = sys.error("stub") + def unary_- : Long - def +(x: String): String = sys.error("stub") + def +(x: String): String /** * Returns this value bit-shifted left by the specified number of bits, * filling in the new right bits with zeroes. * @example {{{ 6 << 3 == 48 // in binary: 0110 << 3 == 0110000 }}} */ - def <<(x: Int): Long = sys.error("stub") + def <<(x: Int): Long /** * Returns this value bit-shifted left by the specified number of bits, * filling in the new right bits with zeroes. * @example {{{ 6 << 3 == 48 // in binary: 0110 << 3 == 0110000 }}} */ - def <<(x: Long): Long = sys.error("stub") + def <<(x: Long): Long /** * Returns this value bit-shifted right by the specified number of bits, * filling the new left bits with zeroes. @@ -68,7 +70,7 @@ final class Long private extends AnyVal { * // 00011111 11111111 11111111 11111101 * }}} */ - def >>>(x: Int): Long = sys.error("stub") + def >>>(x: Int): Long /** * Returns this value bit-shifted right by the specified number of bits, * filling the new left bits with zeroes. @@ -79,7 +81,7 @@ final class Long private extends AnyVal { * // 00011111 11111111 11111111 11111101 * }}} */ - def >>>(x: Long): Long = sys.error("stub") + def >>>(x: Long): Long /** * Returns this value bit-shifted left by the specified number of bits, * filling in the right bits with the same value as the left-most bit of this. @@ -90,7 +92,7 @@ final class Long private extends AnyVal { * // 11111111 11111111 11111111 11111101 * }}} */ - def >>(x: Int): Long = sys.error("stub") + def >>(x: Int): Long /** * Returns this value bit-shifted left by the specified number of bits, * filling in the right bits with the same value as the left-most bit of this. @@ -101,181 +103,181 @@ final class Long private extends AnyVal { * // 11111111 11111111 11111111 11111101 * }}} */ - def >>(x: Long): Long = sys.error("stub") + def >>(x: Long): Long /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Byte): Boolean = sys.error("stub") + def ==(x: Byte): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Short): Boolean = sys.error("stub") + def ==(x: Short): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Char): Boolean = sys.error("stub") + def ==(x: Char): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Int): Boolean = sys.error("stub") + def ==(x: Int): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Long): Boolean = sys.error("stub") + def ==(x: Long): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Float): Boolean = sys.error("stub") + def ==(x: Float): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Double): Boolean = sys.error("stub") + def ==(x: Double): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Byte): Boolean = sys.error("stub") + def !=(x: Byte): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Short): Boolean = sys.error("stub") + def !=(x: Short): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Char): Boolean = sys.error("stub") + def !=(x: Char): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Int): Boolean = sys.error("stub") + def !=(x: Int): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Long): Boolean = sys.error("stub") + def !=(x: Long): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Float): Boolean = sys.error("stub") + def !=(x: Float): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Double): Boolean = sys.error("stub") + def !=(x: Double): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Byte): Boolean = sys.error("stub") + def <(x: Byte): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Short): Boolean = sys.error("stub") + def <(x: Short): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Char): Boolean = sys.error("stub") + def <(x: Char): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Int): Boolean = sys.error("stub") + def <(x: Int): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Long): Boolean = sys.error("stub") + def <(x: Long): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Float): Boolean = sys.error("stub") + def <(x: Float): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Double): Boolean = sys.error("stub") + def <(x: Double): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Byte): Boolean = sys.error("stub") + def <=(x: Byte): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Short): Boolean = sys.error("stub") + def <=(x: Short): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Char): Boolean = sys.error("stub") + def <=(x: Char): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Int): Boolean = sys.error("stub") + def <=(x: Int): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Long): Boolean = sys.error("stub") + def <=(x: Long): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Float): Boolean = sys.error("stub") + def <=(x: Float): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Double): Boolean = sys.error("stub") + def <=(x: Double): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Byte): Boolean = sys.error("stub") + def >(x: Byte): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Short): Boolean = sys.error("stub") + def >(x: Short): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Char): Boolean = sys.error("stub") + def >(x: Char): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Int): Boolean = sys.error("stub") + def >(x: Int): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Long): Boolean = sys.error("stub") + def >(x: Long): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Float): Boolean = sys.error("stub") + def >(x: Float): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Double): Boolean = sys.error("stub") + def >(x: Double): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Byte): Boolean = sys.error("stub") + def >=(x: Byte): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Short): Boolean = sys.error("stub") + def >=(x: Short): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Char): Boolean = sys.error("stub") + def >=(x: Char): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Int): Boolean = sys.error("stub") + def >=(x: Int): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Long): Boolean = sys.error("stub") + def >=(x: Long): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Float): Boolean = sys.error("stub") + def >=(x: Float): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Double): Boolean = sys.error("stub") + def >=(x: Double): Boolean /** * Returns the bitwise OR of this value and `x`. @@ -287,7 +289,7 @@ final class Long private extends AnyVal { * // 11111010 * }}} */ - def |(x: Byte): Long = sys.error("stub") + def |(x: Byte): Long /** * Returns the bitwise OR of this value and `x`. * @example {{{ @@ -298,7 +300,7 @@ final class Long private extends AnyVal { * // 11111010 * }}} */ - def |(x: Short): Long = sys.error("stub") + def |(x: Short): Long /** * Returns the bitwise OR of this value and `x`. * @example {{{ @@ -309,7 +311,7 @@ final class Long private extends AnyVal { * // 11111010 * }}} */ - def |(x: Char): Long = sys.error("stub") + def |(x: Char): Long /** * Returns the bitwise OR of this value and `x`. * @example {{{ @@ -320,7 +322,7 @@ final class Long private extends AnyVal { * // 11111010 * }}} */ - def |(x: Int): Long = sys.error("stub") + def |(x: Int): Long /** * Returns the bitwise OR of this value and `x`. * @example {{{ @@ -331,7 +333,7 @@ final class Long private extends AnyVal { * // 11111010 * }}} */ - def |(x: Long): Long = sys.error("stub") + def |(x: Long): Long /** * Returns the bitwise AND of this value and `x`. @@ -343,7 +345,7 @@ final class Long private extends AnyVal { * // 10100000 * }}} */ - def &(x: Byte): Long = sys.error("stub") + def &(x: Byte): Long /** * Returns the bitwise AND of this value and `x`. * @example {{{ @@ -354,7 +356,7 @@ final class Long private extends AnyVal { * // 10100000 * }}} */ - def &(x: Short): Long = sys.error("stub") + def &(x: Short): Long /** * Returns the bitwise AND of this value and `x`. * @example {{{ @@ -365,7 +367,7 @@ final class Long private extends AnyVal { * // 10100000 * }}} */ - def &(x: Char): Long = sys.error("stub") + def &(x: Char): Long /** * Returns the bitwise AND of this value and `x`. * @example {{{ @@ -376,7 +378,7 @@ final class Long private extends AnyVal { * // 10100000 * }}} */ - def &(x: Int): Long = sys.error("stub") + def &(x: Int): Long /** * Returns the bitwise AND of this value and `x`. * @example {{{ @@ -387,7 +389,7 @@ final class Long private extends AnyVal { * // 10100000 * }}} */ - def &(x: Long): Long = sys.error("stub") + def &(x: Long): Long /** * Returns the bitwise XOR of this value and `x`. @@ -399,7 +401,7 @@ final class Long private extends AnyVal { * // 01011010 * }}} */ - def ^(x: Byte): Long = sys.error("stub") + def ^(x: Byte): Long /** * Returns the bitwise XOR of this value and `x`. * @example {{{ @@ -410,7 +412,7 @@ final class Long private extends AnyVal { * // 01011010 * }}} */ - def ^(x: Short): Long = sys.error("stub") + def ^(x: Short): Long /** * Returns the bitwise XOR of this value and `x`. * @example {{{ @@ -421,7 +423,7 @@ final class Long private extends AnyVal { * // 01011010 * }}} */ - def ^(x: Char): Long = sys.error("stub") + def ^(x: Char): Long /** * Returns the bitwise XOR of this value and `x`. * @example {{{ @@ -432,7 +434,7 @@ final class Long private extends AnyVal { * // 01011010 * }}} */ - def ^(x: Int): Long = sys.error("stub") + def ^(x: Int): Long /** * Returns the bitwise XOR of this value and `x`. * @example {{{ @@ -443,157 +445,157 @@ final class Long private extends AnyVal { * // 01011010 * }}} */ - def ^(x: Long): Long = sys.error("stub") + def ^(x: Long): Long /** * Returns the sum of this value and `x`. */ - def +(x: Byte): Long = sys.error("stub") + def +(x: Byte): Long /** * Returns the sum of this value and `x`. */ - def +(x: Short): Long = sys.error("stub") + def +(x: Short): Long /** * Returns the sum of this value and `x`. */ - def +(x: Char): Long = sys.error("stub") + def +(x: Char): Long /** * Returns the sum of this value and `x`. */ - def +(x: Int): Long = sys.error("stub") + def +(x: Int): Long /** * Returns the sum of this value and `x`. */ - def +(x: Long): Long = sys.error("stub") + def +(x: Long): Long /** * Returns the sum of this value and `x`. */ - def +(x: Float): Float = sys.error("stub") + def +(x: Float): Float /** * Returns the sum of this value and `x`. */ - def +(x: Double): Double = sys.error("stub") + def +(x: Double): Double /** * Returns the difference of this value and `x`. */ - def -(x: Byte): Long = sys.error("stub") + def -(x: Byte): Long /** * Returns the difference of this value and `x`. */ - def -(x: Short): Long = sys.error("stub") + def -(x: Short): Long /** * Returns the difference of this value and `x`. */ - def -(x: Char): Long = sys.error("stub") + def -(x: Char): Long /** * Returns the difference of this value and `x`. */ - def -(x: Int): Long = sys.error("stub") + def -(x: Int): Long /** * Returns the difference of this value and `x`. */ - def -(x: Long): Long = sys.error("stub") + def -(x: Long): Long /** * Returns the difference of this value and `x`. */ - def -(x: Float): Float = sys.error("stub") + def -(x: Float): Float /** * Returns the difference of this value and `x`. */ - def -(x: Double): Double = sys.error("stub") + def -(x: Double): Double /** * Returns the product of this value and `x`. */ - def *(x: Byte): Long = sys.error("stub") + def *(x: Byte): Long /** * Returns the product of this value and `x`. */ - def *(x: Short): Long = sys.error("stub") + def *(x: Short): Long /** * Returns the product of this value and `x`. */ - def *(x: Char): Long = sys.error("stub") + def *(x: Char): Long /** * Returns the product of this value and `x`. */ - def *(x: Int): Long = sys.error("stub") + def *(x: Int): Long /** * Returns the product of this value and `x`. */ - def *(x: Long): Long = sys.error("stub") + def *(x: Long): Long /** * Returns the product of this value and `x`. */ - def *(x: Float): Float = sys.error("stub") + def *(x: Float): Float /** * Returns the product of this value and `x`. */ - def *(x: Double): Double = sys.error("stub") + def *(x: Double): Double /** * Returns the quotient of this value and `x`. */ - def /(x: Byte): Long = sys.error("stub") + def /(x: Byte): Long /** * Returns the quotient of this value and `x`. */ - def /(x: Short): Long = sys.error("stub") + def /(x: Short): Long /** * Returns the quotient of this value and `x`. */ - def /(x: Char): Long = sys.error("stub") + def /(x: Char): Long /** * Returns the quotient of this value and `x`. */ - def /(x: Int): Long = sys.error("stub") + def /(x: Int): Long /** * Returns the quotient of this value and `x`. */ - def /(x: Long): Long = sys.error("stub") + def /(x: Long): Long /** * Returns the quotient of this value and `x`. */ - def /(x: Float): Float = sys.error("stub") + def /(x: Float): Float /** * Returns the quotient of this value and `x`. */ - def /(x: Double): Double = sys.error("stub") + def /(x: Double): Double /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Byte): Long = sys.error("stub") + def %(x: Byte): Long /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Short): Long = sys.error("stub") + def %(x: Short): Long /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Char): Long = sys.error("stub") + def %(x: Char): Long /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Int): Long = sys.error("stub") + def %(x: Int): Long /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Long): Long = sys.error("stub") + def %(x: Long): Long /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Float): Float = sys.error("stub") + def %(x: Float): Float /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Double): Double = sys.error("stub") + def %(x: Double): Double - override def getClass(): Class[Long] = sys.error("stub") + override def getClass(): Class[Long] = null } -object Long extends AnyValCompanion { +object Long extends AnyValCompanion { /** The smallest value representable as a Long. */ final val MinValue = java.lang.Long.MIN_VALUE @@ -622,6 +624,9 @@ object Long extends AnyValCompanion { /** The String representation of the scala.Long companion object. */ override def toString = "object scala.Long" + + /** Language mandated coercions from Long to "wider" types. + */ implicit def long2float(x: Long): Float = x.toFloat implicit def long2double(x: Long): Double = x.toDouble } diff --git a/src/library/scala/Short.scala b/src/library/scala/Short.scala index 1060a9db16..687b198a11 100644 --- a/src/library/scala/Short.scala +++ b/src/library/scala/Short.scala @@ -10,6 +10,8 @@ package scala +import language.implicitConversions + /** `Short`, a 16-bit signed integer (equivalent to Java's `short` primitive type) is a * subtype of [[scala.AnyVal]]. Instances of `Short` are not * represented by an object in the underlying runtime system. @@ -17,14 +19,14 @@ package scala * There is an implicit conversion from [[scala.Short]] => [[scala.runtime.RichShort]] * which provides useful non-primitive operations. */ -final class Short private extends AnyVal { - def toByte: Byte = sys.error("stub") - def toShort: Short = sys.error("stub") - def toChar: Char = sys.error("stub") - def toInt: Int = sys.error("stub") - def toLong: Long = sys.error("stub") - def toFloat: Float = sys.error("stub") - def toDouble: Double = sys.error("stub") +final abstract class Short private extends AnyVal { + def toByte: Byte + def toShort: Short + def toChar: Char + def toInt: Int + def toLong: Long + def toFloat: Float + def toDouble: Double /** * Returns the bitwise negation of this value. @@ -34,30 +36,30 @@ final class Short private extends AnyVal { * // 11111010 * }}} */ - def unary_~ : Int = sys.error("stub") + def unary_~ : Int /** * Returns this value, unmodified. */ - def unary_+ : Int = sys.error("stub") + def unary_+ : Int /** * Returns the negation of this value. */ - def unary_- : Int = sys.error("stub") + def unary_- : Int - def +(x: String): String = sys.error("stub") + def +(x: String): String /** * Returns this value bit-shifted left by the specified number of bits, * filling in the new right bits with zeroes. * @example {{{ 6 << 3 == 48 // in binary: 0110 << 3 == 0110000 }}} */ - def <<(x: Int): Int = sys.error("stub") + def <<(x: Int): Int /** * Returns this value bit-shifted left by the specified number of bits, * filling in the new right bits with zeroes. * @example {{{ 6 << 3 == 48 // in binary: 0110 << 3 == 0110000 }}} */ - def <<(x: Long): Int = sys.error("stub") + def <<(x: Long): Int /** * Returns this value bit-shifted right by the specified number of bits, * filling the new left bits with zeroes. @@ -68,7 +70,7 @@ final class Short private extends AnyVal { * // 00011111 11111111 11111111 11111101 * }}} */ - def >>>(x: Int): Int = sys.error("stub") + def >>>(x: Int): Int /** * Returns this value bit-shifted right by the specified number of bits, * filling the new left bits with zeroes. @@ -79,7 +81,7 @@ final class Short private extends AnyVal { * // 00011111 11111111 11111111 11111101 * }}} */ - def >>>(x: Long): Int = sys.error("stub") + def >>>(x: Long): Int /** * Returns this value bit-shifted left by the specified number of bits, * filling in the right bits with the same value as the left-most bit of this. @@ -90,7 +92,7 @@ final class Short private extends AnyVal { * // 11111111 11111111 11111111 11111101 * }}} */ - def >>(x: Int): Int = sys.error("stub") + def >>(x: Int): Int /** * Returns this value bit-shifted left by the specified number of bits, * filling in the right bits with the same value as the left-most bit of this. @@ -101,181 +103,181 @@ final class Short private extends AnyVal { * // 11111111 11111111 11111111 11111101 * }}} */ - def >>(x: Long): Int = sys.error("stub") + def >>(x: Long): Int /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Byte): Boolean = sys.error("stub") + def ==(x: Byte): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Short): Boolean = sys.error("stub") + def ==(x: Short): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Char): Boolean = sys.error("stub") + def ==(x: Char): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Int): Boolean = sys.error("stub") + def ==(x: Int): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Long): Boolean = sys.error("stub") + def ==(x: Long): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Float): Boolean = sys.error("stub") + def ==(x: Float): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Double): Boolean = sys.error("stub") + def ==(x: Double): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Byte): Boolean = sys.error("stub") + def !=(x: Byte): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Short): Boolean = sys.error("stub") + def !=(x: Short): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Char): Boolean = sys.error("stub") + def !=(x: Char): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Int): Boolean = sys.error("stub") + def !=(x: Int): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Long): Boolean = sys.error("stub") + def !=(x: Long): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Float): Boolean = sys.error("stub") + def !=(x: Float): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Double): Boolean = sys.error("stub") + def !=(x: Double): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Byte): Boolean = sys.error("stub") + def <(x: Byte): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Short): Boolean = sys.error("stub") + def <(x: Short): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Char): Boolean = sys.error("stub") + def <(x: Char): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Int): Boolean = sys.error("stub") + def <(x: Int): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Long): Boolean = sys.error("stub") + def <(x: Long): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Float): Boolean = sys.error("stub") + def <(x: Float): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Double): Boolean = sys.error("stub") + def <(x: Double): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Byte): Boolean = sys.error("stub") + def <=(x: Byte): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Short): Boolean = sys.error("stub") + def <=(x: Short): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Char): Boolean = sys.error("stub") + def <=(x: Char): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Int): Boolean = sys.error("stub") + def <=(x: Int): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Long): Boolean = sys.error("stub") + def <=(x: Long): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Float): Boolean = sys.error("stub") + def <=(x: Float): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Double): Boolean = sys.error("stub") + def <=(x: Double): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Byte): Boolean = sys.error("stub") + def >(x: Byte): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Short): Boolean = sys.error("stub") + def >(x: Short): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Char): Boolean = sys.error("stub") + def >(x: Char): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Int): Boolean = sys.error("stub") + def >(x: Int): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Long): Boolean = sys.error("stub") + def >(x: Long): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Float): Boolean = sys.error("stub") + def >(x: Float): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Double): Boolean = sys.error("stub") + def >(x: Double): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Byte): Boolean = sys.error("stub") + def >=(x: Byte): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Short): Boolean = sys.error("stub") + def >=(x: Short): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Char): Boolean = sys.error("stub") + def >=(x: Char): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Int): Boolean = sys.error("stub") + def >=(x: Int): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Long): Boolean = sys.error("stub") + def >=(x: Long): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Float): Boolean = sys.error("stub") + def >=(x: Float): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Double): Boolean = sys.error("stub") + def >=(x: Double): Boolean /** * Returns the bitwise OR of this value and `x`. @@ -287,7 +289,7 @@ final class Short private extends AnyVal { * // 11111010 * }}} */ - def |(x: Byte): Int = sys.error("stub") + def |(x: Byte): Int /** * Returns the bitwise OR of this value and `x`. * @example {{{ @@ -298,7 +300,7 @@ final class Short private extends AnyVal { * // 11111010 * }}} */ - def |(x: Short): Int = sys.error("stub") + def |(x: Short): Int /** * Returns the bitwise OR of this value and `x`. * @example {{{ @@ -309,7 +311,7 @@ final class Short private extends AnyVal { * // 11111010 * }}} */ - def |(x: Char): Int = sys.error("stub") + def |(x: Char): Int /** * Returns the bitwise OR of this value and `x`. * @example {{{ @@ -320,7 +322,7 @@ final class Short private extends AnyVal { * // 11111010 * }}} */ - def |(x: Int): Int = sys.error("stub") + def |(x: Int): Int /** * Returns the bitwise OR of this value and `x`. * @example {{{ @@ -331,7 +333,7 @@ final class Short private extends AnyVal { * // 11111010 * }}} */ - def |(x: Long): Long = sys.error("stub") + def |(x: Long): Long /** * Returns the bitwise AND of this value and `x`. @@ -343,7 +345,7 @@ final class Short private extends AnyVal { * // 10100000 * }}} */ - def &(x: Byte): Int = sys.error("stub") + def &(x: Byte): Int /** * Returns the bitwise AND of this value and `x`. * @example {{{ @@ -354,7 +356,7 @@ final class Short private extends AnyVal { * // 10100000 * }}} */ - def &(x: Short): Int = sys.error("stub") + def &(x: Short): Int /** * Returns the bitwise AND of this value and `x`. * @example {{{ @@ -365,7 +367,7 @@ final class Short private extends AnyVal { * // 10100000 * }}} */ - def &(x: Char): Int = sys.error("stub") + def &(x: Char): Int /** * Returns the bitwise AND of this value and `x`. * @example {{{ @@ -376,7 +378,7 @@ final class Short private extends AnyVal { * // 10100000 * }}} */ - def &(x: Int): Int = sys.error("stub") + def &(x: Int): Int /** * Returns the bitwise AND of this value and `x`. * @example {{{ @@ -387,7 +389,7 @@ final class Short private extends AnyVal { * // 10100000 * }}} */ - def &(x: Long): Long = sys.error("stub") + def &(x: Long): Long /** * Returns the bitwise XOR of this value and `x`. @@ -399,7 +401,7 @@ final class Short private extends AnyVal { * // 01011010 * }}} */ - def ^(x: Byte): Int = sys.error("stub") + def ^(x: Byte): Int /** * Returns the bitwise XOR of this value and `x`. * @example {{{ @@ -410,7 +412,7 @@ final class Short private extends AnyVal { * // 01011010 * }}} */ - def ^(x: Short): Int = sys.error("stub") + def ^(x: Short): Int /** * Returns the bitwise XOR of this value and `x`. * @example {{{ @@ -421,7 +423,7 @@ final class Short private extends AnyVal { * // 01011010 * }}} */ - def ^(x: Char): Int = sys.error("stub") + def ^(x: Char): Int /** * Returns the bitwise XOR of this value and `x`. * @example {{{ @@ -432,7 +434,7 @@ final class Short private extends AnyVal { * // 01011010 * }}} */ - def ^(x: Int): Int = sys.error("stub") + def ^(x: Int): Int /** * Returns the bitwise XOR of this value and `x`. * @example {{{ @@ -443,157 +445,157 @@ final class Short private extends AnyVal { * // 01011010 * }}} */ - def ^(x: Long): Long = sys.error("stub") + def ^(x: Long): Long /** * Returns the sum of this value and `x`. */ - def +(x: Byte): Int = sys.error("stub") + def +(x: Byte): Int /** * Returns the sum of this value and `x`. */ - def +(x: Short): Int = sys.error("stub") + def +(x: Short): Int /** * Returns the sum of this value and `x`. */ - def +(x: Char): Int = sys.error("stub") + def +(x: Char): Int /** * Returns the sum of this value and `x`. */ - def +(x: Int): Int = sys.error("stub") + def +(x: Int): Int /** * Returns the sum of this value and `x`. */ - def +(x: Long): Long = sys.error("stub") + def +(x: Long): Long /** * Returns the sum of this value and `x`. */ - def +(x: Float): Float = sys.error("stub") + def +(x: Float): Float /** * Returns the sum of this value and `x`. */ - def +(x: Double): Double = sys.error("stub") + def +(x: Double): Double /** * Returns the difference of this value and `x`. */ - def -(x: Byte): Int = sys.error("stub") + def -(x: Byte): Int /** * Returns the difference of this value and `x`. */ - def -(x: Short): Int = sys.error("stub") + def -(x: Short): Int /** * Returns the difference of this value and `x`. */ - def -(x: Char): Int = sys.error("stub") + def -(x: Char): Int /** * Returns the difference of this value and `x`. */ - def -(x: Int): Int = sys.error("stub") + def -(x: Int): Int /** * Returns the difference of this value and `x`. */ - def -(x: Long): Long = sys.error("stub") + def -(x: Long): Long /** * Returns the difference of this value and `x`. */ - def -(x: Float): Float = sys.error("stub") + def -(x: Float): Float /** * Returns the difference of this value and `x`. */ - def -(x: Double): Double = sys.error("stub") + def -(x: Double): Double /** * Returns the product of this value and `x`. */ - def *(x: Byte): Int = sys.error("stub") + def *(x: Byte): Int /** * Returns the product of this value and `x`. */ - def *(x: Short): Int = sys.error("stub") + def *(x: Short): Int /** * Returns the product of this value and `x`. */ - def *(x: Char): Int = sys.error("stub") + def *(x: Char): Int /** * Returns the product of this value and `x`. */ - def *(x: Int): Int = sys.error("stub") + def *(x: Int): Int /** * Returns the product of this value and `x`. */ - def *(x: Long): Long = sys.error("stub") + def *(x: Long): Long /** * Returns the product of this value and `x`. */ - def *(x: Float): Float = sys.error("stub") + def *(x: Float): Float /** * Returns the product of this value and `x`. */ - def *(x: Double): Double = sys.error("stub") + def *(x: Double): Double /** * Returns the quotient of this value and `x`. */ - def /(x: Byte): Int = sys.error("stub") + def /(x: Byte): Int /** * Returns the quotient of this value and `x`. */ - def /(x: Short): Int = sys.error("stub") + def /(x: Short): Int /** * Returns the quotient of this value and `x`. */ - def /(x: Char): Int = sys.error("stub") + def /(x: Char): Int /** * Returns the quotient of this value and `x`. */ - def /(x: Int): Int = sys.error("stub") + def /(x: Int): Int /** * Returns the quotient of this value and `x`. */ - def /(x: Long): Long = sys.error("stub") + def /(x: Long): Long /** * Returns the quotient of this value and `x`. */ - def /(x: Float): Float = sys.error("stub") + def /(x: Float): Float /** * Returns the quotient of this value and `x`. */ - def /(x: Double): Double = sys.error("stub") + def /(x: Double): Double /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Byte): Int = sys.error("stub") + def %(x: Byte): Int /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Short): Int = sys.error("stub") + def %(x: Short): Int /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Char): Int = sys.error("stub") + def %(x: Char): Int /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Int): Int = sys.error("stub") + def %(x: Int): Int /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Long): Long = sys.error("stub") + def %(x: Long): Long /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Float): Float = sys.error("stub") + def %(x: Float): Float /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Double): Double = sys.error("stub") + def %(x: Double): Double - override def getClass(): Class[Short] = sys.error("stub") + override def getClass(): Class[Short] = null } -object Short extends AnyValCompanion { +object Short extends AnyValCompanion { /** The smallest value representable as a Short. */ final val MinValue = java.lang.Short.MIN_VALUE @@ -622,6 +624,9 @@ object Short extends AnyValCompanion { /** The String representation of the scala.Short companion object. */ override def toString = "object scala.Short" + + /** Language mandated coercions from Short to "wider" types. + */ implicit def short2int(x: Short): Int = x.toInt implicit def short2long(x: Short): Long = x.toLong implicit def short2float(x: Short): Float = x.toFloat diff --git a/src/library/scala/Unit.scala b/src/library/scala/Unit.scala index 3da5c083d4..4156071f29 100644 --- a/src/library/scala/Unit.scala +++ b/src/library/scala/Unit.scala @@ -10,17 +10,19 @@ package scala +import language.implicitConversions + /** `Unit` is a subtype of [[scala.AnyVal]]. There is only one value of type * `Unit`, `()`, and it is not represented by any object in the underlying * runtime system. A method with return type `Unit` is analogous to a Java * method which is declared `void`. */ -final class Unit private extends AnyVal { - override def getClass(): Class[Unit] = sys.error("stub") +final abstract class Unit private extends AnyVal { + override def getClass(): Class[Unit] = null } -object Unit extends AnyValCompanion { +object Unit extends AnyValCompanion { /** Transform a value type into a boxed reference type. * diff --git a/src/library/scala/collection/GenMapLike.scala b/src/library/scala/collection/GenMapLike.scala index 4dd2a4fe37..b6c90d4d2a 100644 --- a/src/library/scala/collection/GenMapLike.scala +++ b/src/library/scala/collection/GenMapLike.scala @@ -31,7 +31,7 @@ trait GenMapLike[A, +B, +Repr] extends GenIterableLike[(A, B), Repr] with Equals // This hash code must be symmetric in the contents but ought not // collide trivially. - override def hashCode() = util.MurmurHash3.mapHash(seq) + override def hashCode() = util.hashing.MurmurHash3.mapHash(seq) /** Returns the value associated with a key, or a default value if the key is not contained in the map. * @param key the key. diff --git a/src/library/scala/collection/GenSeqLike.scala b/src/library/scala/collection/GenSeqLike.scala index cfa0ca101e..a77cb05960 100644 --- a/src/library/scala/collection/GenSeqLike.scala +++ b/src/library/scala/collection/GenSeqLike.scala @@ -465,7 +465,7 @@ trait GenSeqLike[+A, +Repr] extends Any with GenIterableLike[A, Repr] with Equal /** Hashcodes for $Coll produce a value from the hashcodes of all the * elements of the $coll. */ - override def hashCode() = util.MurmurHash3.seqHash(seq) + override def hashCode() = util.hashing.MurmurHash3.seqHash(seq) /** The equals method for arbitrary sequences. Compares this sequence to * some other object. diff --git a/src/library/scala/collection/GenSetLike.scala b/src/library/scala/collection/GenSetLike.scala index 219374abc6..18eb31da03 100644 --- a/src/library/scala/collection/GenSetLike.scala +++ b/src/library/scala/collection/GenSetLike.scala @@ -127,5 +127,5 @@ extends GenIterableLike[A, Repr] // Calling map on a set drops duplicates: any hashcode collisions would // then be dropped before they can be added. // Hash should be symmetric in set entries, but without trivial collisions. - override def hashCode() = util.MurmurHash3.setHash(seq) + override def hashCode() = util.hashing.MurmurHash3.setHash(seq) } diff --git a/src/library/scala/collection/IndexedSeqLike.scala b/src/library/scala/collection/IndexedSeqLike.scala index 11f481e425..f79a9d2c66 100644 --- a/src/library/scala/collection/IndexedSeqLike.scala +++ b/src/library/scala/collection/IndexedSeqLike.scala @@ -41,7 +41,7 @@ trait IndexedSeqLike[+A, +Repr] extends Any with SeqLike[A, Repr] { self => def seq: IndexedSeq[A] - override def hashCode() = util.MurmurHash3.seqHash(seq) // TODO - can we get faster via "indexedSeqHash" ? + override def hashCode() = util.hashing.MurmurHash3.seqHash(seq) // TODO - can we get faster via "indexedSeqHash" ? override protected[this] def thisCollection: IndexedSeq[A] = this.asInstanceOf[IndexedSeq[A]] override protected[this] def toCollection(repr: Repr): IndexedSeq[A] = repr.asInstanceOf[IndexedSeq[A]] diff --git a/src/library/scala/collection/LinearSeqLike.scala b/src/library/scala/collection/LinearSeqLike.scala index ceb980ff80..bfe27ef94a 100644 --- a/src/library/scala/collection/LinearSeqLike.scala +++ b/src/library/scala/collection/LinearSeqLike.scala @@ -50,7 +50,7 @@ trait LinearSeqLike[+A, +Repr <: LinearSeqLike[A, Repr]] extends SeqLike[A, Repr def seq: LinearSeq[A] - override def hashCode() = util.MurmurHash3.seqHash(seq) // TODO - can we get faster via "linearSeqHash" ? + override def hashCode() = util.hashing.MurmurHash3.seqHash(seq) // TODO - can we get faster via "linearSeqHash" ? override /*IterableLike*/ def iterator: Iterator[A] = new AbstractIterator[A] { diff --git a/src/library/scala/collection/concurrent/TrieMap.scala b/src/library/scala/collection/concurrent/TrieMap.scala index f944d20bdb..08e9125bd8 100644 --- a/src/library/scala/collection/concurrent/TrieMap.scala +++ b/src/library/scala/collection/concurrent/TrieMap.scala @@ -825,7 +825,7 @@ extends scala.collection.concurrent.Map[K, V] } @inline - def computeHash(k: K) = hashingobj.hashCode(k) + def computeHash(k: K) = hashingobj.hash(k) final def lookup(k: K): V = { val hc = computeHash(k) @@ -915,11 +915,7 @@ object TrieMap extends MutableMapFactory[TrieMap] { def empty[K, V]: TrieMap[K, V] = new TrieMap[K, V] class MangledHashing[K] extends Hashing[K] { - def hashCode(k: K) = { - var hcode = k.## * 0x9e3775cd - hcode = java.lang.Integer.reverseBytes(hcode) - hcode * 0x9e3775cd - } + def hash(k: K) = util.hashing.byteswap32(k.##) } } diff --git a/src/library/scala/collection/convert/Wrappers.scala b/src/library/scala/collection/convert/Wrappers.scala index b1b48b760f..8c603dc91b 100644 --- a/src/library/scala/collection/convert/Wrappers.scala +++ b/src/library/scala/collection/convert/Wrappers.scala @@ -171,15 +171,16 @@ private[collection] trait Wrappers { var prev : Option[A] = None def hasNext = ui.hasNext - + def next() = { val (k, v) = ui.next prev = Some(k) new ju.Map.Entry[A, B] { + import util.hashing.byteswap32 def getKey = k def getValue = v def setValue(v1 : B) = self.put(k, v1) - override def hashCode = k.hashCode + v.hashCode + override def hashCode = byteswap32(k.hashCode) + (byteswap32(v.hashCode) << 16) override def equals(other: Any) = other match { case e: ju.Map.Entry[_, _] => k == e.getKey && v == e.getValue case _ => false diff --git a/src/library/scala/collection/immutable/HashMap.scala b/src/library/scala/collection/immutable/HashMap.scala index 13a0febfee..05529761d3 100644 --- a/src/library/scala/collection/immutable/HashMap.scala +++ b/src/library/scala/collection/immutable/HashMap.scala @@ -74,11 +74,22 @@ class HashMap[A, +B] extends AbstractMap[A, B] private[collection] def computeHash(key: A) = improve(elemHashCode(key)) - protected type Merger[B1] = ((A, B1), (A, B1)) => (A, B1) + protected type MergeFunction[A1, B1] = ((A1, B1), (A1, B1)) => (A1, B1); + + import HashMap.Merger + + protected def liftMerger[A1, B1](mergef: MergeFunction[A1, B1]): Merger[A1, B1] = if (mergef == null) null else new Merger[A1, B1] { + self => + def apply(kv1: (A1, B1), kv2: (A1, B1)): (A1, B1) = mergef(kv1, kv2) + val invert: Merger[A1, B1] = new Merger[A1, B1] { + def apply(kv1: (A1, B1), kv2: (A1, B1)): (A1, B1) = mergef(kv2, kv1) + def invert: Merger[A1, B1] = self + } + } private[collection] def get0(key: A, hash: Int, level: Int): Option[B] = None - private[collection] def updated0[B1 >: B](key: A, hash: Int, level: Int, value: B1, kv: (A, B1), merger: Merger[B1]): HashMap[A, B1] = + private[collection] def updated0[B1 >: B](key: A, hash: Int, level: Int, value: B1, kv: (A, B1), merger: Merger[A, B1]): HashMap[A, B1] = new HashMap.HashMap1(key, hash, value, kv) protected def removed0(key: A, hash: Int, level: Int): HashMap[A, B] = this @@ -87,9 +98,25 @@ class HashMap[A, +B] extends AbstractMap[A, B] def split: Seq[HashMap[A, B]] = Seq(this) - def merge[B1 >: B](that: HashMap[A, B1], merger: Merger[B1] = null): HashMap[A, B1] = merge0(that, 0, merger) - - protected def merge0[B1 >: B](that: HashMap[A, B1], level: Int, merger: Merger[B1]): HashMap[A, B1] = that + @deprecated("Use the `merged` method instead.", "2.10.0") + def merge[B1 >: B](that: HashMap[A, B1], mergef: MergeFunction[A, B1] = null): HashMap[A, B1] = merge0(that, 0, liftMerger(mergef)) + + /** Creates a new map which is the merge of this and the argument hash map. + * + * Uses the specified collision resolution function if two keys are the same. + * The collision resolution function will always take the first argument from + * `this` hash map and the second from `that`. + * + * The `merged` method is on average more performant than doing a traversal and reconstructing a + * new immutable hash map from scratch, or `++`. + * + * @tparam B1 the value type of the other hash map + * @param that the other hash map + * @param mergef the merge function or null if the first key-value pair is to be picked + */ + def merged[B1 >: B](that: HashMap[A, B1])(mergef: MergeFunction[A, B1]): HashMap[A, B1] = merge0(that, 0, liftMerger(mergef)) + + protected def merge0[B1 >: B](that: HashMap[A, B1], level: Int, merger: Merger[A, B1]): HashMap[A, B1] = that override def par = ParHashMap.fromTrie(this) @@ -103,6 +130,13 @@ class HashMap[A, +B] extends AbstractMap[A, B] * @since 2.3 */ object HashMap extends ImmutableMapFactory[HashMap] with BitOperations.Int { + + private[immutable] abstract class Merger[A, B] { + def apply(kv1: (A, B), kv2: (A, B)): (A, B) + def invert: Merger[A, B] + } + + /** $mapCanBuildFromInfo */ implicit def canBuildFrom[A, B]: CanBuildFrom[Coll, (A, B), HashMap[A, B]] = new MapCanBuildFrom[A, B] def empty[A, B]: HashMap[A, B] = EmptyHashMap.asInstanceOf[HashMap[A, B]] @@ -136,12 +170,15 @@ object HashMap extends ImmutableMapFactory[HashMap] with BitOperations.Int { // } // } - override def updated0[B1 >: B](key: A, hash: Int, level: Int, value: B1, kv: (A, B1), merger: Merger[B1]): HashMap[A, B1] = + override def updated0[B1 >: B](key: A, hash: Int, level: Int, value: B1, kv: (A, B1), merger: Merger[A, B1]): HashMap[A, B1] = if (hash == this.hash && key == this.key ) { if (merger eq null) { - if(this.value.asInstanceOf[AnyRef] eq value.asInstanceOf[AnyRef]) this + if (this.value.asInstanceOf[AnyRef] eq value.asInstanceOf[AnyRef]) this else new HashMap1(key, hash, value, kv) - } else new HashMap1(key, hash, value, merger(this.kv, kv)) + } else { + val nkv = merger(this.kv, kv) + new HashMap1(nkv._1, hash, nkv._2, nkv) + } } else { var thatindex = (hash >>> level) & 0x1f var thisindex = (this.hash >>> level) & 0x1f @@ -180,8 +217,8 @@ object HashMap extends ImmutableMapFactory[HashMap] with BitOperations.Int { override def foreach[U](f: ((A, B)) => U): Unit = f(ensurePair) // this method may be called multiple times in a multithreaded environment, but that's ok private[HashMap] def ensurePair: (A,B) = if (kv ne null) kv else { kv = (key, value); kv } - protected override def merge0[B1 >: B](that: HashMap[A, B1], level: Int, merger: Merger[B1]): HashMap[A, B1] = { - that.updated0(key, hash, level, value, kv, merger) + protected override def merge0[B1 >: B](that: HashMap[A, B1], level: Int, merger: Merger[A, B1]): HashMap[A, B1] = { + that.updated0(key, hash, level, value, kv, if (merger ne null) merger.invert else null) } } @@ -193,7 +230,7 @@ object HashMap extends ImmutableMapFactory[HashMap] with BitOperations.Int { override def get0(key: A, hash: Int, level: Int): Option[B] = if (hash == this.hash) kvs.get(key) else None - override def updated0[B1 >: B](key: A, hash: Int, level: Int, value: B1, kv: (A, B1), merger: Merger[B1]): HashMap[A, B1] = + override def updated0[B1 >: B](key: A, hash: Int, level: Int, value: B1, kv: (A, B1), merger: Merger[A, B1]): HashMap[A, B1] = if (hash == this.hash) { if ((merger eq null) || !kvs.contains(key)) new HashMapCollision1(hash, kvs.updated(key, value)) else new HashMapCollision1(hash, kvs + merger((key, kvs(key)), kv)) @@ -221,7 +258,7 @@ object HashMap extends ImmutableMapFactory[HashMap] with BitOperations.Int { def newhm(lm: ListMap[A, B @uV]) = new HashMapCollision1(hash, lm) List(newhm(x), newhm(y)) } - protected override def merge0[B1 >: B](that: HashMap[A, B1], level: Int, merger: Merger[B1]): HashMap[A, B1] = { + protected override def merge0[B1 >: B](that: HashMap[A, B1], level: Int, merger: Merger[A, B1]): HashMap[A, B1] = { // this can be made more efficient by passing the entire ListMap at once var m = that for (p <- kvs) m = m.updated0(p._1, this.hash, level, p._2, p, merger) @@ -268,7 +305,7 @@ object HashMap extends ImmutableMapFactory[HashMap] with BitOperations.Int { None } - override def updated0[B1 >: B](key: A, hash: Int, level: Int, value: B1, kv: (A, B1), merger: Merger[B1]): HashMap[A, B1] = { + override def updated0[B1 >: B](key: A, hash: Int, level: Int, value: B1, kv: (A, B1), merger: Merger[A, B1]): HashMap[A, B1] = { val index = (hash >>> level) & 0x1f val mask = (1 << index) val offset = Integer.bitCount(bitmap & (mask-1)) @@ -380,7 +417,7 @@ time { mNew.iterator.foreach( p => ()) } } else elems(0).split } - protected override def merge0[B1 >: B](that: HashMap[A, B1], level: Int, merger: Merger[B1]): HashMap[A, B1] = that match { + protected override def merge0[B1 >: B](that: HashMap[A, B1], level: Int, merger: Merger[A, B1]): HashMap[A, B1] = that match { case hm: HashMap1[_, _] => this.updated0(hm.key, hm.hash, level, hm.value.asInstanceOf[B1], hm.kv, merger) case hm: HashTrieMap[_, _] => @@ -440,7 +477,7 @@ time { mNew.iterator.foreach( p => ()) } } new HashTrieMap[A, B1](this.bitmap | that.bitmap, merged, totalelems) - case hm: HashMapCollision1[_, _] => that.merge0(this, level, merger) + case hm: HashMapCollision1[_, _] => that.merge0(this, level, if (merger ne null) merger.invert else null) case hm: HashMap[_, _] => this case _ => sys.error("section supposed to be unreachable.") } diff --git a/src/library/scala/collection/mutable/FlatHashTable.scala b/src/library/scala/collection/mutable/FlatHashTable.scala index 4070174902..f6d4cc31b6 100644 --- a/src/library/scala/collection/mutable/FlatHashTable.scala +++ b/src/library/scala/collection/mutable/FlatHashTable.scala @@ -397,9 +397,7 @@ private[collection] object FlatHashTable { //h = h + (h << 4) //h ^ (h >>> 10) - var i = hcode * 0x9e3775cd - i = java.lang.Integer.reverseBytes(i) - val improved = i * 0x9e3775cd + val improved = util.hashing.byteswap32(hcode) // for the remainder, see SI-5293 // to ensure that different bits are used for different hash tables, we have to rotate based on the seed diff --git a/src/library/scala/collection/mutable/HashTable.scala b/src/library/scala/collection/mutable/HashTable.scala index c307e6dcab..97e794f06e 100644 --- a/src/library/scala/collection/mutable/HashTable.scala +++ b/src/library/scala/collection/mutable/HashTable.scala @@ -401,12 +401,7 @@ private[collection] object HashTable { * * For performance reasons, we avoid this improvement. * */ - var i = hcode * 0x9e3775cd - i = java.lang.Integer.reverseBytes(i) - i = i * 0x9e3775cd - // a slower alternative for byte reversal: - // i = (i << 16) | (i >> 16) - // i = ((i >> 8) & 0x00ff00ff) | ((i << 8) & 0xff00ff00) + val i = util.hashing.byteswap32(hcode) /* Jenkins hash * for range 0-10000, output has the msb set to zero */ diff --git a/src/library/scala/collection/mutable/UnrolledBuffer.scala b/src/library/scala/collection/mutable/UnrolledBuffer.scala index cd76c7de4e..0c2e6e1cae 100644 --- a/src/library/scala/collection/mutable/UnrolledBuffer.scala +++ b/src/library/scala/collection/mutable/UnrolledBuffer.scala @@ -179,6 +179,8 @@ extends collection.mutable.AbstractBuffer[T] } } + override def clone(): UnrolledBuffer[T] = new UnrolledBuffer[T] ++= this + override def stringPrefix = "UnrolledBuffer" } diff --git a/src/library/scala/concurrent/impl/ExecutionContextImpl.scala b/src/library/scala/concurrent/impl/ExecutionContextImpl.scala index 1083a93439..7549bf8314 100644 --- a/src/library/scala/concurrent/impl/ExecutionContextImpl.scala +++ b/src/library/scala/concurrent/impl/ExecutionContextImpl.scala @@ -43,17 +43,31 @@ private[scala] class ExecutionContextImpl private[impl] (es: Executor, reporter: } } } - - def createExecutorService: ExecutorService = try { new ForkJoinPool( - Runtime.getRuntime.availableProcessors(), //FIXME from config - forkJoinPoolThreadFactory, - null, //FIXME we should have an UncaughtExceptionHandler, see what Akka does - true) //FIXME I really think this should be async... + + def createExecutorService: ExecutorService = try { + def getInt(name: String, f: String => Int): Int = + try f(System.getProperty(name)) catch { case e: Exception => Runtime.getRuntime.availableProcessors } + def range(floor: Int, desired: Int, ceiling: Int): Int = + if (ceiling < floor) range(ceiling, desired, floor) else scala.math.min(scala.math.max(desired, floor), ceiling) + + new ForkJoinPool( + range( + getInt("scala.concurrent.ec.minThreads", _.toInt), + getInt("scala.concurrent.ec.numThreads", { + case null | "" => Runtime.getRuntime.availableProcessors + case s if s.charAt(0) == 'x' => (Runtime.getRuntime.availableProcessors * s.substring(1).toDouble).ceil.toInt + case other => other.toInt + }), + getInt("scala.concurrent.ec.maxThreads", _.toInt) + ), + forkJoinPoolThreadFactory, + null, //FIXME we should have an UncaughtExceptionHandler, see what Akka does + true) //FIXME I really think this should be async... } catch { case NonFatal(t) => System.err.println("Failed to create ForkJoinPool for the default ExecutionContext, falling back to Executors.newCachedThreadPool") t.printStackTrace(System.err) - Executors.newCachedThreadPool(executorsThreadFactory) + Executors.newCachedThreadPool(executorsThreadFactory) //FIXME use the same desired parallelism here too? } def execute(runnable: Runnable): Unit = executor match { diff --git a/src/library/scala/math/Ordered.scala b/src/library/scala/math/Ordered.scala index 80addea7f3..a5efa41b80 100644 --- a/src/library/scala/math/Ordered.scala +++ b/src/library/scala/math/Ordered.scala @@ -15,7 +15,7 @@ import language.implicitConversions * more information about whether to use [[scala.math.Ordering]] instead. * * Classes that implement this trait can be sorted with - * [[scala.utils.Sorting]] and can be compared with standard comparison operators + * [[scala.util.Sorting]] and can be compared with standard comparison operators * (e.g. > and <). * * Ordered should be used for data with a single, natural ordering (like @@ -27,14 +27,15 @@ import language.implicitConversions * * [[scala.math.PartiallyOrdered]] is an alternative to this trait for partially ordered data. * - * For example, to create a simple class that implements Ordered and then sort it with [[scala.utils.Sorting]]: + * For example, create a simple class that implements `Ordered` and then sort it with [[scala.util.Sorting]]: * {{{ - * class OrderedClass(n:Int) extends Ordered[OrderedClass] { + * case class OrderedClass(n:Int) extends Ordered[OrderedClass] { * def compare(that: OrderedClass) = this.n - that.n * } * - * val x = List(new MyClass(1), new MyClass(5), new MyClass(3)) - * val result = scala.utils.Sorting.quickSort(x) + * val x = Array(OrderedClass(1), OrderedClass(5), OrderedClass(3)) + * scala.util.Sorting.quickSort(x) + * x * }}} * * It is important that the `equals` method for an instance of `Ordered[A]` be consistent with the diff --git a/src/library/scala/runtime/ScalaRunTime.scala b/src/library/scala/runtime/ScalaRunTime.scala index 4c5e0e408b..5cd301a0fe 100644 --- a/src/library/scala/runtime/ScalaRunTime.scala +++ b/src/library/scala/runtime/ScalaRunTime.scala @@ -199,7 +199,7 @@ object ScalaRunTime { def _toString(x: Product): String = x.productIterator.mkString(x.productPrefix + "(", ",", ")") - def _hashCode(x: Product): Int = scala.util.MurmurHash3.productHash(x) + def _hashCode(x: Product): Int = scala.util.hashing.MurmurHash3.productHash(x) /** A helper for case classes. */ def typedProductIterator[T](x: Product): Iterator[T] = { diff --git a/src/library/scala/util/hashing/ByteswapHashing.scala b/src/library/scala/util/hashing/ByteswapHashing.scala new file mode 100644 index 0000000000..fc8a33a486 --- /dev/null +++ b/src/library/scala/util/hashing/ByteswapHashing.scala @@ -0,0 +1,35 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2011, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://www.scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +package scala.util.hashing + + + + + + +/** A fast multiplicative hash by Phil Bagwell. + */ +final class ByteswapHashing[T] extends Hashing[T] { + + def hash(v: T) = byteswap32(v.##) + +} + + +object ByteswapHashing { + + private class Chained[T](h: Hashing[T]) extends Hashing[T] { + def hash(v: T) = byteswap32(h.hash(v)) + } + + /** Composes another `Hashing` with the Byteswap hash. + */ + def chain[T](h: Hashing[T]): Hashing[T] = new Chained(h) + +} diff --git a/src/library/scala/util/hashing/Hashing.scala b/src/library/scala/util/hashing/Hashing.scala index f27a825125..84b549f35e 100644 --- a/src/library/scala/util/hashing/Hashing.scala +++ b/src/library/scala/util/hashing/Hashing.scala @@ -22,7 +22,7 @@ package scala.util.hashing @annotation.implicitNotFound(msg = "No implicit Hashing defined for ${T}.") trait Hashing[T] extends Serializable { - def hashCode(x: T): Int + def hash(x: T): Int } @@ -30,13 +30,13 @@ trait Hashing[T] extends Serializable { object Hashing { final class Default[T] extends Hashing[T] { - def hashCode(x: T) = x.## + def hash(x: T) = x.## } implicit def default[T] = new Default[T] def fromFunction[T](f: T => Int) = new Hashing[T] { - def hashCode(x: T) = f(x) + def hash(x: T) = f(x) } } diff --git a/src/library/scala/util/MurmurHash3.scala b/src/library/scala/util/hashing/MurmurHash3.scala index 9a7f64b4ee..3efd5b5e72 100644 --- a/src/library/scala/util/MurmurHash3.scala +++ b/src/library/scala/util/hashing/MurmurHash3.scala @@ -6,30 +6,11 @@ ** |/ ** \* */ -package scala.util +package scala.util.hashing import java.lang.Integer.{ rotateLeft => rotl } -/** - * An implementation of Austin Appleby's MurmurHash 3 algorithm - * (MurmurHash3_x86_32). - * - * An algorithm designed to generate well-distributed non-cryptographic - * hashes. It is designed to hash data in 32 bit chunks (ints). - * - * The mix method needs to be called at each step to update the intermediate - * hash value. For the last chunk to incorporate into the hash mixLast may - * be used instead, which is slightly faster. Finally finalizeHash needs to - * be called to compute the final hash value. - * - * This is based on the earlier MurmurHash3 code by Rex Kerr, but the - * MurmurHash3 algorithm was since changed by its creator Austin Appleby - * to remedy some weaknesses and improve performance. This represents the - * latest and supposedly final version of the algortihm (revision 136). - * - * @see [[http://code.google.com/p/smhasher]] - */ -class MurmurHash3 { +private[hashing] class MurmurHash3 { /** Mix in a block of data into an intermediate hash value. */ final def mix(hash: Int, data: Int): Int = { var h = mixLast(hash, data) @@ -179,8 +160,25 @@ class MurmurHash3 { } /** - * An instance of MurmurHash3 with predefined seeds for various - * classes. Used by all the scala collections and case classes. + * An implementation of Austin Appleby's MurmurHash 3 algorithm + * (MurmurHash3_x86_32). This object contains methods that hash + * values of various types as well as means to construct `Hashing` + * objects. + * + * This algorithm is designed to generate well-distributed non-cryptographic + * hashes. It is designed to hash data in 32 bit chunks (ints). + * + * The mix method needs to be called at each step to update the intermediate + * hash value. For the last chunk to incorporate into the hash mixLast may + * be used instead, which is slightly faster. Finally finalizeHash needs to + * be called to compute the final hash value. + * + * This is based on the earlier MurmurHash3 code by Rex Kerr, but the + * MurmurHash3 algorithm was since changed by its creator Austin Appleby + * to remedy some weaknesses and improve performance. This represents the + * latest and supposedly final version of the algortihm (revision 136). + * + * @see [[http://code.google.com/p/smhasher]] */ object MurmurHash3 extends MurmurHash3 { final val arraySeed = 0x3c074a61 @@ -205,6 +203,32 @@ object MurmurHash3 extends MurmurHash3 { def mapHash(xs: collection.Map[_, _]): Int = unorderedHash(xs, mapSeed) def setHash(xs: collection.Set[_]): Int = unorderedHash(xs, setSeed) + class ArrayHashing[@specialized T] extends Hashing[Array[T]] { + def hash(a: Array[T]) = arrayHash(a) + } + + def arrayHashing[@specialized T] = new ArrayHashing[T] + + def bytesHashing = new Hashing[Array[Byte]] { + def hash(data: Array[Byte]) = bytesHash(data) + } + + def orderedHashing = new Hashing[TraversableOnce[Any]] { + def hash(xs: TraversableOnce[Any]) = orderedHash(xs) + } + + def productHashing = new Hashing[Product] { + def hash(x: Product) = productHash(x) + } + + def stringHashing = new Hashing[String] { + def hash(x: String) = stringHash(x) + } + + def unorderedHashing = new Hashing[TraversableOnce[Any]] { + def hash(xs: TraversableOnce[Any]) = unorderedHash(xs) + } + /** All this trouble and foreach still appears faster. * Leaving in place in case someone would like to investigate further. */ diff --git a/src/library/scala/util/hashing/package.scala b/src/library/scala/util/hashing/package.scala new file mode 100644 index 0000000000..becfa4911e --- /dev/null +++ b/src/library/scala/util/hashing/package.scala @@ -0,0 +1,35 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2011, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://www.scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +package scala.util + + + + + + +package object hashing { + + /** Fast multiplicative hash with a nice distribution. + */ + def byteswap32(v: Int): Int = { + var hc = v * 0x9e3775cd + hc = java.lang.Integer.reverseBytes(hc) + hc * 0x9e3775cd + } + + /** Fast multiplicative hash with a nice distribution + * for 64-bit values. + */ + def byteswap64(v: Long): Long = { + var hc = v * 0x9e3775cd9e3775cdL + hc = java.lang.Long.reverseBytes(hc) + hc * 0x9e3775cd9e3775cdL + } + +} diff --git a/src/library/scala/xml/Utility.scala b/src/library/scala/xml/Utility.scala index 17c91fa52c..bae529c85c 100755 --- a/src/library/scala/xml/Utility.scala +++ b/src/library/scala/xml/Utility.scala @@ -268,7 +268,7 @@ object Utility extends AnyRef with parsing.TokenTests { * Returns a hashcode for the given constituents of a node */ def hashCode(pre: String, label: String, attribHashCode: Int, scpeHash: Int, children: Seq[Node]) = - scala.util.MurmurHash3.orderedHash(label +: attribHashCode +: scpeHash +: children, pre.##) + scala.util.hashing.MurmurHash3.orderedHash(label +: attribHashCode +: scpeHash +: children, pre.##) def appendQuoted(s: String): String = sbToString(appendQuoted(s, _)) |