minor changes

git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@11100 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
michelou 2007-05-21 08:32:16 +00:00
parent 487396de68
commit 95efbab3ae
16 changed files with 193 additions and 168 deletions

View File

@ -1002,7 +1002,7 @@ GENERATES A DISTRIBUTION
regexp="([^-]*)(-.*)?" select="\1" regexp="([^-]*)(-.*)?" select="\1"
/> />
<echo level="verbose" message="OSGi version: ${osgi.version.number}"/> <echo level="verbose" message="OSGi version: ${osgi.version.number}"/>
<jar destfile="${dist.current.dir}/lib/${comp.jar.name}"> <jar destfile="${dist.current.dir}/lib/${comp.jar.name}" index="true">
<fileset dir="${strap.dir}/lib/compiler"/> <fileset dir="${strap.dir}/lib/compiler"/>
<zipfileset src="${fjbg.jar}"/> <zipfileset src="${fjbg.jar}"/>
<zipfileset src="${msil.jar}"/> <zipfileset src="${msil.jar}"/>
@ -1031,7 +1031,7 @@ GENERATES A DISTRIBUTION
<attribute name="Bundle-RequiredExecutionEnvironment" value="J2SE-1.4"/> <attribute name="Bundle-RequiredExecutionEnvironment" value="J2SE-1.4"/>
</manifest> </manifest>
</jar> </jar>
<jar destfile="${dist.current.dir}/lib/${lib.jar.name}"> <jar destfile="${dist.current.dir}/lib/${lib.jar.name}" index="true">
<fileset dir="${strap.dir}/lib/library"/> <fileset dir="${strap.dir}/lib/library"/>
<fileset dir="${strap.dir}/lib/actors"/> <fileset dir="${strap.dir}/lib/actors"/>
<manifest> <manifest>
@ -1058,7 +1058,7 @@ GENERATES A DISTRIBUTION
<attribute name="Bundle-RequiredExecutionEnvironment" value="J2SE-1.4"/> <attribute name="Bundle-RequiredExecutionEnvironment" value="J2SE-1.4"/>
</manifest> </manifest>
</jar> </jar>
<jar destfile="${dist.current.dir}/lib/${dbc.jar.name}"> <jar destfile="${dist.current.dir}/lib/${dbc.jar.name}" index="true">
<fileset dir="${strap.dir}/lib/dbc"/> <fileset dir="${strap.dir}/lib/dbc"/>
<manifest> <manifest>
<attribute name="Signature-Version" value="${version.number}"/> <attribute name="Signature-Version" value="${version.number}"/>

2
debian/copyright vendored
View File

@ -8,7 +8,7 @@ This package was originally assembled by Lex Spoon (lex@debian.org).
SCALA LICENSE SCALA LICENSE
Copyright (c) 2002-2006 EPFL, Lausanne, unless otherwise specified. Copyright (c) 2002-2007 EPFL, Lausanne, unless otherwise specified.
All rights reserved. All rights reserved.
This software was developed by the Programming Methods Laboratory of the This software was developed by the Programming Methods Laboratory of the

View File

@ -13,19 +13,20 @@ know which version of Java you have, run the command "java -version".
Scala Tools Scala Tools
----------- -----------
- fsc Scala offline compiler
- scalac Scala compiler - scalac Scala compiler
- scaladoc Scala API documentation generator - scaladoc Scala API documentation generator
- scalaint Scala interactive interpreter - scala Scala interactive interpreter
- scalap Scala classfile decoder - scalap Scala classfile decoder
Run the command "scalac -help" to display the list of available Run the command "scalac -help" to display the list of available
compiler options. compiler options.
Install on Unix Unix Installation
--------------- -----------------
Untar the archive. All Scala tools are located in the directory "bin". Untar the archive. All Scala tools are located in the "bin" directory.
Adding that directory to the PATH variable will make the Scala commands Adding that directory to the PATH variable will make the Scala commands
directly accessible. directly accessible.
@ -35,7 +36,7 @@ $ ./bin/scalac share/doc/scala/examples/sort.scala
$ ./bin/scala examples.sort $ ./bin/scala examples.sort
[6,2,8,5,1] [6,2,8,5,1]
[1,2,5,6,8] [1,2,5,6,8]
$ ./bin/scalaint $ ./bin/scala
scala> examples.sort.main(null) scala> examples.sort.main(null)
[6,2,8,5,1] [6,2,8,5,1]
[1,2,5,6,8] [1,2,5,6,8]
@ -43,8 +44,8 @@ scala>:quit
$ $
Install on Windows Windows Installation
------------------ --------------------
Unzip the archive. All Scala tools are located in the "bin" directory. Unzip the archive. All Scala tools are located in the "bin" directory.
Adding that directory to the PATH variable will make the Scala commands Adding that directory to the PATH variable will make the Scala commands
@ -55,7 +56,7 @@ to point to the home directory of the Scala distribution to run any of
these tools. This can be done by adding the following command to your these tools. This can be done by adding the following command to your
AUTOEXEC.BAT file and then rebooting your machine. AUTOEXEC.BAT file and then rebooting your machine.
set SCALA_HOME=<install-directory>\scala-YYYYMMDD-hhmmss set SCALA_HOME=<install-directory>\scala-<major>.<minor>.<patch>
On Windows NT/2000/XP, you do not need to define any variable in order On Windows NT/2000/XP, you do not need to define any variable in order
for the Scala commands to run correctly. for the Scala commands to run correctly.

View File

@ -41,7 +41,7 @@ abstract class Serializer(val service: Service) {
} }
@throws(classOf[IOException]) @throws(classOf[IOException])
def writeBytes(outputStream: DataOutputStream, bytes: Array[byte]): unit = { def writeBytes(outputStream: DataOutputStream, bytes: Array[byte]) {
val length = bytes.length; val length = bytes.length;
// original length // original length
outputStream.writeInt(length) outputStream.writeInt(length)
@ -50,7 +50,7 @@ abstract class Serializer(val service: Service) {
} }
@throws(classOf[IOException]) @throws(classOf[IOException])
def writeObject(outputStream: DataOutputStream, obj: AnyRef) = { def writeObject(outputStream: DataOutputStream, obj: AnyRef) {
val bytes = serialize(obj) val bytes = serialize(obj)
writeBytes(outputStream, bytes) writeBytes(outputStream, bytes)
} }

View File

@ -1,7 +1,7 @@
/* __ *\ /* __ *\
** ________ ___ / / ___ Scala API ** ** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2005-2006, LAMP/EPFL ** ** / __/ __// _ | / / / _ | (c) 2005-2007, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | ** ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | ** ** /____/\___/_/ |_/____/_/ | | **
** |/ ** ** |/ **
\* */ \* */
@ -10,6 +10,9 @@
package scala.actors.remote package scala.actors.remote
/**
* @author Philipp Haller
*/
trait Service { trait Service {
val kernel = new NetKernel(this) val kernel = new NetKernel(this)
val serializer: Serializer val serializer: Serializer

View File

@ -1,7 +1,7 @@
/* __ *\ /* __ *\
** ________ ___ / / ___ Scala API ** ** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2006, LAMP/EPFL ** ** / __/ __// _ | / / / _ | (c) 2002-2007, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | ** ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | ** ** /____/\___/_/ |_/____/_/ | | **
** |/ ** ** |/ **
\* */ \* */
@ -35,19 +35,20 @@ abstract class AbstractTimer {
def issue(message: String, duration: Long): Unit def issue(message: String, duration: Long): Unit
/** Starts a new timer. */ /** Starts a new timer. */
def start() = { def start() {
starts += currentTime starts += currentTime
} }
/** Ends the current timer. */ /** Ends the current timer. */
def stop(message: String): Unit = { def stop(message: String) {
val stop = currentTime val stop = currentTime
issue(message, stop - starts.pop) issue(message, stop - starts.pop)
} }
/** Drops the current timer. */ /** Drops the current timer. */
def drop(): Unit = def drop() {
starts.pop starts.pop
}
//######################################################################## //########################################################################
} }

View File

@ -1,12 +1,12 @@
/* __ *\ /* __ *\
** ________ ___ / / ___ Scala API ** ** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2006, LAMP/EPFL ** ** / __/ __// _ | / / / _ | (c) 2002-2007, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | ** ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | ** ** /____/\___/_/ |_/____/_/ | | **
** |/ ** ** |/ **
\* */ \* */
// $id: $ // $Id$
package scala.tools.util package scala.tools.util
@ -45,7 +45,7 @@ class SocketConnection(hostname: String, port: Int) {
} }
} }
def close() = { def close() {
in.close() in.close()
out.close() out.close()
socket.close() socket.close()

View File

@ -1,7 +1,7 @@
/* __ *\ /* __ *\
** ________ ___ / / ___ Scala API ** ** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2006, LAMP/EPFL ** ** / __/ __// _ | / / / _ | (c) 2002-2007, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | ** ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | ** ** /____/\___/_/ |_/____/_/ | | **
** |/ ** ** |/ **
\* */ \* */
@ -46,7 +46,7 @@ abstract class SocketServer {
fatal("Could not listen on any port; exiting.") fatal("Could not listen on any port; exiting.")
} }
def run(): unit = def run() {
while (!shutDown) { while (!shutDown) {
val serverSocket = try { val serverSocket = try {
new ServerSocket(port) new ServerSocket(port)
@ -75,6 +75,7 @@ abstract class SocketServer {
clientSocket.close() clientSocket.close()
serverSocket.close() serverSocket.close()
} }
}
} }

View File

@ -1,7 +1,7 @@
/* __ *\ /* __ *\
** ________ ___ / / ___ Scala API ** ** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2006, LAMP/EPFL ** ** / __/ __// _ | / / / _ | (c) 2002-2007, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | ** ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | ** ** /____/\___/_/ |_/____/_/ | | **
** |/ ** ** |/ **
\* */ \* */

View File

@ -1,7 +1,7 @@
/* __ *\ /* __ *\
** ________ ___ / / ___ Scala API ** ** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2006, LAMP/EPFL ** ** / __/ __// _ | / / / _ | (c) 2002-2007, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | ** ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | ** ** /____/\___/_/ |_/____/_/ | | **
** |/ ** ** |/ **
\* */ \* */
@ -23,20 +23,20 @@ object UTF8Codec {
val end = from + len val end = from + len
while (i < end) { while (i < end) {
val ch = src(i) val ch = src(i)
i = i + 1 i += 1
if (ch < 128) { if (ch < 128) {
dst(j) = ch.toByte dst(j) = ch.toByte
j = j + 1 j += 1
} }
else if (ch <= 0x3FF) { else if (ch <= 0x3FF) {
dst(j) = (0xC0 | (ch >> 6)).toByte dst(j) = (0xC0 | (ch >> 6)).toByte
dst(j+1) = (0x80 | (ch & 0x3F)).toByte dst(j+1) = (0x80 | (ch & 0x3F)).toByte
j = j + 2 j += 2
} else { } else {
dst(j) = (0xE0 | (ch >> 12)).toByte dst(j) = (0xE0 | (ch >> 12)).toByte
dst(j+1) = (0x80 | ((ch >> 6) & 0x3F)).toByte dst(j+1) = (0x80 | ((ch >> 6) & 0x3F)).toByte
dst(j+2) = (0x80 | (ch & 0x3F)).toByte dst(j+2) = (0x80 | (ch & 0x3F)).toByte
j = j + 3 j += 3
} }
} }
j j
@ -45,7 +45,6 @@ object UTF8Codec {
def encode(s: String, dst: Array[Byte], to: Int): Int = def encode(s: String, dst: Array[Byte], to: Int): Int =
encode(s.toCharArray(), 0, dst, to, s.length()) encode(s.toCharArray(), 0, dst, to, s.length())
def encode(s: String): Array[Byte] = { def encode(s: String): Array[Byte] = {
val dst = new Array[Byte](s.length() * 3) val dst = new Array[Byte](s.length() * 3)
val len = encode(s, dst, 0) val len = encode(s, dst, 0)
@ -60,17 +59,17 @@ object UTF8Codec {
val end = from + len val end = from + len
while (i < end) { while (i < end) {
var b = src(i) & 0xFF var b = src(i) & 0xFF
i = i + 1 i += 1
if (b >= 0xE0) { if (b >= 0xE0) {
b = ((b & 0x0F) << 12) | (src(i) & 0x3F) << 6 b = ((b & 0x0F) << 12) | (src(i) & 0x3F) << 6
b = b | (src(i+1) & 0x3F) b = b | (src(i+1) & 0x3F)
i = i + 2 i += 2
} else if (b >= 0xC0) { } else if (b >= 0xC0) {
b = ((b & 0x1F) << 6) | (src(i) & 0x3F) b = ((b & 0x1F) << 6) | (src(i) & 0x3F)
i = i + 1 i += 1
} }
dst(j) = b.toChar dst(j) = b.toChar
j = j + 1 j += 1
} }
j j
} }

View File

@ -14,17 +14,17 @@ package scala.testing
import compat.Platform import compat.Platform
/** <code>Benchmark</code> can be used to quickly turn an existing /** <p>
* class into a benchmark. Here is a short example: * <code>Benchmark</code> can be used to quickly turn an existing
* * class into a benchmark. Here is a short example:
* <pre> * </p><pre>
* <b>object</b> sort1 <b>extends</b> Sorter <b>with</b> Benchmark { * <b>object</b> sort1 <b>extends</b> Sorter <b>with</b> Benchmark {
* <b>def</b> run = sort(List.range(1, 1000)) * <b>def</b> run = sort(List.range(1, 1000))
* } * }
* </pre> * </pre>
* <p> * <p>
* The run method has to be defined by the user, who will perform * The <code>run</code> method has to be defined by the user, who
* the timed operation there. * will perform the timed operation there.
* Run the benchmark as follows: * Run the benchmark as follows:
* </p> * </p>
* <pre> * <pre>
@ -34,6 +34,8 @@ import compat.Platform
* This will run the benchmark 5 times and log the execution times in * This will run the benchmark 5 times and log the execution times in
* a file called <code>times.log</code> * a file called <code>times.log</code>
* </p> * </p>
*
* @author Burak Emir
*/ */
trait Benchmark { trait Benchmark {
@ -67,7 +69,7 @@ trait Benchmark {
* consecutive runs, and the name of a log file where to * consecutive runs, and the name of a log file where to
* append the times. * append the times.
*/ */
def main(args: Array[String]): Unit = { def main(args: Array[String]) {
if (args.length > 1) { if (args.length > 1) {
val logFile = new java.io.FileWriter(args(1), true) // append, not overwrite val logFile = new java.io.FileWriter(args(1), true) // append, not overwrite
if (args.length >= 3) if (args.length >= 3)

View File

@ -39,26 +39,31 @@ import scala.collection.mutable.ArrayBuffer
* Console.println(tf.toString()) * Console.println(tf.toString())
* } * }
* </pre> * </pre>
* <p>
* The trait <code>TestConsoleMain</code> contains this code as
* a <code>main</code> method, for convenience.
* </p>
* *
* The trait TestConsoleMain contains this code as a main method, for convenience. * @author Burak Emir
*/ */
object SUnit { object SUnit {
/** convenience trait, mix it in a TestMain object and implement "suite" to get this code /** convenience trait, mix it in a TestMain object and implement "suite" to get this code
* <b>val</b> r = <b>new</b> TestResult() * <b>val</b> r = <b>new</b> TestResult()
* suite.run(r) * suite.run(r)
* <b>for</b> (<b>val</b> tf &lt;- r.failures()) { * <b>for</b> (<b>val</b> tf &lt;- r.failures()) {
* Console.println(tf.toString()) * Console.println(tf.toString())
*/ */
trait TestConsoleMain { trait TestConsoleMain {
def suite: TestSuite def suite: TestSuite
def main(args:Array[String]) { def main(args: Array[String]) {
val r = new TestResult() val r = new TestResult()
suite.run(r) suite.run(r)
for (tf <- r.failures()) for (tf <- r.failures())
Console.println(tf.toString()) Console.println(tf.toString())
} }
} }
/** a Test can be run with its result being collected */ /** a Test can be run with its result being collected */
trait Test { trait Test {
def run(r: TestResult): Unit def run(r: TestResult): Unit
@ -165,21 +170,23 @@ object SUnit {
assertNotNull("(no message)", actual) assertNotNull("(no message)", actual)
/** /**
* @deprecated use assertNotEq instead * @deprecated use assertNotEq instead
*/ */
@deprecated def assertNotSame(msg: String, expected: => AnyRef, actual: => AnyRef): Unit = @deprecated
def assertNotSame(msg: String, expected: => AnyRef, actual: => AnyRef): Unit =
if (expected.eq(actual)) fail(msg) if (expected.eq(actual)) fail(msg)
/** /**
* @deprecated use assertNotEq instead * @deprecated use assertNotEq instead
*/ */
@deprecated def assertNotSame(expected: => AnyRef, actual: => AnyRef): Unit = @deprecated
def assertNotSame(expected: => AnyRef, actual: => AnyRef): Unit =
assertNotEq("(no message)", expected, actual) assertNotEq("(no message)", expected, actual)
/** fail if expected eq actual */ /** fail if expected eq actual */
def assertNotEq(msg: String, expected: => AnyRef, actual: => AnyRef) { def assertNotEq(msg: String, expected: => AnyRef, actual: => AnyRef) {
if (expected eq actual) fail(msg) if (expected eq actual) fail(msg)
} }
/** fail if expected eq actual */ /** fail if expected eq actual */
def assertNotEq(expected: => AnyRef, actual: => AnyRef) { def assertNotEq(expected: => AnyRef, actual: => AnyRef) {
@ -195,14 +202,16 @@ object SUnit {
assertNull("(no message)", actual) assertNull("(no message)", actual)
/** /**
* @deprecated use assertEq instead * @deprecated use assertEq instead
*/ */
@deprecated
def assertSame(msg: String, expected: => AnyRef, actual: => AnyRef): Unit = def assertSame(msg: String, expected: => AnyRef, actual: => AnyRef): Unit =
if(!expected.eq(actual)) fail(msg) if(!expected.eq(actual)) fail(msg)
/** /**
* @deprecated use assertEq instead * @deprecated use assertEq instead
*/ */
@deprecated
def assertSame(expected: => AnyRef, actual: => AnyRef): Unit = def assertSame(expected: => AnyRef, actual: => AnyRef): Unit =
assertEq("(no message)", expected, actual) assertEq("(no message)", expected, actual)

View File

@ -1,7 +1,7 @@
/* __ *\ /* __ *\
** ________ ___ / / ___ Scala API ** ** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2006, LAMP/EPFL ** ** / __/ __// _ | / / / _ | (c) 2003-2007, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | ** ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | ** ** /____/\___/_/ |_/____/_/ | | **
** |/ ** ** |/ **
\* */ \* */
@ -11,19 +11,23 @@
package scala.testing package scala.testing
/** /**
* Some simple methods to support unit testing with assertions * Some simple methods to support unit testing with assertions
* to contain more JUnit style assertions which use Scala's features. * to contain more JUnit style assertions which use Scala's features.
* @deprecated use SUnit instead *
* @author Burak Emir
*
* @deprecated use <a href="SUnit.html" target="contentFrame">SUnit</a>
* instead.
*/ */
@deprecated @deprecated
object UnitTest { object UnitTest {
class Report(report_ok: () => Unit, report_fail: (String,String) => Unit) { class Report(report_ok: () => Unit, report_fail: (String,String) => Unit) {
def ok(): Unit = report_ok() def ok(): Unit = report_ok()
def fail(actual: String, expected: String): Unit = def fail(actual: String, expected: String) {
report_fail(actual, expected) report_fail(actual, expected)
}
} }
var report = new Report( var report = new Report(
@ -36,7 +40,7 @@ object UnitTest {
/** /**
* @param r ... * @param r ...
*/ */
def setReporter(r: Report) = { def setReporter(r: Report) {
this.report = r this.report = r
} }

View File

@ -1,7 +1,7 @@
/* __ *\ /* __ *\
** ________ ___ / / ___ Scala API ** ** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2006, LAMP/EPFL ** ** / __/ __// _ | / / / _ | (c) 2003-2007, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | ** ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | ** ** /____/\___/_/ |_/____/_/ | | **
** |/ ** ** |/ **
\* */ \* */
@ -36,14 +36,14 @@ abstract class Document {
def :/:(hd: String): Document = hd :: DocBreak :: this def :/:(hd: String): Document = hd :: DocBreak :: this
/** /**
* Format this document on WRITER and try to set line breaks so that * Format this document on <code>writer</code> and try to set line
* the result fits in WIDTH columns. * breaks so that the result fits in <code>width</code> columns.
* *
* @param width ... * @param width ...
* @param writer ... * @param writer ...
*/ */
def format(width: Int, writer: Writer): Unit = { def format(width: Int, writer: Writer) {
type FmtState = (Int,Boolean,Document) type FmtState = (Int, Boolean, Document)
def fits(w: Int, state: List[FmtState]): boolean = state match { def fits(w: Int, state: List[FmtState]): boolean = state match {
case _ if w < 0 => case _ if w < 0 =>
@ -66,12 +66,12 @@ abstract class Document {
fits(w, (i, false, d) :: z) fits(w, (i, false, d) :: z)
} }
def spaces(n: Int): Unit = { def spaces(n: Int) {
var rem = n var rem = n
while (rem >= 16) { writer write " "; rem = rem - 16 } while (rem >= 16) { writer write " "; rem -= 16 }
if (rem >= 8) { writer write " "; rem = rem - 8 } if (rem >= 8) { writer write " "; rem -= 8 }
if (rem >= 4) { writer write " "; rem = rem - 4 } if (rem >= 4) { writer write " "; rem -= 4 }
if (rem >= 2) { writer write " "; rem = rem - 2} if (rem >= 2) { writer write " "; rem -= 2}
if (rem == 1) { writer write " " } if (rem == 1) { writer write " " }
} }

View File

@ -1,7 +1,7 @@
/* __ *\ /* __ *\
** ________ ___ / / ___ Scala API ** ** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2006, LAMP/EPFL ** ** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | ** ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | ** ** /____/\___/_/ |_/____/_/ | | **
** |/ ** ** |/ **
\* */ \* */
@ -15,37 +15,42 @@ package scala.util
import Predef._ import Predef._
import java.lang.InheritableThreadLocal import java.lang.InheritableThreadLocal
/** Fluids provide a binding mechanism where the current /** <p>
* value is found through <em>dynamic scope</em>, but where * Fluids provide a binding mechanism where the current
* access to the fluid itself is resolved through </em>static * value is found through <em>dynamic scope</em>, but where
* binding</em> to a variable referencing the fluid. * access to the fluid itself is resolved through </em>static
* * binding</em> to a variable referencing the fluid.
* The current value can be retrieved with the * </p>
* <code>value</code> method. New values can be * <p>
* pushed using the <code>withValue</code> method. * The current value can be retrieved with the
* Values pushed via <code>withValue</code> only * <code>value</code> method. New values can be
* stay valid while the <code>withValue</code>'s * pushed using the <code>withValue</code> method.
* <em>second</em> argument, a parameterless closure, * Values pushed via <code>withValue</code> only
* executes. When the second argument finishes, * stay valid while the <code>withValue</code>'s
* the fluid reverts to the previous value. * <em>second</em> argument, a parameterless closure,
* * executes. When the second argument finishes,
* Usage of <code>withValue</code> looks like this: * the fluid reverts to the previous value.
* <blockquote><pre> * </p>
* someFluid.withValue(newValue) { * <p>
* // ... code called in here that calls value ... * Usage of <code>withValue</code> looks like this:
* // ... will be given back the newValue ... * </p>
* } * <blockquote><pre>
* </pre></blockquote> * someFluid.withValue(newValue) {
* * // ... code called in here that calls value ...
* Each thread gets its own stack of bindings. When a * // ... will be given back the newValue ...
* new thread is created, the fluid gets a copy of * }
* the stack of bindings from the parent thread, and * </pre></blockquote>
* from then on the bindings for the new thread * <p>
* are independent of those for the original thread. * Each thread gets its own stack of bindings. When a
* * new thread is created, the fluid gets a copy of
* @author Lex Spoon * the stack of bindings from the parent thread, and
* @version 1.0, 21/03/2006 * from then on the bindings for the new thread
*/ * are independent of those for the original thread.
* </p>
*
* @author Lex Spoon
* @version 1.0, 21/03/2006
*/
class Fluid[T](init: T) { class Fluid[T](init: T) {
private val tl = new InheritableThreadLocal { private val tl = new InheritableThreadLocal {
override def initialValue = init.asInstanceOf[AnyRef] override def initialValue = init.asInstanceOf[AnyRef]
@ -71,7 +76,7 @@ class Fluid[T](init: T) {
} }
/** Change the currently bound value, discarding the old value. /** Change the currently bound value, discarding the old value.
* Usually withValue() gives better semantics. * Usually <code>withValue()</code> gives better semantics.
*/ */
def value_=(newval: T) = { tl.set(newval) } def value_=(newval: T) = { tl.set(newval) }

View File

@ -1,7 +1,7 @@
/* __ *\ /* __ *\
** ________ ___ / / ___ Scala API ** ** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2006-2007, Ross Judson ** ** / __/ __// _ | / / / _ | (c) 2006-2007, Ross Judson **
** __\ \/ /__/ __ |/ /__/ __ | ** ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | ** ** /____/\___/_/ |_/____/_/ | | **
** |/ ** ** |/ **
\* */ \* */
@ -99,9 +99,9 @@ object Sorting {
var i = 0 var i = 0
while (i < n) { while (i < n) {
swap(a, b) swap(a, b)
i = i + 1 i += 1
a = a + 1 a += 1
b = b + 1 b += 1
} }
} }
def med3(a: Int, b: Int, c: Int) = { def med3(a: Int, b: Int, c: Int) = {
@ -118,9 +118,9 @@ object Sorting {
var j = i var j = i
while (j > off && x(j-1) > x(j)) { while (j > off && x(j-1) > x(j)) {
swap(j, j-1) swap(j, j-1)
j = j - 1 j -= 1
} }
i = i + 1 i += 1
} }
} else { } else {
// Choose a partition element, v // Choose a partition element, v
@ -142,29 +142,29 @@ object Sorting {
var a = off var a = off
var b = a var b = a
var c = off + len - 1 var c = off + len - 1
var d = c; var d = c
var done = false var done = false
while(!done) { while(!done) {
while (b <= c && x(b) <= v) { while (b <= c && x(b) <= v) {
if (x(b) == v) { if (x(b) == v) {
swap(a, b) swap(a, b)
a = a + 1 a += 1
} }
b = b + 1 b += 1
} }
while (c >= b && x(c) >= v) { while (c >= b && x(c) >= v) {
if (x(c) == v) { if (x(c) == v) {
swap(c, d) swap(c, d)
d = d - 1 d -= 1
} }
c = c - 1 c -= 1
} }
if (b > c) { if (b > c) {
done = true done = true
} else { } else {
swap(b, c) swap(b, c)
c = c - 1 c -= 1
b = b + 1 b += 1
} }
} }
@ -196,10 +196,10 @@ object Sorting {
var b = _b var b = _b
var i = 0 var i = 0
while (i < n) { while (i < n) {
swap(a,b) swap(a, b)
i = i + 1 i += 1
a = a + 1 a += 1
b = b + 1 b += 1
} }
} }
def med3(a: Int, b: Int, c: Int) = { def med3(a: Int, b: Int, c: Int) = {
@ -216,9 +216,9 @@ object Sorting {
var j = i var j = i
while (j > off && x(j-1) > x(j)) { while (j > off && x(j-1) > x(j)) {
swap(j, j-1) swap(j, j-1)
j = j - 1 j -= 1
} }
i = i + 1 i += 1
} }
} else { } else {
// Choose a partition element, v // Choose a partition element, v
@ -246,28 +246,28 @@ object Sorting {
while (b <= c && x(b) <= v) { while (b <= c && x(b) <= v) {
if (x(b) == v) { if (x(b) == v) {
swap(a, b) swap(a, b)
a = a + 1 a += 1
} }
b = b + 1 b += 1
} }
while (c >= b && x(c) >= v) { while (c >= b && x(c) >= v) {
if (x(c) == v) { if (x(c) == v) {
swap(c, d) swap(c, d)
d = d - 1 d -= 1
} }
c = c - 1 c -= 1
} }
if (b > c) { if (b > c) {
done = true done = true
} else { } else {
swap(b, c) swap(b, c)
c = c - 1 c -= 1
b = b + 1 b += 1
} }
} }
// Swap partition elements back to middle // Swap partition elements back to middle
val n = off + len; val n = off + len
var s = Math.min(a-off, b-a) var s = Math.min(a-off, b-a)
vecswap(off, b-s, s) vecswap(off, b-s, s)
s = Math.min(d-c, n-d-1) s = Math.min(d-c, n-d-1)
@ -295,9 +295,9 @@ object Sorting {
var i = 0 var i = 0
while (i < n) { while (i < n) {
swap(a, b) swap(a, b)
i = i + 1 i += 1
a = a + 1 a += 1
b = b + 1 b += 1
} }
} }
def med3(a: Int, b: Int, c: Int) = def med3(a: Int, b: Int, c: Int) =
@ -313,10 +313,10 @@ object Sorting {
while (i < len + off) { while (i < len + off) {
var j = i var j = i
while (j>off && x(j-1)>x(j)) { while (j>off && x(j-1)>x(j)) {
swap(j,j-1) swap(j, j-1)
j = j - 1 j -= 1
} }
i = i + 1 i += 1
} }
} else { } else {
// Choose a partition element, v // Choose a partition element, v
@ -344,23 +344,23 @@ object Sorting {
while (b <= c && x(b) <= v) { while (b <= c && x(b) <= v) {
if (x(b) == v) { if (x(b) == v) {
swap(a, b) swap(a, b)
a = a + 1 a += 1
} }
b = b + 1 b += 1
} }
while (c >= b && x(c) >= v) { while (c >= b && x(c) >= v) {
if (x(c) == v) { if (x(c) == v) {
swap(c, d) swap(c, d)
d = d - 1 d -= 1
} }
c = c - 1 c -= 1
} }
if (b > c) { if (b > c) {
done = true done = true
} else { } else {
swap(b, c) swap(b, c)
c = c - 1 c -= 1
b = b + 1 b += 1
} }
} }
@ -392,10 +392,10 @@ object Sorting {
var b = _b var b = _b
var i = 0 var i = 0
while (i < n) { while (i < n) {
swap(a,b) swap(a, b)
i = i + 1 i += 1
a = a + 1 a += 1
b = b + 1 b += 1
} }
} }
def med3(a: Int, b: Int, c: Int) = def med3(a: Int, b: Int, c: Int) =
@ -412,9 +412,9 @@ object Sorting {
var j = i var j = i
while (j > off && x(j-1) > x(j)) { while (j > off && x(j-1) > x(j)) {
swap(j, j-1) swap(j, j-1)
j = j - 1 j -= 1
} }
i = i + 1 i += 1
} }
} else { } else {
// Choose a partition element, v // Choose a partition element, v
@ -442,23 +442,23 @@ object Sorting {
while (b <= c && x(b) <= v) { while (b <= c && x(b) <= v) {
if (x(b) == v) { if (x(b) == v) {
swap(a, b) swap(a, b)
a = a + 1 a += 1
} }
b = b + 1 b += 1
} }
while (c >= b && x(c) >= v) { while (c >= b && x(c) >= v) {
if (x(c) == v) { if (x(c) == v) {
swap(c, d) swap(c, d)
d = d - 1 d -= 1
} }
c = c - 1 c -= 1
} }
if (b > c) { if (b > c) {
done = true done = true
} else { } else {
swap(b, c) swap(b, c)
c = c - 1 c -= 1
b = b + 1 b += 1
} }
} }
@ -489,17 +489,17 @@ object Sorting {
while (k <= hi) { while (k <= hi) {
if ((t_lo <= mid) && ((t_hi > hi) || (f(a(t_lo), a(t_hi))))) { if ((t_lo <= mid) && ((t_hi > hi) || (f(a(t_lo), a(t_hi))))) {
scratch(k) = a(t_lo) scratch(k) = a(t_lo)
t_lo = t_lo + 1 t_lo += 1
} else { } else {
scratch(k) = a(t_hi) scratch(k) = a(t_hi)
t_hi = t_hi + 1 t_hi += 1
} }
k = k + 1 k += 1
} }
k = lo k = lo
while (k <= hi) { while (k <= hi) {
a(k) = scratch(k) a(k) = scratch(k)
k = k + 1 k += 1
} }
} }
} }