summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-08-29 19:05:10 +0000
committerPaul Phillips <paulp@improving.org>2009-08-29 19:05:10 +0000
commit1d19903447d0044ed843d81e9d70c9e37c4e7ceb (patch)
tree5f86191692891abc607218f554f0f6589c0a193f
parent463be6731fcab426eeed0ce693fc4a2898f6d5e0 (diff)
downloadscala-1d19903447d0044ed843d81e9d70c9e37c4e7ceb.tar.gz
scala-1d19903447d0044ed843d81e9d70c9e37c4e7ceb.tar.bz2
scala-1d19903447d0044ed843d81e9d70c9e37c4e7ceb.zip
A few cleanups, and toXXX methods for BigDecima...
A few cleanups, and toXXX methods for BigDecimal and BigInteger so all the numeric types have the same conversion methods.
-rw-r--r--src/library/scala/BigDecimal.scala36
-rw-r--r--src/library/scala/BigInt.scala2
-rw-r--r--src/library/scala/collection/interfaces/TraversableMethods.scala2
-rw-r--r--src/library/scala/io/Process.scala6
4 files changed, 35 insertions, 11 deletions
diff --git a/src/library/scala/BigDecimal.scala b/src/library/scala/BigDecimal.scala
index ae008cce38..31413f5b1c 100644
--- a/src/library/scala/BigDecimal.scala
+++ b/src/library/scala/BigDecimal.scala
@@ -10,8 +10,21 @@
package scala
-import java.math.{BigDecimal => BigDec}
-import java.math.MathContext
+import java.{ lang => jl }
+import java.math.{ MathContext, BigDecimal => BigDec }
+
+/** Conversions which present a consistent conversion interface
+ * across all the numeric types.
+ */
+trait ScalaNumericConversions extends jl.Number {
+ def toChar = intValue.toChar
+ def toByte = byteValue
+ def toShort = shortValue
+ def toInt = intValue
+ def toLong = longValue
+ def toFloat = floatValue
+ def toDouble = doubleValue
+}
/**
* @author Stephane Micheloud
@@ -83,7 +96,7 @@ object BigDecimal
// note we don't use the static valueOf because it doesn't let us supply
// a MathContext, but we should be duplicating its logic, modulo caching.
def apply(d: Double, mc: MathContext): BigDecimal =
- new BigDecimal(new BigDec(java.lang.Double.toString(d), mc), mc)
+ new BigDecimal(new BigDec(jl.Double.toString(d), mc), mc)
/** Translates a character array representation of a <code>BigDecimal</code>
* into a <code>BigDecimal</code>.
@@ -156,7 +169,7 @@ object BigDecimal
class BigDecimal(
val bigDecimal: BigDec,
val mc: MathContext)
-extends java.lang.Number
+extends jl.Number with ScalaNumericConversions
{
def this(bigDecimal: BigDec) = this(bigDecimal, BigDecimal.defaultMathContext)
import BigDecimal.RoundingMode._
@@ -164,7 +177,12 @@ extends java.lang.Number
/** Cuts way down on the wrapper noise. */
private implicit def bigdec2BigDecimal(x: BigDec): BigDecimal = new BigDecimal(x, mc)
- /** Returns the hash code for this BigDecimal. */
+ /** Returns the hash code for this BigDecimal.
+ * Note that this does not use the underlying java object's
+ * hashCode because we compare BigDecimals with compareTo
+ * which deems 2 == 2.00, whereas in java these are unequal
+ * with unequal hashCodes.
+ */
override def hashCode(): Int = doubleValue.hashCode()
/** Compares this BigDecimal with the specified value for equality.
@@ -341,10 +359,10 @@ extends java.lang.Number
/** This BigDecimal as an exact value.
*/
- def byteValueExact: Byte = bigDecimal.byteValueExact
- def shortValueExact: Short = bigDecimal.shortValueExact
- def intValueExact: Int = bigDecimal.intValueExact
- def longValueExact: Long = bigDecimal.longValueExact
+ def toByteExact = bigDecimal.byteValueExact
+ def toShortExact = bigDecimal.shortValueExact
+ def toIntExact = bigDecimal.intValueExact
+ def toLongExact = bigDecimal.longValueExact
/** Creates a partially constructed GenericRange[BigDecimal] in range
* <code>[start;end)</code>, where start is the target BigDecimal. The step
diff --git a/src/library/scala/BigInt.scala b/src/library/scala/BigInt.scala
index b525fa731b..dd84371123 100644
--- a/src/library/scala/BigInt.scala
+++ b/src/library/scala/BigInt.scala
@@ -110,7 +110,7 @@ object BigInt {
* @version 1.0, 15/07/2003
*/
@serializable
-class BigInt(val bigInteger: BigInteger) extends jl.Number
+class BigInt(val bigInteger: BigInteger) extends jl.Number with ScalaNumericConversions
{
/** Returns the hash code for this BigInt. */
override def hashCode(): Int = this.bigInteger.hashCode()
diff --git a/src/library/scala/collection/interfaces/TraversableMethods.scala b/src/library/scala/collection/interfaces/TraversableMethods.scala
index b0df866c9c..7558be8305 100644
--- a/src/library/scala/collection/interfaces/TraversableMethods.scala
+++ b/src/library/scala/collection/interfaces/TraversableMethods.scala
@@ -33,7 +33,9 @@ trait TraversableMethods[+A, +This <: TraversableTemplate[A, This] with Traversa
def toIterable: Iterable[A]
def toList: List[A]
def toSequence: Sequence[A]
+ def toSet[B >: A]: immutable.Set[B]
def toStream: Stream[A]
+ def toVector[B >: A]: mutable.Vector[B]
// strings
def addString(b: StringBuilder): StringBuilder
diff --git a/src/library/scala/io/Process.scala b/src/library/scala/io/Process.scala
index 2e803aeff6..28209648f2 100644
--- a/src/library/scala/io/Process.scala
+++ b/src/library/scala/io/Process.scala
@@ -27,7 +27,10 @@ import java.util.concurrent.LinkedBlockingQueue
* See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4109888
* for a dated list of the many obstacles to a clean interface.
*
-|* This is not finished!! Do not rely upon it yet.
+ * This is not finished!! Do not rely upon it yet.
+ *
+ * TODO - remove requirement that process complete before we
+ * can get an iterator.
*
* @author Paul Phillips
* @since 2.8
@@ -36,6 +39,7 @@ import java.util.concurrent.LinkedBlockingQueue
@experimental
object Process
{
+ lazy val javaVmArguments = java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments()
lazy val runtime = Runtime.getRuntime()
@experimental