removing msil from trunk. everything related to .net is in branches/msil

git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@18976 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
rytz 2009-10-08 14:46:15 +00:00
parent 4143009857
commit d99726ea5a
210 changed files with 3 additions and 5754 deletions

View File

@ -274,7 +274,7 @@ LOCAL REFERENCE BUILD (LOCKER)
</javac>
<!-- NOTE: Potential problem with maximal command line length on Windows
(32768 characters for XP, since executed with Java's "exec"). See
src/build/msil.xml for more details. -->
src/build/msil.xml in msil branch for more details. -->
<scalacfork
destdir="${build-locker.dir}/classes/library"
compilerpathref="starr.classpath"
@ -1560,24 +1560,6 @@ FORWARDED TARGETS FOR JVM 1.5 BUILD
</target>
-->
<!-- ===========================================================================
FORWARDED TARGETS FOR MSIL BUILD
============================================================================ -->
<target name="msil" depends="pack.done">
<ant antfile="${src.dir}/build/msil.xml" target="msil-pack.done" inheritall="yes" inheritrefs="yes"/>
</target>
<target name="msiltest"/>
<target name="msildist" depends="pack.done">
<ant antfile="${src.dir}/build/msil.xml" target="msil-all.done" inheritall="yes" inheritrefs="yes"/>
</target>
<target name="msilclean">
<ant antfile="${src.dir}/build/msil.xml" target="msil-all.clean" inheritall="yes" inheritrefs="yes"/>
</target>
<!-- ===========================================================================
FORWARDED TARGETS FOR PACKAGING
============================================================================ -->
@ -1586,14 +1568,9 @@ FORWARDED TARGETS FOR PACKAGING
<ant antfile="${src.dir}/build/pack.xml" target="pack-all.done" inheritall="yes" inheritrefs="yes"/>
</target>
<target name="msildistpack" depends="pack.done">
<ant antfile="${src.dir}/build/msil.xml" target="msil-dist.done" inheritall="yes" inheritrefs="yes"/>
<ant antfile="${src.dir}/build/pack.xml" target="msilpack-all.done" inheritall="yes" inheritrefs="yes"/>
</target>
<!-- Used by the scala-installer script -->
<target name="alldistpack" depends="distpack, msildistpack"/>
<target name="allallclean" depends="all.clean, msilclean"/>
<target name="alldistpack" depends="distpack"/>
<target name="allallclean" depends="all.clean"/>
<!-- ===========================================================================
FORWARDED TARGETS FOR NIGHTLY BUILDS
@ -1611,11 +1588,6 @@ FORWARDED TARGETS FOR NIGHTLY BUILDS
<ant antfile="${src.dir}/build/pack.xml" target="pack-all.done" inheritall="yes" inheritrefs="yes"/>
</target>
<target name="msilnightly" depends="pack.done">
<ant antfile="${src.dir}/build/msil.xml" target="msil-all.done" inheritall="yes" inheritrefs="yes"/>
<ant antfile="${src.dir}/build/pack.xml" target="msilpack-all.done" inheritall="yes" inheritrefs="yes"/>
</target>
<!-- ===========================================================================
POSITIONS
============================================================================ -->

View File

@ -1,4 +0,0 @@
unix.mono.home=/home/linuxsoft/apps/mono
win.mono.home=C:/Progra~1/Mono
dotnet.home=C:/Windows/Micros~1.NET/Framew~1/v2.0.50727

View File

@ -1,316 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="sabbus-msil">
<description>
SuperSabbus extension for the MSIL library targeted for the dotnet framework. THIS FILE IS NOT STAND-ALONE AND SHOULD ONLY BE USED THROUGH ENTRY POINTS IN SUPERSABBUS.
</description>
<!-- TODO: test / make it work on Windows (use <ilasm/> task) -->
<!-- TODO: for separate compilation: make sure only files that have been changed
since last run are re-compiled -->
<!-- TODO: run test suite (or at least a part of it) on .NET -->
<!-- TODO: generate scaladoc of .NET library -->
<!-- TODO: (?) generate the runner scripts with scala.tools.ant.ScalaTool -->
<!-- ===========================================================================
PROPERTIES
============================================================================ -->
<!-- contains the scala-net / scalac-net commands -->
<property name="src-mono.dir" value="${src.dir}/mono"/>
<!-- Loads custom properties definitions -->
<property file="${src.dir}/build/msil.properties"/>
<!-- Sets location of build folders -->
<property name="build-msil.dir" value="${build.dir}/msil"/>
<property name="build-msil-src.dir" value="${build.dir}/msil-src"/>
<property name="build-msil-pack.dir" value="${build.dir}/msil-pack"/>
<!-- ===========================================================================
INITIALISATION
============================================================================ -->
<target name="msil.init">
<!-- define the "ilasm" task (and others). they are in fact already there from
antlib.xml, but in a deprecated version. -->
<!-- <taskdef resource="org/apache/ant/dotnet/antlib.xml"
classpath="${lib-ant.dir}/ant-dotnet-1.0.jar"/> -->
<!-- Sets ilasm command. Search in
- dotnet.home/ilasm.exe
- unix.mono.home/ilasm
- win.mono.home/lib/mono/2.0/ilasm.exe
- path
(the ".home"s can be set in msil.properties) -->
<condition property="ilasm.cmd" value="${dotnet.home}/ilasm.exe">
<and>
<os family="windows"/><isset property="dotnet.home"/>
<available file="${dotnet.home}/ilasm.exe"/>
</and>
</condition>
<condition property="ilasm.cmd" value="${unix.mono.home}/ilasm">
<and>
<os family="unix"/><isset property="unix.mono.home"/>
<available file="${unix.mono.home}/ilasm"/>
</and>
</condition>
<condition property="ilasm.cmd" value="${win.mono.home}/ilasm">
<and>
<os family="windows"/><isset property="win.mono.home"/>
<available file="${win.mono.home}/lib/mono/2.0/ilasm.exe"/>
</and>
</condition>
<condition property="ilasm.cmd" value="ilasm">
<and><available file="ilasm" filepath="${env.PATH}"/></and>
</condition>
<echo level="verbose" message="Found: ${ilasm.cmd}"/>
<fail message="Command 'ilasm' not found">
<condition><not><isset property="ilasm.cmd"/></not></condition>
</fail>
<!-- Sets ilasm arguments (either Windows or Unix) -->
<if>
<isset property="os.win"/>
<then>
<property
name="ilasm.args"
value="/quiet /dll /output="
/>
</then>
<else>
<property
name="ilasm.args"
value="/dll /output:"
/>
</else>
</if>
</target>
<!-- ===========================================================================
MSIL BUILD
============================================================================ -->
<target name="msil.start" depends="msil.init"/>
<target name="msil.src" depends="msil.start">
<!-- simple sync & copy overwrite is not very nice, because overwritten files
will then have a new timestamp, and be recompiled -->
<mkdir dir="${build-msil-src.dir}"/>
<copy todir="${build-msil-src.dir}" overwrite="true">
<!-- FIXME: include new collection library -->
<fileset dir="${src.dir}/library" excludes="scalax/**">
<and>
<present present="srconly" targetdir="${src.dir}/dotnet-library"/>
<different targetdir="${build-msil-src.dir}" ignoreFileTimes="true"/>
</and>
</fileset>
<!-- FIXME: include new collection library -->
<fileset dir="${src.dir}/dotnet-library" excludes="scalax/**">
<different targetdir="${build-msil-src.dir}" ignoreFileTimes="true"/>
</fileset>
</copy>
<delete verbose="true">
<difference>
<fileset dir="${build-msil-src.dir}"/>
<union>
<fileset dir="${build-msil-src.dir}">
<present targetdir="${src.dir}/dotnet-library"/>
</fileset>
<fileset dir="${build-msil-src.dir}">
<present targetdir="${src.dir}/library"/>
</fileset>
</union>
</difference>
</delete>
</target>
<target name="msil.lib" depends="msil.src">
<stopwatch name="msil.lib.timer"/>
<mkdir dir="${build-msil.dir}/library"/>
<!-- <ilasm srcdir="${msil.dir}/il" includes="*.msil" outputfile="${msil.dir}/lib/predef.dll"/> -->
<scalac
srcdir="${build-msil-src.dir}"
destdir="${build-msil.dir}/library"
target="msil"
assemname="predef.msil"
assemrefs="${lib.dir}">
<include name="**/*.scala"/>
<exclude name="scala/ScalaObject.scala"/>
</scalac>
<stopwatch name="msil.lib.timer" action="total"/>
</target>
<target name="msil.done" depends="msil.lib"/>
<target name="msil.clean" depends="msil-pack.clean">
<delete dir="${build-msil.dir}" includeemptydirs="yes" quiet="yes" failonerror="no"/>
<delete dir="${build-msil-src.dir}" includeemptydirs="yes" quiet="yes" failonerror="no"/>
</target>
<!-- ===========================================================================
PACKED MSIL BUILD (MSIL-PACK)
============================================================================ -->
<target name="msil-pack.start" depends="msil.done"/>
<target name="msil-pack.lib" depends="msil-pack.start">
<mkdir dir="${build-msil-pack.dir}/lib"/>
<pathconvert property="ilasm.infiles" pathsep=" ">
<fileset dir="${build-msil.dir}/library" includes="**/*.msil"/>
</pathconvert>
<property name="msil-pack-lib.file" value="${build-msil-pack.dir}/lib/predef.dll"/>
<!--
NOTE: Command line length hell on windows. The maximal command line length on
Windows XP or later is 8191 characters (http://support.microsoft.com/kb/830473).
BUT: this only applies for processes executed directly in the shell, which is NOT
the case by default when using ant's "exec" command; this one uses the Java VM's
execution facilities which allow larger command lines. Testing gives:
- Windows XP: 32768 characters
When the parameter (vmlauncher="false") is specified, the <exec/> command uses
the udnerlying shell, and the smaller limit applies.
The call to ilasm produces lots of output, which could be avoided using
(spawn="true"). This seems to work wrt to the character limit (32768), but is
probably not the best solution since it's incompatible with (failonerror),
and does not produce any output at all.
-->
<exec executable="${ilasm.cmd}" failonerror="true">
<arg line="${ilasm.args}${msil-pack-lib.file} ${ilasm.infiles}"/>
</exec>
</target>
<target name="msil-pack.bin" depends="msil-pack.lib">
<mkdir dir="${build-msil-pack.dir}/bin"/>
<copy todir="${build-msil-pack.dir}/bin">
<fileset
dir="${src-mono.dir}/bin"
includes="scala-net*"
/>
<filterset>
<filter token="VERSION" value="${version.number}"/>
<filter token="COPYRIGHT" value="${copyright.string}"/>
<filter token="NAME" value="Scala code runner"/>
</filterset>
</copy>
<copy todir="${build-msil-pack.dir}/bin">
<fileset
dir="${src-mono.dir}/bin"
includes="scalac-net*"
/>
<filterset>
<filter token="VERSION" value="${version.number}"/>
<filter token="COPYRIGHT" value="${copyright.string}"/>
<filter token="NAME" value="Scala compiler"/>
</filterset>
</copy>
<chmod perm="ugo+rx" dir="${build-msil-pack.dir}/bin"
includes="scala*-net*" excludes="*.bat"/>
<if>
<isset property="os.win"/>
<then>
<copy todir="${build-msil-pack.dir}/lib">
<fileset
dir="${lib.dir}"
includes="mscorlib.dll,scalaruntime.dll"/>
<fileset
dir="${build-pack.dir}/lib"
includes="scala-compiler.jar,scala-library.jar"/>
</copy>
</then>
<else>
<symlink
link="${build-msil-pack.dir}/lib/mscorlib.dll"
resource="${lib.dir}/mscorlib.dll"
overwrite="yes"/>
<symlink
link="${build-msil-pack.dir}/lib/scalaruntime.dll"
resource="${lib.dir}/scalaruntime.dll"
overwrite="yes"/>
<symlink
link="${build-msil-pack.dir}/lib/scala-compiler.jar"
resource="${build-pack.dir}/lib/scala-compiler.jar"
overwrite="yes"/>
<symlink
link="${build-msil-pack.dir}/lib/scala-library.jar"
resource="${build-pack.dir}/lib/scala-library.jar"
overwrite="yes"/>
</else>
</if>
</target>
<target name="msil-pack.done" depends="msil-pack.bin"/>
<target name="msil-pack.clean">
<delete dir="${build-msil-pack.dir}" includeemptydirs="yes" quiet="yes" failonerror="no"/>
</target>
<!-- ===========================================================================
DOCUMENTATION
============================================================================ -->
<!-- see four.xml for template -->
<target name="msil-docs.done"/>
<target name="msil-docs.clean"/>
<!-- ===========================================================================
BOOTRAPING TEST AND TEST SUITE
============================================================================ -->
<!-- see four.xml for template -->
<target name="msil-test.done"/>
<!-- ===========================================================================
DISTRIBUTION
============================================================================ -->
<target name="msil-dist.start" depends="msil-pack.done">
<property name="msil-dist.dir" value="${dists.dir}/scala-msil-${version.number}"/>
</target>
<target name="msil-dist.lib" depends="msil-dist.start">
<mkdir dir="${msil-dist.dir}/lib"/>
<copy toDir="${msil-dist.dir}/lib">
<fileset dir="${build-msil-pack.dir}/lib"
includes="*.dll"/>
<fileset dir="${build-msil-pack.dir}/lib"
includes="scala-compiler.jar,scala-library.jar"/>
</copy>
</target>
<target name="msil-dist.bin" depends="msil-dist.lib">
<mkdir dir="${msil-dist.dir}/bin"/>
<copy toDir="${msil-dist.dir}/bin">
<fileset dir="${build-msil-pack.dir}/bin"
includes="scala*-net*"/>
</copy>
<chmod perm="ugo+rx" dir="${msil-dist.dir}/bin"
includes="scala*-net*" excludes="*.bat"/>
</target>
<target name="msil-dist.latest" depends="msil-dist.bin" unless="os.win">
<symlink link="${dists.dir}/latest-msil" resource="${msil-dist.dir}" overwrite="yes"/>
</target>
<target name="msil-dist.done" depends="msil-dist.latest"/>
<!-- ===========================================================================
TEST AND DISTRIBUTION BUNDLE (ALL)
============================================================================ -->
<target name="msil-all.done" depends="msil-dist.done, msil-test.done"/>
<target name="msil-all.clean" depends="msil-docs.clean, msil.clean"/>
</project>

View File

@ -260,60 +260,6 @@ JAVA FOUR DISTRIBUTION PACKAGING
<target name="fourpack-archives.done" depends="fourpack-archives.zip"/>
<!-- ===========================================================================
MSIL DISTRIBUTION PACKAGING
============================================================================ -->
<!-- MSIL Archive -->
<target name="msilpack-archives.start">
<mkdir dir="${dists.dir}/archives"/>
</target>
<target name="msilpack-archives.tar" depends="msilpack-archives.start">
<tar destfile="${dists.dir}/archives/scala-${version.number}-msil.tgz"
compression="gzip" longfile="gnu">
<tarfileset dir="${dists.dir}/scala-msil-${version.number}" prefix="scala-${version.number}-msil"
includes="bin/**" mode="755"/>
<!-- Inlcude only dll's. Using scala-msil depends on having a scala distribution -->
<tarfileset dir="${dists.dir}/scala-msil-${version.number}" prefix="scala-${version.number}-msil"
includes="lib/*.dll"/>
</tar>
<checksum file="${dists.dir}/archives/scala-${version.number}-msil.tgz" fileext=".md5"/>
</target>
<target name="msilpack-archives.zip" depends="msilpack-archives.tar">
<zip destfile="${dists.dir}/archives/scala-${version.number}-msil.zip">
<zipfileset dir="${dists.dir}/scala-msil-${version.number}" prefix="scala-${version.number}-msil"
includes="bin/**,lib/*.dll"/>
</zip>
<checksum file="${dists.dir}/archives/scala-${version.number}-msil.zip" fileext=".md5"/>
</target>
<target name="msilpack-archives.done" depends="msilpack-archives.zip"/>
<!-- MSIL Sbaz package -->
<target name="msilpack-sbaz.start">
<mkdir dir="${dists.dir}/sbaz"/>
</target>
<target name="msilpack-sbaz.msil" depends="msilpack-sbaz.start">
<sbaz
file="${dists.dir}/sbaz/scala-msil-${version.number}.sbp"
adfile="${dists.dir}/sbaz/scala-msil-${version.number}.advert"
name="scala-msil"
version="${version.number}"
desc="The Scala MSIL package contains everything needed to use Scala on .NET."
depends="scala-library,scala-devel"
link="${sbaz.universe}/scala-msil-${version.number}.sbp">
<binset dir="${dists.dir}/scala-msil-${version.number}/bin" includes="scala*-net*"/>
<libset dir="${dists.dir}/scala-msil-${version.number}/lib" includes="*.dll"/>
</sbaz>
</target>
<target name="msilpack-sbaz.done" depends="msilpack-sbaz.msil"/>
<!-- ===========================================================================
MISCELLANEOUS
============================================================================ -->
@ -322,8 +268,6 @@ MISCELLANEOUS
<target name="fourpack-all.done" depends="fourpack-archives.done"/>
<target name="msilpack-all.done" depends="msilpack-archives.done, msilpack-sbaz.done"/>
<!-- ===========================================================================
MISCELLANEOUS
============================================================================ -->

View File

@ -1,78 +0,0 @@
INFO: The dotnet-library tree has been synchronized with
revision 15115 of src/library on $Date: 2008-05-21 14:33:42 +0200 (Wed, 21 May 2008) $.
IMPORTANT:
Never, never, never, ever add/remove/edit files in the dotnet-library
tree by hand. If you need to change sth use the opportunity to merge
the changes that have occured since the last merge. Any manual intervention
makes the merging harder and is to be considerd rude and counterproductive.
HOW TO MERGE:
You can obtain the revision number of the last merge from the commit history
of the tree. Or from the second line of this document. But you should
always check to see if it is consistent with svn log messages.
lamppc26:trunk luc$ svn log -r 15115
------------------------------------------------------------------------
r15115 | rytz | 2008-05-20 16:57:39 +0200 (Tue, 20 May 2008) | 1 line
Synced src/dotnet-library with rev 15086 of src/library
------------------------------------------------------------------------
Unless you have a specific revision in mind you can check the lates revision
of the src/library tree with
koko:~/scala>svn info src/library/
Path: src/library
URL: https://lampsvn.epfl.ch/svn-repos/scala/scala/trunk/src/library
Repository Root: https://lampsvn.epfl.ch/svn-repos/scala
Repository UUID: 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
Revision: 12880
Node Kind: directory
Schedule: normal
Last Changed Author: mihaylov
Last Changed Rev: 12880
Last Changed Date: 2007-09-17 12:56:57 +0200 (Mon, 17 Sep 2007)
From this we could figure out that we need to merge the changes that happened
between revisions 12365 and 12880 of the src/library tree:
koko:~/scala/src/dotnet-library>svn merge \
https://lampsvn.epfl.ch/svn-repos/scala/scala/trunk/src/library@12365 \
https://lampsvn.epfl.ch/svn-repos/scala/scala/trunk/src/library@12880 ./
(note the ./ at the end of the line specifying the working copy)
You'll get many "Skipped missing target: ..." messages because this tree
only contains files that are different for MSIL. Hopefully, changes in those
files do not introduce anything platform-specific because they will be copied
from the src/library tree. If there are platform-specific changes, the
offending file has to be added to the dotnet-library tree and modified to
compile for .NET.
When you have sorted out the conflicts (by means of manual editing and
'svn resolved'), at the top project directory run
ant msil
to check, at the bare minimum, whether the MSIL subset of the library compiles.
If this is fine, you can commit your changes but make sure that in the commit
message you
INCLUDE THE REVISION NUMBER WITH WHICH YOU HAVE MERGED!!!!
This is very important because subversion will not keep it for you. And this
number is absilutely necessary for the next merge. Also, you should update
the revision number in this document for consistency.
koko:~/scala/src/dotnet-library>svn ci -m "Synced src/dotnet-library with rev 12880 of src/library"
Adding dotnet-library/README
Sending dotnet-library/scala/Predef.scala
Sending dotnet-library/scala/Random.scala
Sending dotnet-library/scala/runtime/RichString.scala
Transmitting file data ....
Committed revision 12881.

View File

@ -1,93 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
package scala
//import java.lang.System.getProperty
//import scala.compat.Platform.currentTime
/** <p>
* The <code>Application</code> trait can be used to quickly turn objects
* into executable programs, but is <em>not recommended</em>.
* Here is an example:
* </p><pre>
* object Main with Application {
* Console.println("Hello World!");
* }
* </pre>
* <p>
* Here, object <code>Main</code> inherits the <code>main</code> method
* of <code>Application</code>. The body of the <code>Main</code> object
* defines the main program. This technique does not work if the main
* program depends on command-line arguments (which are not accessible
* with the technique presented here).
* </p>
* <p>
* It is possible to time the execution of objects that inherit from class
* <code>Application</code> by setting the global <code>scala.time</code>
* property. Here is an example for benchmarking object <code>Main</code>:
* </p><pre>
* java -Dscala.time Main
* </pre>
* <p>
* In practice the <code>Application</code> trait has a number of serious
* pitfalls:
* </p>
* <ul>
* <li> Threaded code that references the object will block until static
* initialization is complete. However, because the entire execution of an
* <code>object</code> extending <code>Application</code> takes place during
* static initialization, concurrent code will <em>always</em> deadlock if
* it must synchronize with the enclosing object.</li>
* <li>As described above, there is no way to obtain the
* command-line arguments because all code in body of an <code>object</code>
* extending <code>Application</code> is run as part of the static initialization
* which occurs before <code>Application</code>'s <code>main</code> method
* even begins execution.</li>
* <li>Static initializers are run only once during program execution, and
* JVM authors usually assume their execution to be relatively short.
* Therefore, certain JVM configurations may become confused, or simply fail to
* optimize or JIT the code in the body of an <code>object</code> extending
* <code>Application</code>. This can lead to a significant
* performance degradation.</li>
* </ul>
*
* Instead, it is recommended to define a <code>main</code> method explicitly:
* <pre>
* <b>object</b> Main {
* <b>def</b> main(args: Array[String]) {
* //..
* }
* }
* </pre>
*
* @author Matthias Zenger
* @version 1.0, 10/09/2003
*/
trait Application {
/** The time when execution of this program started.
*/
// val executionStart: Long = currentTime
/** The default main method.
*
* @param args the arguments passed to the main method
*/
def main(args: Array[String]) {
// if (getProperty("scala.time") ne null) {
// val total = currentTime - executionStart
// Console.println("[total " + total + "ms]")
// }
}
}

View File

@ -1 +0,0 @@
/* BigDecimal.scala does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* BigInt does not exist for the dotnet target */

View File

@ -1,310 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
package scala
import System.IO.{TextReader,TextWriter}
import scala.util.DynamicVariable
import Predef._
/** The <code>Console</code> object implements functionality for
* printing Scala values on the terminal. There are also functions
* for reading specific values. <code>Console</code> also defines
* constants for marking up text on ANSI terminals.
*
* @author Matthias Zenger
* @version 1.0, 03/09/2003
*/
object Console {
// ANSI colors foreground
final val BLACK = "\033[30m"
final val RED = "\033[31m"
final val GREEN = "\033[32m"
final val YELLOW = "\033[33m"
final val BLUE = "\033[34m"
final val MAGENTA = "\033[35m"
final val CYAN = "\033[36m"
final val WHITE = "\033[37m"
// ANSI colors background
final val BLACK_B = "\033[40m"
final val RED_B = "\033[41m"
final val GREEN_B = "\033[42m"
final val YELLOW_B = "\033[43m"
final val BLUE_B = "\033[44m"
final val MAGENTA_B = "\033[45m"
final val CYAN_B = "\033[46m"
final val WHITE_B = "\033[47m"
// ANSI styles
final val RESET = "\033[0m"
final val BOLD = "\033[1m"
final val UNDERLINED = "\033[4m"
final val BLINK = "\033[5m"
final val REVERSED = "\033[7m"
final val INVISIBLE = "\033[8m"
private val outVar = new DynamicVariable[TextWriter](System.Console.Out)
private val inVar = new DynamicVariable[TextReader](System.Console.In)
def out = outVar.value
def in = inVar.value
/** Set the default output stream.
*
* @param out the new output stream.
*/
def setOut(out: TextWriter) { outVar.value = out }
/** Set the default output stream for the duration
* of execution of one thunk.
*
* @param out the new output stream.
* @param thunk the code to execute with
* the new output stream active
*/
def withOut[T](out: TextWriter)(thunk: =>T): T =
outVar.withValue(out)(thunk)
/** Set the default input stream.
*
* @param reader specifies the new input stream.
*/
def setIn(reader: TextReader) {
inVar.value = reader
}
/** Set the default input stream for the duration
* of execution of one thunk.
*
* @param in the new input stream.
* @param thunk the code to execute with
* the new input stream active
*/
def withIn[T](reader: TextReader)(thunk: =>T): T =
inVar.withValue(reader)(thunk)
/** Print an object on the terminal.
*
* @param obj the object to print.
*/
def print(obj: Any) {
out.Write(if (null == obj) "null" else obj.toString())
}
/** Flush the output stream. This function is required when partial
* output (i.e. output not terminated by a new line character) has
* to be made visible on the terminal.
*/
def flush() { out.Flush() }
/** Print a new line character on the terminal.
*/
def println() { out.WriteLine() }
/** Print out an object followed by a new line character.
*
* @param x the object to print.
*/
def println(x: Any) { out.WriteLine(x) }
/** <p>
* Prints its arguments as a formatted string, based on a string
* pattern (in a fashion similar to printf in C).
* </p>
* <p>
* The interpretation of the formatting patterns is described in
* <a href="" target="contentFrame" class="java/util/Formatter">
* <code>java.util.Formatter</code></a>.
* </p>
*
* @param text the pattern for formatting the arguments.
* @param args the arguments used to instantiating the pattern.
* @throws java.lang.IllegalArgumentException
*/
def printf(text: String, args: Any*) { format(text, args: _*) }
/**
* @see <a href="#printf(java.lang.String,scala.Any*)"
* target="contentFrame">Console.printf</a>.
*/
def format(text: String, args: Any*) {
if (text eq null) out.Write("null")
else out.Write(text, args.toArray)
}
/** Read a full line from the terminal. Throws System.IO.EndOfStreamException if the end of the
* input stream has been reached.
*
* @return the string read from the terminal.
* @throws System.IO.EndOfStreamException
*/
def readLine(): String = {
val s = in.ReadLine()
if (s == null) throw new System.IO.EndOfStreamException("Console has reached end of input") else s
}
/** Print a formatted text and read a full line from the terminal.
* Returns null if the end of the input stream has been reached.
*
* @param text the format of the text to print out.
* @param args the parameters used to instantiate the format.
* @return the string read from the terminal.
*/
def readLine(text: String, args: Any*): String = {
printf(text, args: _*)
readLine()
}
/** Read a boolean value from the terminal.
*
* @return the boolean value read from the terminal.
*/
def readBoolean(): Boolean = readLine().toLowerCase() match {
case "true" => true
case "t" => true
case "yes" => true
case "y" => true
case _ => false
}
/** Read a byte value from the terminal.
*/
def readByte(): Byte = readLine().toByte
/** Read a short value from the terminal.
*/
def readShort(): Short = readLine().toShort
/** Read a char value from the terminal.
*/
def readChar(): Char = readLine() charAt 0
/** Read an int value from the terminal.
*/
def readInt(): Int = readLine().toInt
/** Read an int value from the terminal.
*/
def readLong(): Long = readLine().toLong
/** Read a float value from the terminal.
*/
def readFloat(): Float = readLine().toFloat
/** Read a double value from the terminal.
*/
def readDouble(): Double = readLine().toDouble
// /** Read in some structured input, specified by a format specifier.
// * See class <code>java.text.MessageFormat</code> for details of
// * the format specification.
// *
// * @param format the format of the input.
// * @return a list of all extracted values.
// */
// def readf(format: String): List[Any] =
// textComponents(new MessageFormat(format).parse(readLine()))
// /** Read in some structured input, specified by a format specifier.
// * Opposed to <code>readf</code>, this function only returns the
// * first value extracted from the input according to the format
// * specification.
// *
// * @param format ...
// * @return ...
// */
// def readf1(format: String): Any = readf(format).head
// /** Read in some structured input, specified by a format specifier.
// * Opposed to <code>readf</code>, this function only returns the
// * first two values extracted from the input according to the format
// * specification.
// *
// * @param format ...
// * @return ...
// */
// def readf2(format: String): (Any, Any) = {
// val res = readf(format)
// (res.head, res.tail.head)
// }
// /** Read in some structured input, specified by a format specifier.
// * Opposed to <code>readf</code>, this function only returns the
// * first three values extracted from the input according to the format
// * specification.
// *
// * @param format ...
// * @return ...
// */
// def readf3(format: String): (Any, Any, Any) = {
// val res = readf(format)
// (res.head, res.tail.head, res.tail.tail.head)
// }
// private def textComponents(a: Array[AnyRef]): List[Any] = {
// var i: Int = a.length - 1
// var res: List[Any] = Nil
// while (i >= 0) {
// res = (a(i) match {
// case x: java.lang.Boolean => x.booleanValue()
// case x: java.lang.Byte => x.byteValue()
// case x: java.lang.Short => x.shortValue()
// case x: java.lang.Character => x.charValue()
// case x: java.lang.Integer => x.intValue()
// case x: java.lang.Long => x.longValue()
// case x: java.lang.Float => x.floatValue()
// case x: java.lang.Double => x.doubleValue()
// case x => x
// }) :: res;
// i = i - 1
// }
// res
// }
// private def textParams(s: Seq[Any]): Array[AnyRef] = {
// val res = new Array[AnyRef](s.length)
// var i: Int = 0
// val iter = s.iterator
// while (iter.hasNext) {
// res(i) = iter.next match {
// case x: Boolean => java.lang.Boolean.valueOf(x)
// /** Should use java.lang.Byte.valueOf(Byte), but only available
// * in Java 1.5 and above. */
// case x: Byte => new java.lang.Byte(x)
// /** Should use java.lang.Short.valueOf(Short), but only available
// * in Java 1.5 and above. */
// case x: Short => new java.lang.Short(x)
// /** Should use java.lang.Character.valueOf(Char), but only available
// * in Java 1.5 and above. */
// case x: Char => new java.lang.Character(x)
// /** Should use java.lang.Integer.valueOf(Int), but only available
// * in Java 1.5 and above. */
// case x: Int => new java.lang.Integer(x)
// /** Should use java.lang.Long.valueOf(Long), but only available
// * in Java 1.5 and above. */
// case x: Long => new java.lang.Long(x)
// case x: Float => new java.lang.Float(x)
// case x: Double => new java.lang.Double(x)
// case x: Unit => "()"
// case x: AnyRef => x
// }
// i += 1
// }
// res
// }
}

View File

@ -1,146 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
package scala
/** The object <code>Math</code> contains methods for performing basic numeric
* operations such as the elementary exponential, logarithm, square root, and
* trigonometric functions.
*/
object Math {
/** The smallest possible value for <a href="Byte.html" target="_self">scala.Byte</a>. */
val MIN_BYTE = System.Byte.MinValue
/** The greatest possible value for <a href="Byte.html" target="_self">scala.Byte</a>. */
val MAX_BYTE = System.Byte.MaxValue
/** The smallest possible value for <a href="Short.html" target="_self">scala.Short</a>. */
val MIN_SHORT = System.Int16.MinValue
/** The greatest possible value for <a href="Short.html" target="_self">scala.Short</a>. */
val MAX_SHORT = System.Int16.MaxValue
/** The smallest possible value for <a href="Char.html" target="_self">scala.Char</a>. */
val MIN_CHAR = System.Char.MinValue
/** The greatest possible value for <a href="Char.html" target="_self">scala.Char</a>. */
val MAX_CHAR = System.Char.MaxValue
/** The smallest possible value for <a href="Int.html" target="_self">scala.Int</a>. */
val MIN_INT = System.Int32.MinValue
/** The greatest possible value for <a href="Int.html" target="_self">scala.Int</a>. */
val MAX_INT = System.Int32.MaxValue
/** The smallest possible value for <a href="Long.html" target="_self">scala.Long</a>. */
val MIN_LONG = System.Int64.MinValue
/** The greatest possible value for <a href="Long.html" target="_self">scala.Long</a>. */
val MAX_LONG = System.Int64.MaxValue
/** The smallest possible value for <a href="Float.html" target="_self">scala.Float</a>. */
val MIN_FLOAT = System.Single.MinValue
/** The smallest difference between two values of <a href="Float.html" target="_self">scala.Float</a>. */
val EPS_FLOAT = System.Single.Epsilon
/** The greatest possible value for <a href="Float.html" target="_self">scala.Float</a>. */
val MAX_FLOAT = System.Single.MinValue
/** A value of type <a href="Float.html" target="_self">scala.Float</a> that represents no number. */
//val NaN_FLOAT = System.Single.NaN
/** Negative infinity of type <a href="Float.html" target="_self">scala.Float</a>. */
//val NEG_INF_FLOAT = System.Double.NegativeInfinity
/** Positive infinity of type <a href="Float.html" target="_self">scala.Float</a>. */
//val POS_INF_FLOAT = System.Double.PositiveInfinity
/** The smallest possible value for <a href="Double.html" target="_self">scala.Double</a>. */
val MIN_DOUBLE = System.Double.MinValue
/** The smallest difference between two values of <a href="Double.html" target="_self">scala.Double</a>. */
val EPS_DOUBLE = System.Double.Epsilon
/** The greatest possible value for <a href="Double.html" target="_self">scala.Double</a>. */
val MAX_DOUBLE = System.Double.MaxValue
/** A value of type <a href="Double.html" target="_self">scala.Double</a> that represents no number. */
//val NaN_DOUBLE = System.Double.NaN
/** Negative infinity of type <a href="Double.html" target="_self">scala.Double</a>. */
//val NEG_INF_DOUBLE = System.Double.NegativeInfinity
/** Positive infinity of type <a href="Double.html" target="_self">scala.Double</a>. */
//val POS_INF_DOUBLE = System.Double.PositiveInfinity
/** The <code>double</code> value that is closer than any other to
* <code>e</code>, the base of the natural logarithms.
*/
val E = System.Math.E
val Pi = System.Math.PI
//def random: Double = System.Math.random()
def sin(x: Double): Double = System.Math.Sin(x)
def cos(x: Double): Double = System.Math.Cos(x)
def tan(x: Double): Double = System.Math.Tan(x)
def asin(x: Double): Double = System.Math.Asin(x)
def acos(x: Double): Double = System.Math.Acos(x)
def atan(x: Double): Double = System.Math.Atan(x)
def toRadians(x: Double): Double = x * Pi / 180.0
def toDegrees(x: Double): Double = x * 180.0 / Pi
def exp(x: Double): Double = System.Math.Exp(x)
def log(x: Double): Double = System.Math.Log(x)
def sqrt(x: Double): Double = System.Math.Sqrt(x)
def sqrt(x: Int): Int = System.Math.Sqrt(x.toDouble).toInt
def IEEEremainder(x: Double, y: Double): Double = System.Math.IEEERemainder(x, y)
def ceil(x: Double): Double = System.Math.Ceiling(x)
def floor(x: Double): Double = System.Math.Floor(x)
//def rint(x: Double): Double = System.Math.rint(x)
def atan2(y: Double, x: Double): Double = System.Math.Atan2(y, x)
def pow(x: Double, y: Double): Double = System.Math.Pow(x, y)
def round(x: Float): Int = System.Math.Round(x).toInt
def round(x: Double): Long = System.Math.Round(x).toLong
def abs(x: Int): Int = System.Math.Abs(x)
def abs(x: Long): Long = System.Math.Abs(x)
def abs(x: Float): Float = System.Math.Abs(x)
def abs(x: Double): Double = System.Math.Abs(x)
def max(x: Int, y: Int): Int = System.Math.Max(x, y)
def max(x: Long, y: Long): Long = System.Math.Max(x, y)
def max(x: Float, y: Float): Float = System.Math.Max(x, y)
def max(x: Double, y: Double): Double = System.Math.Max(x, y)
def min(x: Int, y: Int): Int = System.Math.Min(x, y)
def min(x: Long, y: Long): Long = System.Math.Min(x, y)
def min(x: Float, y: Float): Float = System.Math.Min(x, y)
def min(x: Double, y: Double): Double = System.Math.Min(x, y)
def signum(x: Double): Double = x match { case 0 => 0
case y if y < 0 => -1.0
case y if y > 0 => 1.0 }
def signum(x: Float): Float = x match { case 0f => 0f
case y if y < 0f => -1.0f
case y if y > 0f => 1.0f }
def signum(x: Long): Long = x match { case 0l => 0l
case y if y < 0l => -1l
case y if y > 0l => 1l }
def signum(x: Int): Int = x match { case 0 => 0
case y if y < 0 => -1
case y if y > 0 => 1}
// from Java 1.5
// def log10(x: Double): Double = java.lang.Math.log10(x)
// def cbrt(x: Double): Double = java.lang.Math.cbrt(x)
//
// def ulp(x: Double): Double = java.lang.Math.ulp(x)
// def ulp(x: Float): Float = java.lang.Math.ulp(x)
// def sinh(x: Double): Double = java.lang.Math.sinh(x)
// def cosh(x: Double): Double = java.lang.Math.cosh(x)
// def tanh(x: Double):Double = java.lang.Math.tanh(x)
// def hypot(x: Double, y: Double): Double = java.lang.Math.hypot(x, y)
// def expm1(x: Double): Double = java.lang.Math.expm1(x)
// def log1p(x: Double): Double = java.lang.Math.log1p(x)
}

View File

@ -1,117 +0,0 @@
package scala
object Numeric {
// trait BigIntIsIntegral extends Integral[BigInt] {
// def plus(x: BigInt, y: BigInt): BigInt = x + y
// def minus(x: BigInt, y: BigInt): BigInt = x - y
// def times(x: BigInt, y: BigInt): BigInt = x * y
// def quot(x: BigInt, y: BigInt): BigInt = x / y
// def rem(x: BigInt, y: BigInt): BigInt = x % y
// def negate(x: BigInt): BigInt = -x
// def abs(x: BigInt): BigInt = if (x < 0) -x else x
// def signum(x: BigInt): BigInt = if (x < 0) -1 else if (x > 0) 1 else 0
// def fromInt(x: Int): BigInt = BigInt(x)
// def toInt(x: BigInt): Int = x.intValue
// def toLong(x: BigInt): Long = x.longValue
// def toFloat(x: BigInt): Float = x.longValue.toFloat
// def toDouble(x: BigInt): Double = x.longValue.toDouble
// }
// implicit object BigIntIsIntegral extends BigIntIsIntegral
trait IntIsIntegral extends Integral[Int] {
def plus(x: Int, y: Int): Int = x + y
def minus(x: Int, y: Int): Int = x - y
def times(x: Int, y: Int): Int = x * y
def quot(x: Int, y: Int): Int = x / y
def rem(x: Int, y: Int): Int = x % y
def negate(x: Int): Int = -x
def abs(x: Int): Int = if (x < 0) -x else x
def signum(x: Int): Int = if (x < 0) -1 else if (x > 0) 1 else 0
def fromInt(x: Int): Int = x
def toInt(x: Int): Int = x
def toLong(x: Int): Long = x
def toFloat(x: Int): Float = x
def toDouble(x: Int): Double = x
}
implicit object IntIsIntegral extends IntIsIntegral
trait LongIsIntegral extends Integral[Long] {
def plus(x: Long, y: Long): Long = x + y
def minus(x: Long, y: Long): Long = x - y
def times(x: Long, y: Long): Long = x * y
def quot(x: Long, y: Long): Long = x / y
def rem(x: Long, y: Long): Long = x % y
def negate(x: Long): Long = -x
def abs(x: Long): Long = if (x < 0) -x else x
def signum(x: Long): Long = if (x < 0) -1 else if (x > 0) 1 else 0
def fromInt(x: Int): Long = x
def toInt(x: Long): Int = x.toInt
def toLong(x: Long): Long = x
def toFloat(x: Long): Float = x
def toDouble(x: Long): Double = x
}
implicit object LongIsIntegral extends LongIsIntegral
trait FloatIsFractional extends Fractional[Float] {
def plus(x: Float, y: Float): Float = x + y
def minus(x: Float, y: Float): Float = x - y
def times(x: Float, y: Float): Float = x * y
def div(x: Float, y: Float): Float = x / y
def negate(x: Float): Float = -x
def abs(x: Float): Float = if (x < 0) -x else x
def signum(x: Float): Float = if (x < 0) -1 else if (x > 0) 1 else 0
def fromInt(x: Int): Float = x
def toInt(x: Float): Int = x.toInt
def toLong(x: Float): Long = x.toLong
def toFloat(x: Float): Float = x
def toDouble(x: Float): Double = x
}
implicit object FloatIsFractional extends FloatIsFractional
trait DoubleIsFractional extends Fractional[Double] {
def plus(x: Double, y: Double): Double = x + y
def minus(x: Double, y: Double): Double = x - y
def times(x: Double, y: Double): Double = x * y
def div(x: Double, y: Double): Double = x / y
def negate(x: Double): Double = -x
def abs(x: Double): Double = if (x < 0) -x else x
def signum(x: Double): Double = if (x < 0) -1 else if (x > 0) 1 else 0
def fromInt(x: Int): Double = x
def toInt(x: Double): Int = x.toInt
def toLong(x: Double): Long = x.toLong
def toFloat(x: Double): Float = x.toFloat
def toDouble(x: Double): Double = x
}
implicit object DoubleIsFractional extends DoubleIsFractional
}
trait Numeric[T] {
def plus(x: T, y: T): T
def minus(x: T, y: T): T
def times(x: T, y: T): T
def negate(x: T): T
def abs(x: T): T
def signum(x: T): T
def fromInt(x: Int): T
def toInt(x: T): Int
def toLong(x: T): Long
def toFloat(x: T): Float
def toDouble(x: T): Double
def zero = fromInt(0)
def one = fromInt(1)
class Ops(lhs: T) {
def +(rhs: T) = plus(lhs, rhs)
def -(rhs: T) = minus(lhs, rhs)
def *(rhs: T) = times(lhs, rhs)
def unary_-() = negate(lhs)
def abs(): T = Numeric.this.abs(lhs)
def signum(): T = Numeric.this.signum(lhs)
def toInt(): Int = Numeric.this.toInt(lhs)
def toLong(): Long = Numeric.this.toLong(lhs)
def toFloat(): Float = Numeric.this.toFloat(lhs)
def toDouble(): Double = Numeric.this.toDouble(lhs)
}
implicit def mkNumericOps(lhs: T): Ops = new Ops(lhs)
}

View File

@ -1,319 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
package scala
/** A trait for representing total orderings. It is important to
* distinguish between a type that has a total order and a representation
* of total ordering on some type. This trait is for representing the
* latter.
*
* A <a href="http://en.wikipedia.org/wiki/Total_order">total ordering</a>
* is a binary relation on a type <code>T</code> that is also an equivalence relation
* and partial ordering on values of type <code>T</code>. This relation is exposed as
* the <code>compare</code> method of the <code>Ordering</code> trait.
* This relation must be:
* <ul>
* <li>reflexive: <code>compare(x, x) == 0</code>, for any <code>x</code> of
* type <code>T</code>.</li>
* <li>symmetry: <code>compare(x, y) == z</code> and <code>compare(y, x) == w</code>
* then <code>Math.signum(z) == -Math.signum(w)</code>, for any <code>x</code> and <code>y</code> of
* type <code>T</code> and <code>z</code> and <code>w</code> of type <code>Int</code>.</li>
* <li>transitive: if <code>compare(x, y) == z</code> and <code>compare(y, w) == v</code>
* and <code>Math.signum(z) &gt;= 0</code> and <code>Math.signum(v) &gt;= 0</code> then
* <code>compare(x, w) == u</code> and <code>Math.signum(z + v) == Math.signum(u)</code>,
* for any <code>x</code>, <code>y</code>,
* and <code>w</code> of type <code>T</code> and <code>z</code>, <code>v</code>, and <code>u</code>
* of type <code>Int</code>.</li>
* </ul>
*
* @author Geoffrey Washburn
* @version 0.9.5, 2008-04-15
*/
trait Ordering[T] extends PartialOrdering[T] {
/** Returns a negative integer iff <code>x</code> comes before
* <code>y</code> in the ordering, returns 0 iff <code>x</code>
* is the same in the ordering as <code>y</code>, and returns a
* positive number iff <code>x</code> comes after
* <code>y</code> in the ordering.
*/
def compare(x: T, y: T): Int
/** Returns <code>true</code> iff <code>x</code> comes before
* <code>y</code> in the ordering.
*/
override def lteq(x: T, y: T): Boolean = compare(x, y) <= 0
/** Returns <code>true</code> iff <code>y</code> comes before
* <code>x</code> in the ordering.
*/
override def gteq(x: T, y: T): Boolean = compare(x, y) >= 0
/** Returns <code>true</code> iff <code>x</code> comes before
* <code>y</code> in the ordering and is not the same as <code>y</code>.
*/
override def lt(x: T, y: T): Boolean = compare(x, y) < 0
/** Returns <code>true</code> iff <code>y</code> comes before
* <code>x</code> in the ordering and is not the same as <code>x</code>.
*/
override def gt(x: T, y: T): Boolean = compare(x, y) > 0
/** Returns <code>true</code> iff <code>x</code> is equivalent to
* <code>y</code> in the ordering.
*/
override def equiv(x: T, y: T): Boolean = compare(x, y) == 0
class Ops(lhs: T) {
def <(rhs: T) = lt(lhs, rhs)
def <=(rhs: T) = lteq(lhs, rhs)
def >(rhs: T) = gt(lhs, rhs)
def >=(rhs: T) = gteq(lhs, rhs)
def ===(rhs: T) = equiv(lhs, rhs)
def !==(rhs: T) = !equiv(lhs, rhs)
}
implicit def mkOrderingOps(lhs: T): Ops = new Ops(lhs)
}
object Ordering
{
def apply[T](implicit ord : Ordering[T]) = ord
implicit val Unit : Ordering[Unit] = new Ordering[Unit] {
def compare(x : Unit, y : Unit) = 0;
}
implicit val Boolean : Ordering[Boolean] = new Ordering[Boolean] {
def compare(x : Boolean, y : Boolean) = (x, y) match {
case (false, true) => -1;
case (true, false) => 1;
case _ => 0;
}
}
implicit val Byte : Ordering[Byte] = new Ordering[Byte] {
def compare(x : Byte, y : Byte) = x.toInt - y.toInt;
}
implicit val Char : Ordering[Char] = new Ordering[Char] {
def compare(x : Char, y : Char) = x.toInt - y.toInt;
}
implicit val Short : Ordering[Short] = new Ordering[Short] {
def compare(x : Short, y : Short) = x.toInt - y.toInt;
}
implicit val Int : Ordering[Int] = new Ordering[Int] {
def compare(x : Int, y : Int) =
if(x < y) -1;
else if (x == y) 0;
else 1
}
implicit val Long : Ordering[Long] = new Ordering[Long] {
def compare(x : Long, y : Long) =
if(x < y) -1;
else if (x == y) 0;
else 1
}
implicit val Float : Ordering[Float] = new Ordering[Float] {
def compare(x : Float, y : Float) =
if(x < y) -1;
else if (x == y) 0;
else 1
}
implicit val Double : Ordering[Double] = new Ordering[Double] {
def compare(x : Double, y : Double) =
if(x < y) -1;
else if (x == y) 0;
else 1
}
// implicit val BigInt : Ordering[BigInt] = new Ordering[BigInt] {
// def compare(x : BigInt, y : BigInt) = x.compare(y);
// }
implicit val String : Ordering[String] = new Ordering[String] {
def compare(x : String, y : String) = x.compareTo(y);
}
implicit def Option[T](implicit ord : Ordering[T]) : Ordering[Option[T]] =
new Ordering[Option[T]] {
def compare(x : Option[T], y : Option[T]) = (x, y) match {
case (None, None) => 0;
case (None, _) => -1;
case (_, None) => 1
case (Some(x), Some(y)) => ord.compare(x, y);
}
}
implicit def Iterable[T](implicit ord : Ordering[T]) : Ordering[Iterable[T]] =
new Ordering[Iterable[T]] {
def compare(x : Iterable[T], y : Iterable[T]) : Int = {
val xe = x.iterator;
val ye = y.iterator;
while (xe.hasNext && ye.hasNext){
val res = ord.compare(xe.next, ye.next);
if (res != 0) return res;
}
Boolean.compare(xe.hasNext, ye.hasNext);
}
}
implicit def Tuple2[T1, T2](implicit ord1 : Ordering[T1], ord2 : Ordering[T2]) : Ordering[(T1, T2)] =
new Ordering[(T1, T2)]{
def compare(x : Tuple2[T1, T2], y : Tuple2[T1, T2]) : Int = {
val compare1 = ord1.compare(x._1, y._1);
if (compare1 != 0) return compare1;
val compare2 = ord2.compare(x._2, y._2);
if (compare2 != 0) return compare2;
0;
}
}
implicit def Tuple3[T1, T2, T3](implicit ord1 : Ordering[T1], ord2 : Ordering[T2], ord3 : Ordering[T3]) : Ordering[(T1, T2, T3)] =
new Ordering[(T1, T2, T3)]{
def compare(x : Tuple3[T1, T2, T3], y : Tuple3[T1, T2, T3]) : Int = {
val compare1 = ord1.compare(x._1, y._1);
if (compare1 != 0) return compare1;
val compare2 = ord2.compare(x._2, y._2);
if (compare2 != 0) return compare2;
val compare3 = ord3.compare(x._3, y._3);
if (compare3 != 0) return compare3;
0;
}
}
implicit def Tuple4[T1, T2, T3, T4](implicit ord1 : Ordering[T1], ord2 : Ordering[T2], ord3 : Ordering[T3], ord4 : Ordering[T4]) : Ordering[(T1, T2, T3, T4)] =
new Ordering[(T1, T2, T3, T4)]{
def compare(x : Tuple4[T1, T2, T3, T4], y : Tuple4[T1, T2, T3, T4]) : Int = {
val compare1 = ord1.compare(x._1, y._1);
if (compare1 != 0) return compare1;
val compare2 = ord2.compare(x._2, y._2);
if (compare2 != 0) return compare2;
val compare3 = ord3.compare(x._3, y._3);
if (compare3 != 0) return compare3;
val compare4 = ord4.compare(x._4, y._4);
if (compare4 != 0) return compare4;
0;
}
}
implicit def Tuple5[T1, T2, T3, T4, T5](implicit ord1 : Ordering[T1], ord2 : Ordering[T2], ord3 : Ordering[T3], ord4 : Ordering[T4], ord5 : Ordering[T5]) : Ordering[(T1, T2, T3, T4, T5)] =
new Ordering[(T1, T2, T3, T4, T5)]{
def compare(x : Tuple5[T1, T2, T3, T4, T5], y : Tuple5[T1, T2, T3, T4, T5]) : Int = {
val compare1 = ord1.compare(x._1, y._1);
if (compare1 != 0) return compare1;
val compare2 = ord2.compare(x._2, y._2);
if (compare2 != 0) return compare2;
val compare3 = ord3.compare(x._3, y._3);
if (compare3 != 0) return compare3;
val compare4 = ord4.compare(x._4, y._4);
if (compare4 != 0) return compare4;
val compare5 = ord5.compare(x._5, y._5);
if (compare5 != 0) return compare5;
0;
}
}
implicit def Tuple6[T1, T2, T3, T4, T5, T6](implicit ord1 : Ordering[T1], ord2 : Ordering[T2], ord3 : Ordering[T3], ord4 : Ordering[T4], ord5 : Ordering[T5], ord6 : Ordering[T6]) : Ordering[(T1, T2, T3, T4, T5, T6)] =
new Ordering[(T1, T2, T3, T4, T5, T6)]{
def compare(x : Tuple6[T1, T2, T3, T4, T5, T6], y : Tuple6[T1, T2, T3, T4, T5, T6]) : Int = {
val compare1 = ord1.compare(x._1, y._1);
if (compare1 != 0) return compare1;
val compare2 = ord2.compare(x._2, y._2);
if (compare2 != 0) return compare2;
val compare3 = ord3.compare(x._3, y._3);
if (compare3 != 0) return compare3;
val compare4 = ord4.compare(x._4, y._4);
if (compare4 != 0) return compare4;
val compare5 = ord5.compare(x._5, y._5);
if (compare5 != 0) return compare5;
val compare6 = ord6.compare(x._6, y._6);
if (compare6 != 0) return compare6;
0;
}
}
implicit def Tuple7[T1, T2, T3, T4, T5, T6, T7](implicit ord1 : Ordering[T1], ord2 : Ordering[T2], ord3 : Ordering[T3], ord4 : Ordering[T4], ord5 : Ordering[T5], ord6 : Ordering[T6], ord7 : Ordering[T7]) : Ordering[(T1, T2, T3, T4, T5, T6, T7)] =
new Ordering[(T1, T2, T3, T4, T5, T6, T7)]{
def compare(x : Tuple7[T1, T2, T3, T4, T5, T6, T7], y : Tuple7[T1, T2, T3, T4, T5, T6, T7]) : Int = {
val compare1 = ord1.compare(x._1, y._1);
if (compare1 != 0) return compare1;
val compare2 = ord2.compare(x._2, y._2);
if (compare2 != 0) return compare2;
val compare3 = ord3.compare(x._3, y._3);
if (compare3 != 0) return compare3;
val compare4 = ord4.compare(x._4, y._4);
if (compare4 != 0) return compare4;
val compare5 = ord5.compare(x._5, y._5);
if (compare5 != 0) return compare5;
val compare6 = ord6.compare(x._6, y._6);
if (compare6 != 0) return compare6;
val compare7 = ord7.compare(x._7, y._7);
if (compare7 != 0) return compare7;
0;
}
}
implicit def Tuple8[T1, T2, T3, T4, T5, T6, T7, T8](implicit ord1 : Ordering[T1], ord2 : Ordering[T2], ord3 : Ordering[T3], ord4 : Ordering[T4], ord5 : Ordering[T5], ord6 : Ordering[T6], ord7 : Ordering[T7], ord8 : Ordering[T8]) : Ordering[(T1, T2, T3, T4, T5, T6, T7, T8)] =
new Ordering[(T1, T2, T3, T4, T5, T6, T7, T8)]{
def compare(x : Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], y : Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]) : Int = {
val compare1 = ord1.compare(x._1, y._1);
if (compare1 != 0) return compare1;
val compare2 = ord2.compare(x._2, y._2);
if (compare2 != 0) return compare2;
val compare3 = ord3.compare(x._3, y._3);
if (compare3 != 0) return compare3;
val compare4 = ord4.compare(x._4, y._4);
if (compare4 != 0) return compare4;
val compare5 = ord5.compare(x._5, y._5);
if (compare5 != 0) return compare5;
val compare6 = ord6.compare(x._6, y._6);
if (compare6 != 0) return compare6;
val compare7 = ord7.compare(x._7, y._7);
if (compare7 != 0) return compare7;
val compare8 = ord8.compare(x._8, y._8);
if (compare8 != 0) return compare8;
0;
}
}
implicit def Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9](implicit ord1 : Ordering[T1], ord2 : Ordering[T2], ord3 : Ordering[T3], ord4 : Ordering[T4], ord5 : Ordering[T5], ord6 : Ordering[T6], ord7 : Ordering[T7], ord8 : Ordering[T8], ord9 : Ordering[T9]) : Ordering[(T1, T2, T3, T4, T5, T6, T7, T8, T9)] =
new Ordering[(T1, T2, T3, T4, T5, T6, T7, T8, T9)]{
def compare(x : Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], y : Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) : Int = {
val compare1 = ord1.compare(x._1, y._1);
if (compare1 != 0) return compare1;
val compare2 = ord2.compare(x._2, y._2);
if (compare2 != 0) return compare2;
val compare3 = ord3.compare(x._3, y._3);
if (compare3 != 0) return compare3;
val compare4 = ord4.compare(x._4, y._4);
if (compare4 != 0) return compare4;
val compare5 = ord5.compare(x._5, y._5);
if (compare5 != 0) return compare5;
val compare6 = ord6.compare(x._6, y._6);
if (compare6 != 0) return compare6;
val compare7 = ord7.compare(x._7, y._7);
if (compare7 != 0) return compare7;
val compare8 = ord8.compare(x._8, y._8);
if (compare8 != 0) return compare8;
val compare9 = ord9.compare(x._9, y._9);
if (compare9 != 0) return compare9;
0;
}
}
}

View File

@ -1,237 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
package scala
/** The <code>Predef</code> object provides definitions that are
* accessible in all Scala compilation units without explicit
* qualification.
*/
object Predef {
// classOf dummy ------------------------------------------------------
/** Return the runtime representation of a class type. */
def classOf[T]: Class[T] = null
// aliases ------------------------------------------------------------
@deprecated type byte = scala.Byte
@deprecated type short = scala.Short
@deprecated type char = scala.Char
@deprecated type int = scala.Int
@deprecated type long = scala.Long
@deprecated type float = scala.Float
@deprecated type double = scala.Double
@deprecated type boolean = scala.Boolean
@deprecated type unit = scala.Unit
type String = System.String
type Class[T] = System.Type
type Runnable = scala.runtime.Runnable
type Throwable = System.Exception
type Exception = System.Exception
type Error = System.Exception
type RuntimeException = System.Exception
type NullPointerException = System.NullReferenceException
type ClassCastException = System.InvalidCastException
type IndexOutOfBoundsException = System.IndexOutOfRangeException
type ArrayIndexOutOfBoundsException = System.IndexOutOfRangeException
type StringIndexOutOfBoundsException = System.IndexOutOfRangeException
type UnsupportedOperationException = System.InvalidOperationException
type IllegalArgumentException = System.ArgumentException
type NoSuchElementException = System.InvalidOperationException
type NumberFormatException = System.FormatException
type AbstractMethodError = System.InvalidOperationException
// miscelleaneous -----------------------------------------------------
private val P = scala.`package` // to force scala package object to be seen.
private val L = scala.collection.immutable.List // to force Nil, :: to be seen.
private val S = scala.collection.mutable.StringBuilder // to force StringBuilder to be seen.
//val $scope = scala.xml.TopScope
type Function[-A, +B] = Function1[A, B]
type Map[A, +B] = collection.immutable.Map[A, B]
type Set[A] = collection.immutable.Set[A]
val Map = collection.immutable.Map
val Set = collection.immutable.Set
// errors and asserts -------------------------------------------------
def error(message: String): Nothing = throw new RuntimeException(message)
def exit(): Nothing = exit(0)
def exit(status: Int): Nothing = {
System.Environment.Exit(status)
throw new Throwable()
}
def assert(assertion: Boolean) {
if (!assertion)
throw new Error("assertion failed")
}
def assert(assertion: Boolean, message: => Any) {
if (!assertion)
throw new Error("assertion failed: " + message)
}
def assume(assumption: Boolean) {
if (!assumption)
throw new IllegalArgumentException("assumption failed")
}
def assume(assumption: Boolean, message: => Any) {
if (!assumption)
throw new System.Security.SecurityException("assumption failed: "+ message)
}
def require(requirement: Boolean) {
if (!requirement)
throw new IllegalArgumentException("requirement failed")
}
def require(requirement: Boolean, message: => Any) {
if (!requirement)
throw new IllegalArgumentException("requirement failed: "+ message)
}
// tupling ------------------------------------------------------------
type Pair[+A, +B] = Tuple2[A, B]
object Pair {
def apply[A, B](x: A, y: B) = Tuple2(x, y)
def unapply[A, B](x: Tuple2[A, B]): Option[Tuple2[A, B]] = Some(x)
}
type Triple[+A, +B, +C] = Tuple3[A, B, C]
object Triple {
def apply[A, B, C](x: A, y: B, z: C) = Tuple3(x, y, z)
def unapply[A, B, C](x: Tuple3[A, B, C]): Option[Tuple3[A, B, C]] = Some(x)
}
class Ensuring[A](x: A) {
def ensuring(cond: Boolean): A = { assert(cond); x }
def ensuring(cond: Boolean, msg: Any): A = { assert(cond, msg); x }
def ensuring(cond: A => Boolean): A = { assert(cond(x)); x }
def ensuring(cond: A => Boolean, msg: Any): A = { assert(cond(x), msg); x }
}
implicit def any2Ensuring[A](x: A): Ensuring[A] = new Ensuring(x)
class ArrowAssoc[A](x: A) {
def -> [B](y: B): Tuple2[A, B] = Tuple2(x, y)
def [B](y: B): Tuple2[A, B] = ->(y)
}
implicit def any2ArrowAssoc[A](x: A): ArrowAssoc[A] = new ArrowAssoc(x)
def Tuple[A1](x1: A1) = Tuple1(x1)
def Tuple[A1, A2](x1: A1, x2: A2) = Tuple2(x1, x2)
def Tuple[A1, A2, A3](x1: A1, x2: A2, x3: A3) = Tuple3(x1, x2, x3)
def Tuple[A1, A2, A3, A4](x1: A1, x2: A2, x3: A3, x4: A4) = Tuple4(x1, x2, x3, x4)
def Tuple[A1, A2, A3, A4, A5](x1: A1, x2: A2, x3: A3, x4: A4, x5: A5) = Tuple5(x1, x2, x3, x4, x5)
def Tuple[A1, A2, A3, A4, A5, A6](x1: A1, x2: A2, x3: A3, x4: A4, x5: A5, x6: A6) = Tuple6(x1, x2, x3, x4, x5, x6)
def Tuple[A1, A2, A3, A4, A5, A6, A7](x1: A1, x2: A2, x3: A3, x4: A4, x5: A5, x6: A6, x7: A7) = Tuple7(x1, x2, x3, x4, x5, x6, x7)
def Tuple[A1, A2, A3, A4, A5, A6, A7, A8](x1: A1, x2: A2, x3: A3, x4: A4, x5: A5, x6: A6, x7: A7, x8: A8) = Tuple8(x1, x2, x3, x4, x5, x6, x7, x8)
def Tuple[A1, A2, A3, A4, A5, A6, A7, A8, A9](x1: A1, x2: A2, x3: A3, x4: A4, x5: A5, x6: A6, x7: A7, x8: A8, x9: A9) = Tuple9(x1, x2, x3, x4, x5, x6, x7, x8, x9)
// printing and reading -----------------------------------------------
def print(x: Any) = Console.print(x)
def println() = Console.println()
def println(x: Any) = Console.println(x)
//def printf(text: String, xs: Any*) = Console.printf(text, xs: _*)
//def format(text: String, xs: Any*) = Console.format(text, xs)
def readLine(): String = Console.readLine()
def readLine(text: String, args: Any*) = Console.readLine(text, args)
def readBoolean() = Console.readBoolean()
def readByte() = Console.readByte()
def readShort() = Console.readShort()
def readChar() = Console.readChar()
def readInt() = Console.readInt()
def readLong() = Console.readLong()
def readFloat() = Console.readFloat()
def readDouble() = Console.readDouble()
//def readf(format: String) = Console.readf(format)
//def readf1(format: String) = Console.readf1(format)
//def readf2(format: String) = Console.readf2(format)
//def readf3(format: String) = Console.readf3(format)
// views --------------------------------------------------------------
implicit def identity[A](x: A): A = x
implicit def byteWrapper(x: Byte) = new runtime.RichByte(x)
implicit def shortWrapper(x: Short) = new runtime.RichShort(x)
implicit def intWrapper(x: Int) = new runtime.RichInt(x)
implicit def charWrapper(c: Char) = new runtime.RichChar(c)
implicit def longWrapper(x: Long) = new runtime.RichLong(x)
implicit def floatWrapper(x: Float) = new runtime.RichFloat(x)
implicit def doubleWrapper(x: Double) = new runtime.RichDouble(x)
implicit def booleanWrapper(x: Boolean) = new runtime.RichBoolean(x)
implicit def unitWrapper(x: Boolean) = new runtime.RichUnit
implicit def stringWrapper(x: String) = new runtime.RichString(x)
implicit def any2stringadd(x: Any) = new runtime.StringAdd(x)
implicit def exceptionWrapper(exc: Throwable) = new runtime.RichException(exc)
final class GetClassWrapper(obj: AnyRef) {
def getClass(): runtime.RichClass = classWrapper(obj.GetType())
}
implicit def getClassWrapper(obj: AnyRef) = new GetClassWrapper(obj)
implicit def classWrapper(clazz: Class[_]): runtime.RichClass =
new runtime.RichClass(clazz)
/** Lens from Ordering[T] to Ordered[T] */
implicit def orderingToOrdered[T](x: T)(implicit ord: Ordering[T]): Ordered[T] =
new Ordered[T] { def compare(that: T): Int = ord.compare(x, that) }
implicit def byte2short(x: Byte): Short = x.toShort
implicit def byte2int(x: Byte): Int = x.toInt
implicit def byte2long(x: Byte): Long = x.toLong
implicit def byte2float(x: Byte): Float = x.toFloat
implicit def byte2double(x: Byte): Double = x.toDouble
implicit def short2int(x: Short): Int = x.toInt
implicit def short2long(x: Short): Long = x.toLong
implicit def short2float(x: Short): Float = x.toFloat
implicit def short2double(x: Short): Double = x.toDouble
implicit def char2int(x: Char): Int = x.toInt
implicit def char2long(x: Char): Long = x.toLong
implicit def char2float(x: Char): Float = x.toFloat
implicit def char2double(x: Char): Double = x.toDouble
implicit def int2long(x: Int): Long = x.toLong
implicit def int2float(x: Int): Float = x.toFloat
implicit def int2double(x: Int): Double = x.toDouble
implicit def long2float(x: Long): Float = x.toFloat
implicit def long2double(x: Long): Double = x.toDouble
implicit def float2double(x: Float): Double = x.toDouble
//implicit def forceArrayProjection[A](x : Array.Projection[A]) : Array[A] = x.force !!! re-enable?
def currentThread = System.Threading.Thread.CurrentThread
}

View File

@ -1,234 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2006-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
package scala
import collection.immutable.Vector
import collection.generic.VectorView
/** <p>
* <code>GenericRange</code> is a generified version of the
* <code>Range</code> class which works with arbitrary types.
* It must be supplied with Integral and Ordering implementations
* of the range type.
*
* Factories for likely types include Range.BigInt and Range.Long.
* Range.Int exists for completeness, but the Int-based scala.Range
* should be more performant.
* </p><pre>
* <b>val</b> r1 = new Range(0, 100, 1)
* <b>val</b> veryBig = Math.MAX_INT.toLong + 1
* <b>val</b> r2 = Range.Long(veryBig, veryBig + 100, 1)
* assert(r1 sameElements r2.map(_ - veryBig))
* </pre>
*
* @author Paul Phillips
* @version 2.8
*/
abstract class GenericRange[T]
(val start: T, val end: T, val step: T)
(implicit num: Integral[T], ord: Ordering[T])
extends VectorView[T, Vector[T]] with RangeToString[T] {
import num._
import ord._
// this lets us pretend all ranges are exclusive
val isInclusive: Boolean
private val trueEnd = if (isInclusive) end + one else end
// todo? - we could lift the length restriction by implementing a range as a sequence of
// subranges and limiting the subranges to MAX_INT. There's no other way around it because
// the generics we inherit assume integer-based indexing (as well they should.)
require(step !== zero)
require(genericLength <= fromInt(Math.MAX_INT), "Implementation restricts ranges to Math.MAX_INT elements.")
protected def underlying = Vector.empty[T]
/** Create a new range with the start and end values of this range and
* a new <code>step</code>.
*/
def by(step: T): GenericRange[T] =
if (isInclusive) GenericRange.inclusive(start, end, step)
else GenericRange(start, end, step)
override def foreach[U](f: T => U) {
var i = start
if (step > zero) {
while (i < trueEnd) {
f(i)
i = i + step
}
} else {
while (i > trueEnd) {
f(i)
i = i + step
}
}
}
lazy val genericLength: T = {
def plen(start: T, end: T, step: T) =
if (trueEnd <= start) zero
else (trueEnd - start - one) / step + one
if (step > zero) plen(start, trueEnd, step)
else plen(trueEnd, start, -step)
}
lazy val length: Int = toInt(genericLength)
// Since apply(Int) already exists, we are not allowed apply(T) since
// they erase to the same thing.
def apply(idx: Int): T = applyAt(fromInt(idx))
def applyAt(idx: T): T = {
if (idx < zero || idx >= genericLength) throw new IndexOutOfBoundsException(idx.toString)
start + idx * step
}
override def contains(_x: Any): Boolean = {
// XXX - can we avoid this cast and still have a contains method?
val x =
try { _x.asInstanceOf[T] }
catch { case _: ClassCastException => return false }
if (step > zero) start <= x && x < trueEnd
else start >= x && x > trueEnd
}
}
private[scala] trait RangeToString[T] extends VectorView[T, Vector[T]] {
// The default toString() tries to print every element and will exhaust memory
// if the Range is unduly large. This interacts poorly with the REPL.
override def toString() = {
val MAX_PRINT = 512 // some arbitrary value
val str = (this take MAX_PRINT).toString
if (length > MAX_PRINT) str.substring(0, str.length-1) + "...)"
else str
}
}
object GenericRange {
import Numeric._
import Ordering._
class Inclusive[T](start: T, end: T, step: T)(implicit num: Integral[T], ord: Ordering[T])
extends GenericRange(start, end, step)
{
val isInclusive = true
def exclusive: Exclusive[T] = new Exclusive(start, end, step)
}
class Exclusive[T](start: T, end: T, step: T)(implicit num: Integral[T], ord: Ordering[T])
extends GenericRange(start, end, step)
{
val isInclusive = false
def inclusive: Inclusive[T] = new Inclusive(start, end, step)
}
def apply[T](start: T, end: T, step: T)(implicit num: Integral[T], ord: Ordering[T]) =
new Exclusive(start, end, step)
def inclusive[T](start: T, end: T, step: T)(implicit num: Integral[T], ord: Ordering[T]) =
new Inclusive(start, end, step)
}
/** <p>
* The <code>Range</code> class represents integer values in range
* <code>[start;end)</code> with non-zero step value <code>step</code>.
* Sort of acts like a sequence also (supports length and contains).
* For example:
* </p><pre>
* <b>val</b> r1 = 0 until 10
* <b>val</b> r2 = r1.start until r1.end by r1.step + 1
* println(r2.length) // = 5
* </pre>
*
* @author Martin Odersky
* @version 2.8
*/
class Range(val start: Int, val end: Int, val step: Int)
extends VectorView[Int, Vector[Int]] with RangeToString[Int]
{
require(step != 0)
protected def underlying = Vector.empty[Int]
/** Create a new range with the start and end values of this range and
* a new <code>step</code>.
*/
def by(step: Int): Range = new Range(start, end, step)
final override def foreach[U](f: Int => U) {
var i = start
if (step > 0) {
while (i < end) {
f(i)
i += step
}
} else {
while (i > end) {
f(i)
i += step
}
}
}
lazy val length: Int = {
def plen(start: Int, end: Int, step: Int) =
if (end <= start) 0 else (end - start - 1) / step + 1
if (step > 0) plen(start, end, step)
else plen(end, start, -step)
}
@inline
final def apply(idx: Int): Int = {
if (idx < 0 || idx >= length) throw new IndexOutOfBoundsException(idx.toString)
start + idx * step
}
def contains(x: Int): Boolean =
if (step > 0) start <= x && x < end
else start >= x && x > end
def inclusive = Range.inclusive(start, end, step)
}
object Range {
/** @deprecated use Range.inclusive instead */
final class Inclusive(start: Int, end0: Int, step: Int)
extends Range(start, if (step > 0) end0 + 1 else end0 - 1, step) { self =>
override def by(step: Int): Range = new Inclusive(start, end0, step)
}
def apply(start: Int, end: Int, step: Int) =
new Range(start, end, step)
def inclusive(start: Int, end: Int, step: Int): Range =
new Range.Inclusive(start, end, step)
// object BigInt {
// def apply(start: BigInt, end: BigInt, step: BigInt) = GenericRange(start, end, step)
// def inclusive(start: BigInt, end: BigInt, step: BigInt) = GenericRange.inclusive(start, end, step)
// }
object Long {
def apply(start: Long, end: Long, step: Long) = GenericRange(start, end, step)
def inclusive(start: Long, end: Long, step: Long) = GenericRange.inclusive(start, end, step)
}
// Illustrating genericity with Int Range, which should have the same behavior
// as the original Range class. However we leave the original Range
// indefinitely, for performance and because the compiler seems to bootstrap
// off it and won't do so with our parameterized version without modifications.
object Int {
def apply(start: Int, end: Int, step: Int) = GenericRange(start, end, step)
def inclusive(start: Int, end: Int, step: Int) = GenericRange.inclusive(start, end, step)
}
}

View File

@ -1,49 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
package scala
/** <p>
* Instances of <code>Symbol</code> can be created easily with
* Scala's built-in quote mechanism.
* </p>
* <p>
* For instance, the <a href="http://scala-lang.org/" target="_top">Scala</a>
* term <code>'mysym</code> will invoke the constructor of the
* <code>Symbol</code> class in the following way:
* <code>new Symbol("mysym")</code>.
* </p>
*
* @author Martin Odersky
* @version 1.7, 08/12/2003
*/
final case class Symbol(name: String) {
/** Converts this symbol to a string.
*/
override def toString(): String = {
"'" + name
}
/** <p>
* Makes this symbol into a unique reference.
* </p>
* <p>
* If two interened symbols are equal (i.e. they have the same name)
* then they must be identical (wrt reference equality).
* </p>
*
* @return the unique reference to this symbol.
*/
def intern: Symbol = this
}

View File

@ -1 +0,0 @@
/* JavaConversions does not exist for the dotnet target */

View File

@ -1,863 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
package scala.collection.immutable
import mutable.ListBuffer
import generic._
/** A class representing an ordered collection of elements of type
* <code>a</code>. This class comes with two implementing case
* classes <code>scala.Nil</code> and <code>scala.::</code> that
* implement the abstract members <code>isEmpty</code>,
* <code>head</code> and <code>tail</code>.
*
* @author Martin Odersky and others
* @version 2.8
*/
sealed abstract class List[+A] extends LinearSequence[A]
with Product
with TraversableClass[A, List]
with LinearSequenceTemplate[A, List[A]] {
override def companion: Companion[List] = List
import collection.{Iterable, Traversable, Sequence, Vector}
/** Returns true if the list does not contain any elements.
* @return <code>true</code>, iff the list is empty.
*/
def isEmpty: Boolean
/** Returns this first element of the list.
*
* @return the first element of this list.
* @throws Predef.NoSuchElementException if the list is empty.
*/
def head: A
/** Returns this list without its first element.
*
* @return this list without its first element.
* @throws Predef.NoSuchElementException if the list is empty.
*/
def tail: List[A]
// New methods in List
/** <p>
* Add an element <code>x</code> at the beginning of this list.
* </p>
*
* @param x the element to prepend.
* @return the list with <code>x</code> added at the beginning.
* @ex <code>1 :: List(2, 3) = List(2, 3).::(1) = List(1, 2, 3)</code>
*/
def ::[B >: A] (x: B): List[B] =
new scala.collection.immutable.::(x, this)
/** <p>
* Returns a list resulting from the concatenation of the given
* list <code>prefix</code> and this list.
* </p>
*
* @param prefix the list to concatenate at the beginning of this list.
* @return the concatenation of the two lists.
* @ex <code>List(1, 2) ::: List(3, 4) = List(3, 4).:::(List(1, 2)) = List(1, 2, 3, 4)</code>
*/
def :::[B >: A](prefix: List[B]): List[B] =
if (isEmpty) prefix
else (new ListBuffer[B] ++ prefix).prependToList(this)
/** Reverse the given prefix and append the current list to that.
* This function is equivalent to an application of <code>reverse</code>
* on the prefix followed by a call to <code>:::</code>, but is more
* efficient.
*
* @param prefix the prefix to reverse and then prepend
* @return the concatenation of the reversed prefix and the current list.
*/
def reverse_:::[B >: A](prefix: List[B]): List[B] = {
var these: List[B] = this
var pres = prefix
while (!pres.isEmpty) {
these = pres.head :: these
pres = pres.tail
}
these
}
/** Apply a function to all the elements of the list, and return the
* reversed list of results. This is equivalent to a call to <code>map</code>
* followed by a call to <code>reverse</code>, but more efficient.
* !!! should we deprecate this? Why have reverseMap, but not filterMap or reverseFilter, say?
* @param f the function to apply to each elements.
* @return the reversed list of results.
*/
def reverseMap[B](f: A => B): List[B] = {
def loop(l: List[A], res: List[B]): List[B] = l match {
case Nil => res
case head :: tail => loop(tail, f(head) :: res)
}
loop(this, Nil)
}
/** Like xs map f, but returns <code>xs</code> unchanged if function
* <code>f</code> maps all elements to themselves (wrt ==).
* @note Unlike `map`, `mapConserve` is not tail-recursive.
*/
def mapConserve[B >: A] (f: A => B): List[B] = {
def loop(ys: List[A]): List[B] =
if (ys.isEmpty) this
else {
val head0 = ys.head
val head1 = f(head0)
if (head1 == head0) {
loop(ys.tail)
} else {
val ys1 = head1 :: ys.tail.mapConserve(f)
if (this eq ys) ys1
else {
val b = new ListBuffer[B]
var xc = this
while (xc ne ys) {
b += xc.head
xc = xc.tail
}
b.prependToList(ys1)
}
}
}
loop(this)
}
// Overridden methods from IterableTemplate or overloaded variants of such methods
/** Create a new list which contains all elements of this list
* followed by all elements of Traversable `that'
*/
override def ++[B >: A, That](that: Traversable[B])(implicit bf: BuilderFactory[B, That, List[A]]): That = {
val b = bf(this)
if (b.isInstanceOf[ListBuffer[_]]) (this ::: that.toList).asInstanceOf[That]
else super.++(that)
}
/** Create a new list which contains all elements of this list
* followed by all elements of Iterator `that'
*/
override def ++[B >: A, That](that: Iterator[B])(implicit bf: BuilderFactory[B, That, List[A]]): That =
this ++ that.toList
/** Overrides the method in Iterable for efficiency.
*
* @return the list itself
*/
override def toList: List[A] = this
/** Returns the <code>n</code> first elements of this list, or else the whole
* list, if it has less than <code>n</code> elements.
* @param n the number of elements to take.
* @return the <code>n</code> first elements of this list.
*/
override def take(n: Int): List[A] = {
val b = new ListBuffer[A]
var i = 0
var these = this
while (!these.isEmpty && i < n) {
i += 1
b += these.head
these = these.tail
}
if (these.isEmpty) this
else b.toList
}
/** Returns the list without its <code>n</code> first elements.
* If this list has less than <code>n</code> elements, the empty list is returned.
*
* @param n the number of elements to drop.
* @return the list without its <code>n</code> first elements.
*/
override def drop(n: Int): List[A] = {
var these = this
var count = n
while (!these.isEmpty && count > 0) {
these = these.tail
count -= 1
}
these
}
/** Returns the list with elements belonging to the given index range.
*
* @param start the start position of the list slice.
* @param end the end position (exclusive) of the list slice.
* @return the list with elements belonging to the given index range.
*/
override def slice(start: Int, end: Int): List[A] = {
var len = end
if (start > 0) len -= start
drop(start) take len
}
/** Returns the rightmost <code>n</code> elements from this list.
*
* @param n the number of elements to take
* @return the suffix of length <code>n</code> of the list
*/
override def takeRight(n: Int): List[A] = {
def loop(lead: List[A], lag: List[A]): List[A] = lead match {
case Nil => lag
case _ :: tail => loop(tail, lag.tail)
}
loop(drop(n), this)
}
// dropRight is inherited from Stream
/** Split the list at a given point and return the two parts thus
* created.
*
* @param n the position at which to split
* @return a pair of lists composed of the first <code>n</code>
* elements, and the other elements.
*/
override def splitAt(n: Int): (List[A], List[A]) = {
val b = new ListBuffer[A]
var i = 0
var these = this
while (!these.isEmpty && i < n) {
i += 1
b += these.head
these = these.tail
}
(b.toList, these)
}
/** Returns the longest prefix of this list whose elements satisfy
* the predicate <code>p</code>.
*
* @param p the test predicate.
* @return the longest prefix of this list whose elements satisfy
* the predicate <code>p</code>.
*/
override def takeWhile(p: A => Boolean): List[A] = {
val b = new ListBuffer[A]
var these = this
while (!these.isEmpty && p(these.head)) {
b += these.head
these = these.tail
}
b.toList
}
/** Returns the longest suffix of this list whose first element
* does not satisfy the predicate <code>p</code>.
*
* @param p the test predicate.
* @return the longest suffix of the list whose first element
* does not satisfy the predicate <code>p</code>.
*/
override def dropWhile(p: A => Boolean): List[A] =
if (isEmpty || !p(head)) this
else tail dropWhile p
/** Returns the longest prefix of the list whose elements all satisfy
* the given predicate, and the rest of the list.
*
* @param p the test predicate
* @return a pair consisting of the longest prefix of the list whose
* elements all satisfy <code>p</code>, and the rest of the list.
*/
override def span(p: A => Boolean): (List[A], List[A]) = {
val b = new ListBuffer[A]
var these = this
while (!these.isEmpty && p(these.head)) {
b += these.head
these = these.tail
}
(b.toList, these)
}
/** A list consisting of all elements of this list in reverse order.
*/
override def reverse: List[A] = {
var result: List[A] = Nil
var these = this
while (!these.isEmpty) {
result = these.head :: result
these = these.tail
}
result
}
override def stringPrefix = "List"
override def toStream : Stream[A] =
if (isEmpty) Stream.Empty
else new Stream.Cons(head, tail.toStream)
// !!! todo: work in patch
/** Computes the difference between this list and the given list
* <code>that</code>.
*
* @param that the list of elements to remove from this list.
* @return this list without the elements of the given list
* <code>that</code>.
* @deprecated use diff instead
*/
@deprecated def -- [B >: A](that: List[B]): List[B] = {
val b = new ListBuffer[B]
var these = this
while (!these.isEmpty) {
if (!that.contains(these.head)) b += these.head
these = these.tail
}
b.toList
}
/** Computes the difference between this list and the given object
* <code>x</code>.
*
* @param x the object to remove from this list.
* @return this list without occurrences of the given object
* <code>x</code>.
* @deprecated use diff instead
*/
@deprecated def - [B >: A](x: B): List[B] = {
val b = new ListBuffer[B]
var these = this
while (!these.isEmpty) {
if (these.head != x) b += these.head
these = these.tail
}
b.toList
}
/** <p>
* Sort the list according to the comparison function
* <code>&lt;(e1: a, e2: a) =&gt; Boolean</code>,
* which should be true iff <code>e1</code> is smaller than
* <code>e2</code>.
* !!! todo: move sorting to IterableTemplate
* </p>
*
* @param lt the comparison function
* @return a list sorted according to the comparison function
* <code>&lt;(e1: a, e2: a) =&gt; Boolean</code>.
* @ex <pre>
* List("Steve", "Tom", "John", "Bob")
* .sort((e1, e2) => (e1 compareTo e2) &lt; 0) =
* List("Bob", "John", "Steve", "Tom")</pre>
* @deprecated use sortWith instead
*/
@deprecated def sort(lt : (A,A) => Boolean): List[A] = {
/** Merge two already-sorted lists */
def merge(l1: List[A], l2: List[A]): List[A] = {
val res = new ListBuffer[A]
var left1 = l1
var left2 = l2
while (!left1.isEmpty && !left2.isEmpty) {
if(lt(left1.head, left2.head)) {
res += left1.head
left1 = left1.tail
} else {
res += left2.head
left2 = left2.tail
}
}
res ++= left1
res ++= left2
res.toList
}
/** Split a list into two lists of about the same size */
def split(lst: List[A]) = {
val res1 = new ListBuffer[A]
val res2 = new ListBuffer[A]
var left = lst
while (!left.isEmpty) {
res1 += left.head
left = left.tail
if (!left.isEmpty) {
res2 += left.head
left = left.tail
}
}
(res1.toList, res2.toList)
}
/** Merge-sort the specified list */
def ms(lst: List[A]): List[A] =
lst match {
case Nil => lst
case x :: Nil => lst
case x :: y :: Nil =>
if (lt(x,y))
lst
else
y :: x :: Nil
case lst =>
val (l1, l2) = split(lst)
val l1s = ms(l1)
val l2s = ms(l2)
merge(l1s, l2s)
}
ms(this)
}
}
/** The empty list.
*
* @author Martin Odersky
* @version 1.0, 15/07/2003
*/
@SerialVersionUID(0 - 8256821097970055419L)
case object Nil extends List[Nothing] {
override def isEmpty = true
override def head: Nothing =
throw new NoSuchElementException("head of empty list")
override def tail: List[Nothing] =
throw new NoSuchElementException("tail of empty list")
override def equals(that: Any) = that match {
case that1: Sequence[_] => that1.isEmpty
case _ => false
}
}
/** A non empty list characterized by a head and a tail.
*
* @author Martin Odersky
* @version 1.0, 15/07/2003
*/
@SerialVersionUID(0L - 8476791151983527571L)
final case class ::[B](private var hd: B, private[scala] var tl: List[B]) extends List[B] {
override def head : B = hd
override def tail : List[B] = tl
override def isEmpty: Boolean = false
// import java.io._
// private def writeObject(out: ObjectOutputStream) {
// var xs: List[B] = this
// while (!xs.isEmpty) { out.writeObject(xs.head); xs = xs.tail }
// out.writeObject(ListSerializeEnd)
// }
// private def readObject(in: ObjectInputStream) {
// hd = in.readObject.asInstanceOf[B]
// assert(hd != ListSerializeEnd)
// var current: ::[B] = this
// while (true) in.readObject match {
// case ListSerializeEnd =>
// current.tl = Nil
// return
// case a : Any =>
// val list : ::[B] = new ::(a.asInstanceOf[B], Nil)
// current.tl = list
// current = list
// }
// }
}
/** This object provides methods for creating specialized lists, and for
* transforming special kinds of lists (e.g. lists of lists).
*
* @author Martin Odersky
* @version 2.8
*/
object List extends SequenceFactory[List] {
import collection.{Iterable, Sequence, Vector}
implicit def builderFactory[A]: BuilderFactory[A, List[A], Coll] = new VirtualBuilderFactory[A]
def newBuilder[A]: Builder[A, List[A]] = new ListBuffer[A]
override def empty[A]: List[A] = Nil
override def apply[A](xs: A*): List[A] = xs.toList
/** Create a sorted list with element values
* <code>v<sub>n+1</sub> = step(v<sub>n</sub>)</code>
* where <code>v<sub>0</sub> = start</code>
* and elements are in the range between <code>start</code> (inclusive)
* and <code>end</code> (exclusive)
*
* @deprecated use @see iterate instead.
* @param start the start value of the list
* @param end the end value of the list
* @param step the increment function of the list, which given <code>v<sub>n</sub></code>,
* computes <code>v<sub>n+1</sub></code>. Must be monotonically increasing
* or decreasing.
* @return the sorted list of all integers in range [start;end).
*/
@deprecated def range(start: Int, end: Int, step: Int => Int): List[Int] = {
val up = step(start) > start
val down = step(start) < start
val b = new ListBuffer[Int]
var i = start
while ((!up || i < end) && (!down || i > end)) {
b += i
val next = step(i)
if (i == next)
throw new IllegalArgumentException("the step function did not make any progress on "+ i)
i = next
}
b.toList
}
/** Create a list containing several copies of an element.
* @deprecated use @see fill instead
*
* @param n the length of the resulting list
* @param elem the element composing the resulting list
* @return a list composed of n elements all equal to elem
*/
@deprecated def make[A](n: Int, elem: A): List[A] = {
val b = new ListBuffer[A]
var i = 0
while (i < n) {
b += elem
i += 1
}
b.toList
}
/** Concatenate all the elements of a given list of lists.
*
* @deprecated use `xss.flatten` instead
* @param xss the list of lists that are to be concatenated
* @return the concatenation of all the lists
*/
@deprecated def flatten[A](xss: List[List[A]]): List[A] = {
val b = new ListBuffer[A]
for (xs <- xss) {
var xc = xs
while (!xc.isEmpty) {
b += xc.head
xc = xc.tail
}
}
b.toList
}
/** Transforms a list of pairs into a pair of lists.
*
* @param xs the list of pairs to unzip
* @return a pair of lists.
* @deprecated use `xs.unzp` instead
*/
@deprecated def unzip[A,B](xs: List[(A,B)]): (List[A], List[B]) = {
val b1 = new ListBuffer[A]
val b2 = new ListBuffer[B]
var xc = xs
while (!xc.isEmpty) {
b1 += xc.head._1
b2 += xc.head._2
xc = xc.tail
}
(b1.toList, b2.toList)
}
/** Transforms an iterable of pairs into a pair of lists.
*
* @deprecated use `xs.unzip` instead
* @param xs the iterable of pairs to unzip
* @return a pair of lists.
*/
@deprecated def unzip[A,B](xs: Iterable[(A,B)]): (List[A], List[B]) =
xs.foldRight[(List[A], List[B])]((Nil, Nil)) {
case ((x, y), (xs, ys)) => (x :: xs, y :: ys)
}
/**
* Returns the <code>Left</code> values in the given <code>Iterable</code> of <code>Either</code>s.
* @deprecated use `Either.lefts` instead
*/
@deprecated def lefts[A, B](es: Iterable[Either[A, B]]) =
es.foldRight[List[A]](Nil)((e, as) => e match {
case Left(a) => a :: as
case Right(_) => as
})
/**
* Returns the <code>Right</code> values in the given<code>Iterable</code> of <code>Either</code>s.
* @deprecated use `Either.rights` instead
*/
@deprecated def rights[A, B](es: Iterable[Either[A, B]]) =
es.foldRight[List[B]](Nil)((e, bs) => e match {
case Left(_) => bs
case Right(b) => b :: bs
})
/** Transforms an Iterable of Eithers into a pair of lists.
*
* @param xs the iterable of Eithers to separate
* @return a pair of lists.
* @deprecated use `Either.separate` instead
*/
@deprecated def separate[A,B](es: Iterable[Either[A,B]]): (List[A], List[B]) =
es.foldRight[(List[A], List[B])]((Nil, Nil)) {
case (Left(a), (lefts, rights)) => (a :: lefts, rights)
case (Right(b), (lefts, rights)) => (lefts, b :: rights)
}
/** Converts an iterator to a list.
*
* @param it the iterator to convert
* @return a list that contains the elements returned by successive
* calls to <code>it.next</code>
* @deprecated use it.toList instead
*/
@deprecated def fromIterator[A](it: Iterator[A]): List[A] = it.toList
/** Converts an array into a list.
*
* @param arr the array to convert
* @return a list that contains the same elements than <code>arr</code>
* in the same order
* @deprecated use `array.toList` instead
*/
@deprecated def fromArray[A](arr: Array[A]): List[A] = fromArray(arr, 0, arr.length)
/** Converts a range of an array into a list.
*
* @param arr the array to convert
* @param start the first index to consider
* @param len the lenght of the range to convert
* @return a list that contains the same elements than <code>arr</code>
* in the same order
* @deprecated use `array.view(start, end).toList` instead
*/
@deprecated def fromArray[A](arr: Array[A], start: Int, len: Int): List[A] = {
var res: List[A] = Nil
var i = start + len
while (i > start) {
i -= 1
res = arr(i) :: res
}
res
}
/** Parses a string which contains substrings separated by a
* separator character and returns a list of all substrings.
*
* @param str the string to parse
* @param separator the separator character
* @return the list of substrings
* @deprecated use `str.split(separator).toList` instead
*/
@deprecated def fromString(str: String, separator: Char): List[String] = {
var words: List[String] = Nil
var pos = str.length()
while (pos > 0) {
val pos1 = str.lastIndexOf(separator, pos - 1)
if (pos1 + 1 < pos)
words = str.substring(pos1 + 1, pos) :: words
pos = pos1
}
words
}
/** Returns the given string as a list of characters.
*
* @param str the string to convert.
* @return the string as a list of characters.
* @deprecated use <code>str.toList</code> instead
*/
@deprecated def fromString(str: String): List[Char] = str.toList
/** Returns the given list of characters as a string.
*
* @param xs the list to convert.
* @return the list in form of a string.
* @deprecated use xs.mkString instead
*/
@deprecated def toString(xs: List[Char]): String = {
val sb = new StringBuilder()
var xc = xs
while (!xc.isEmpty) {
sb.append(xc.head)
xc = xc.tail
}
sb.toString()
}
/** Like xs map f, but returns <code>xs</code> unchanged if function
* <code>f</code> maps all elements to themselves.
* @deprecated use xs.mapConserve(f)
*/
@deprecated def mapConserve[A <: AnyRef](xs: List[A])(f: A => A): List[A] = {
def loop(ys: List[A]): List[A] =
if (ys.isEmpty) xs
else {
val head0 = ys.head
val head1 = f(head0)
if (head1 eq head0) {
loop(ys.tail)
} else {
val ys1 = head1 :: mapConserve(ys.tail)(f)
if (xs eq ys) ys1
else {
val b = new ListBuffer[A]
var xc = xs
while (xc ne ys) {
b += xc.head
xc = xc.tail
}
b.prependToList(ys1)
}
}
}
loop(xs)
}
/** Returns the list resulting from applying the given function <code>f</code>
* to corresponding elements of the argument lists.
* @deprecated use (xs, ys).map(f) instead
* @param f function to apply to each pair of elements.
* @return <code>[f(a0,b0), ..., f(an,bn)]</code> if the lists are
* <code>[a0, ..., ak]</code>, <code>[b0, ..., bl]</code> and
* <code>n = min(k,l)</code>
*/
@deprecated def map2[A,B,C](xs: List[A], ys: List[B])(f: (A, B) => C): List[C] = {
val b = new ListBuffer[C]
var xc = xs
var yc = ys
while (!xc.isEmpty && !yc.isEmpty) {
b += f(xc.head, yc.head)
xc = xc.tail
yc = yc.tail
}
b.toList
}
/** Returns the list resulting from applying the given function
* <code>f</code> to corresponding elements of the argument lists.
*
* @param f function to apply to each pair of elements.
* @deprecated use (xs, ys, zs).map(f) instead
* @return <code>[f(a<sub>0</sub>,b<sub>0</sub>,c<sub>0</sub>),
* ..., f(a<sub>n</sub>,b<sub>n</sub>,c<sub>n</sub>)]</code>
* if the lists are <code>[a<sub>0</sub>, ..., a<sub>k</sub>]</code>,
* <code>[b<sub>0</sub>, ..., b<sub>l</sub>]</code>,
* <code>[c<sub>0</sub>, ..., c<sub>m</sub>]</code> and
* <code>n = min(k,l,m)</code>
*/
@deprecated def map3[A,B,C,D](xs: List[A], ys: List[B], zs: List[C])(f: (A, B, C) => D): List[D] = {
val b = new ListBuffer[D]
var xc = xs
var yc = ys
var zc = zs
while (!xc.isEmpty && !yc.isEmpty && !zc.isEmpty) {
b += f(xc.head, yc.head, zc.head)
xc = xc.tail
yc = yc.tail
zc = zc.tail
}
b.toList
}
/** Tests whether the given predicate <code>p</code> holds
* for all corresponding elements of the argument lists.
*
* @param p function to apply to each pair of elements.
* @return <code>(p(a<sub>0</sub>,b<sub>0</sub>) &amp;&amp;
* ... &amp;&amp; p(a<sub>n</sub>,b<sub>n</sub>))]</code>
* if the lists are <code>[a<sub>0</sub>, ..., a<sub>k</sub>]</code>;
* <code>[b<sub>0</sub>, ..., b<sub>l</sub>]</code>
* and <code>n = min(k,l)</code>
* @deprecated use (xs, ys).forall(f) instead
*/
@deprecated def forall2[A,B](xs: List[A], ys: List[B])(f: (A, B) => Boolean): Boolean = {
var xc = xs
var yc = ys
while (!xc.isEmpty && !yc.isEmpty) {
if (!f(xc.head, yc.head)) return false
xc = xc.tail
yc = yc.tail
}
true
}
/** Tests whether the given predicate <code>p</code> holds
* for some corresponding elements of the argument lists.
*
* @param p function to apply to each pair of elements.
* @return <code>n != 0 &amp;&amp; (p(a<sub>0</sub>,b<sub>0</sub>) ||
* ... || p(a<sub>n</sub>,b<sub>n</sub>))]</code> if the lists are
* <code>[a<sub>0</sub>, ..., a<sub>k</sub>]</code>,
* <code>[b<sub>0</sub>, ..., b<sub>l</sub>]</code> and
* <code>n = min(k,l)</code>
* @deprecated use (xs, ys).forall(f) instead
*/
@deprecated def exists2[A,B](xs: List[A], ys: List[B])(f: (A, B) => Boolean): Boolean = {
var xc = xs
var yc = ys
while (!xc.isEmpty && !yc.isEmpty) {
if (f(xc.head, yc.head)) return true
xc = xc.tail
yc = yc.tail
}
false
}
/** Transposes a list of lists.
* pre: All element lists have the same length.
*
* @param xss the list of lists
* @return the transposed list of lists
* @deprecated use xss.transpose instead
*/
@deprecated def transpose[A](xss: List[List[A]]): List[List[A]] = {
val buf = new ListBuffer[List[A]]
var yss = xss
while (!yss.head.isEmpty) {
buf += (yss map (_.head))
yss = (yss map (_.tail))
}
buf.toList
}
/** Lists with ordered elements are ordered
implicit def list2ordered[a <% Ordered[a]](x: List[a]): Ordered[List[a]] = new Ordered[List[a]] {
def compare [b >: List[a] <% Ordered[b]](y: b): Int = y match {
case y1: List[a] => compareLists(x, y1);
case _ => -(y compare x)
}
private def compareLists(xs: List[a], ys: List[a]): Int = {
if (xs.isEmpty && ys.isEmpty) 0
else if (xs.isEmpty) -1
else if (ys.isEmpty) 1
else {
val s = xs.head compare ys.head;
if (s != 0) s
else compareLists(xs.tail, ys.tail)
}
}
}
*/
}
/** Only used for list serialization */
@SerialVersionUID(0L - 8476791151975527571L)
private[scala] case object ListSerializeEnd

View File

@ -1 +0,0 @@
/* PagedSeq does not exist for the dotnet target */

View File

@ -1,4 +0,0 @@
/** OpenHashMap.scala currently doesn't work on .NET because of a bug.
* Remove this file once the ticket is closed.
* http://lampsvn.epfl.ch/trac/scala/ticket/1218
*/

View File

@ -1,955 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2006-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
package scala.collection.mutable
import collection.generic._
import scala.runtime.RichString
/** <p>
* A mutable sequence of characters. This class provides an API compatible
* with <a class="java/lang/StringBuilder" href="" target="_top">
* <code>java.lang.StringBuilder</code></a>.
* </p>generic/
*
* @author Stephane Micheloud
* @author Martin Odersky
* @version 2.8
*/
//@serializable
//@SerialVersionUID(0 - 8525408645367278351L)
final class StringBuilder(initCapacity: Int, private val initValue: String)
extends Builder[Char, String]
with Vector[Char] {
require(initCapacity > 0)
/** The value is used for character storage. */
private var array = new Array[Char](initCapacity + initValue.length)
/** The count is the number of characters used. */
private var count: Int = 0
/** Constructs a string builder with no characters in it and an
* initial capacity of 16 characters.
*/
def this() = this(16, "")
/** Constructs a string builder with no characters in it and an
* initial capacity specified by the <code>capacity</code> argument.
*
* @param capacity the initial capacity.
* @throws NegativeArraySizeException if the <code>capacity</code>
* argument is less than <code>0</code>.
*/
def this(capacity: Int) = this(capacity, "")
/** Constructs a string builder with initial characters
* equal to characters of `str`.
*/
def this(str: String) = this(16, str)
append(initValue)
def toArray: Array[Char] = array
def length: Int = count
def length_=(n: Int) { setLength(n) }
/** Clears the builder contents.
*/
def clear(): Unit = setLength(0)
/** Sets the length of the character sequence.
*
* @param newLength the new length
* @throws IndexOutOfBoundsException if the <code>n</code> argument is negative.
*/
def setLength(n: Int) {
require(n >= 0, n)
while (count < n) append('\0')
count = n
}
/** Returns the current capacity. The capacity is the amount of storage
* available for newly inserted characters, beyond which an allocation
* will occur.
*
* @return the current capacity
*/
def capacity: Int = array.length
/** Same as <code>ensureCapacity</code>.
* @deprecated use `ensureCapacity` instead. An assignment is misleading
* because it can never decrease the capacity.
*/
@deprecated def capacity_=(n: Int) { ensureCapacity(n) }
/** <p>
* Ensures that the capacity is at least equal to the specified minimum.
* If the current capacity is less than the argument, then a new internal
* array is allocated with greater capacity. The new capacity is the larger of:
* </p>
* <ul>
* <li>The <code>n</code> argument.
* <li>Twice the old capacity, plus <code>2</code>.
* </ul>
* <p>
* If the <code>n</code> argument is non-positive, this
* method takes no action and simply returns.
* </p>
*
* @param n the minimum desired capacity.
*/
def ensureCapacity(n: Int) {
if (n > array.length) {
var newsize = array.length * 2
while (n > newsize)
newsize = newsize * 2
val newar = new Array[Char](newsize)
Array.copy(array, 0, newar, 0, count)
array = newar
}
}
/** <p>
* Returns the <code>Char</code> value in this sequence at the specified index.
* The first <code>Char</code> value is at index <code>0</code>, the next at index
* <code>1</code>, and so on, as in array indexing.
* </p>
* <p>
* The index argument must be greater than or equal to
* <code>0</code>, and less than the length of this sequence.
* </p>
*
* @param index the index of the desired <code>Char</code> value.
* @return the <code>Char</code> value at the specified index.
* @throws IndexOutOfBoundsException if <code>index</code> is
* negative or greater than or equal to <code>length()</code>.
*/
def charAt(index: Int): Char = {
if (index < 0 || index >= count)
throw new StringIndexOutOfBoundsException//(index)
array(index)
}
/** Same as <code>charAt</code>. */
def apply(i: Int): Char = charAt(i)
/** <p>
* Removes the <code>Char</code> at the specified position in this
* sequence. This sequence is shortened by one <code>Char</code>.
* </p>
*
* @param index Index of <code>Char</code> to remove
* @return This object.
* @throws StringIndexOutOfBoundsException if the <code>index</code>
* is negative or greater than or equal to <code>length()</code>.
*/
def deleteCharAt(index: Int): StringBuilder = {
if (index < 0 || index >= count)
throw new StringIndexOutOfBoundsException//(index)
compat.Platform.arraycopy(array, index + 1, array, index, count - index - 1)
count -= 1
this
}
/** <p>
* The character at the specified index is set to <code>ch</code>. This
* sequence is altered to represent a new character sequence that is
* identical to the old character sequence, except that it contains the
* character <code>ch</code> at position <code>index</code>.
* </p>
* <p>
* The index argument must be greater than or equal to
* <code>0</code>, and less than the length of this sequence.
* </p>
*
* @param index the index of the character to modify.
* @param ch the new character.
* @throws IndexOutOfBoundsException if <code>index</code> is
* negative or greater than or equal to <code>length()</code>.
*/
def setCharAt(index: Int, ch: Char) {
if (index < 0 || index >= count)
throw new StringIndexOutOfBoundsException//(index)
array(index) = ch
}
/** Same as <code>setCharAt</code>. */
def update(i: Int, c: Char) { setCharAt(i, c) }
/** Returns a new <code>String</code> that contains a subsequence of
* characters currently contained in this character sequence. The
* substring begins at the specified index and extends to the end of
* this sequence.
*
* @param start The beginning index, inclusive.
* @return The new string.
* @throws StringIndexOutOfBoundsException if <code>start</code> is
* less than zero, or greater than the length of this object.
*/
def substring(start: Int): String = substring(start, count)
/** Returns a new <code>String</code> that contains a subsequence of
* characters currently contained in this sequence. The
* substring begins at the specified <code>start</code> and
* extends to the character at index <code>end - 1</code>.
*
* @param start The beginning index, inclusive.
* @param end The ending index, exclusive.
* @return The new string.
* @throws StringIndexOutOfBoundsException if <code>start</code>
* or <code>end</code> are negative or greater than
* <code>length()</code>, or <code>start</code> is
* greater than <code>end</code>.
*/
def substring(start: Int, end: Int): String = {
if (start < 0)
throw new StringIndexOutOfBoundsException//(start)
if (end > count)
throw new StringIndexOutOfBoundsException//(end)
if (start > end)
throw new StringIndexOutOfBoundsException//(end - start)
new String(array, start, end - start)
}
// def subSequence(start: Int, end: Int): java.lang.CharSequence = substring(start, end)
/* Appends the string representation of the <code>Any</code> argument.
*/
def +=(x: Char): this.type = { append(x); this }
def +(x: Char): this.type = { +=(x); this }
/** <p>
* Appends the string representation of the <code>Any</code>
* argument.
* </p>
* <p>
* The argument is converted to a string as if by the method
* <code>System.Convert.ToString</code>, and the characters of that
* string are then appended to this sequence.
* </p>
*
* @param x an <code>Any</code> object.
* @return a reference to this object.
*/
def append(x: Any): StringBuilder =
append(System.Convert.ToString(x))
/** Appends the specified string to this character sequence.
*
* @param s a string.
* @return a reference to this object.
*/
def append(s: String): StringBuilder = {
val str = if (s == null) "null" else s
val len = str.length
ensureCapacity(count + len)
compat.Platform.arraycopy(str.ToCharArray, 0, array, count, len)
count += len
this
}
/** Appends the specified string builder to this sequence.
*
* @param sb
* @return
*/
def append(sb: StringBuilder): StringBuilder =
if (sb == null)
append("null")
else {
val len = sb.length
ensureCapacity(count + len)
compat.Platform.arraycopy(sb.toArray, 0, array, count, len)
count += len
this
}
/** <p>
* Appends the string representation of the <code>Char</code> sequence
* argument to this sequence.
* </p>
* <p>
* The characters of the sequence argument are appended, in order,
* to the contents of this sequence. The length of this sequence
* increases by the length of the argument.
* </p>
*
* @param x the characters to be appended.
* @return a reference to this object.
*/
def appendAll(x: Seq[Char]): StringBuilder =
appendAll(x.toArray, 0, x.length)
/* @deprecated use appendAll instead. This method is deprecated
* because of the possible confusion with `append(Any)`.
*/
@deprecated def append(x: Seq[Char]): StringBuilder =
appendAll(x)
/** <p>
* Appends the string representation of the <code>Char</code> array
* argument to this sequence.
* </p>
* <p>
* The characters of the array argument are appended, in order, to
* the contents of this sequence. The length of this sequence
* increases by the length of the argument.
* </p>
*
* @param x the characters to be appended.
* @return a reference to this object.
*/
def appendAll(x: Array[Char]): StringBuilder =
appendAll(x, 0, x.length)
/** @deprecated use appendAll instead. This method is deprecated
* because of the possible confusion with `append(Any)`.
*/
@deprecated def append(x: Array[Char]): StringBuilder =
appendAll(x)
/** <p>
* Appends the string representation of a subarray of the
* <code>char</code> array argument to this sequence.
* </p>
* <p>
* Characters of the <code>Char</code> array <code>x</code>, starting at
* index <code>offset</code>, are appended, in order, to the contents
* of this sequence. The length of this sequence increases
* by the value of <code>len</code>.
* </p>
*
* @param x the characters to be appended.
* @param offset the index of the first <code>Char</code> to append.
* @param len the number of <code>Char</code>s to append.
* @return a reference to this object.
*/
def appendAll(x: Array[Char], offset: Int, len: Int): StringBuilder = {
ensureCapacity(count + len)
compat.Platform.arraycopy(x, offset, array, count, len)
count += len
this
}
/** @deprecated use appendAll instead. This method is deprecated
* because of the possible confusion with `append(Any, Int, Int)`.
*/
@deprecated def append(x: Array[Char], offset: Int, len: Int): StringBuilder =
appendAll(x, offset, len)
/** <p>
* Appends the string representation of the <code>Boolean</code>
* argument to the sequence.
* </p>
* <p>
* The argument is converted to a string as if by the method
* <code>System.Convert.ToString</code>, and the characters of that
* string are then appended to this sequence.
* </p>
*
* @param x a <code>Boolean</code>.
* @return a reference to this object.
*/
def append(x: Boolean): StringBuilder = append(System.Convert.ToString(x))
// def append(x: Byte): StringBuilder = append(System.Convert.ToString(x))
def append(x: Char): StringBuilder = {
ensureCapacity(count + 1)
array(count) = x
count += 1
this
}
def append(x: Short): StringBuilder =
append(System.Convert.ToString(x))
def append(x: Int): StringBuilder =
append(System.Convert.ToString(x))
def append(x: Long): StringBuilder =
append(System.Convert.ToString(x))
def append(x: Float): StringBuilder =
append(System.Convert.ToString(x))
def append(x: Double): StringBuilder =
append(System.Convert.ToString(x))
/** Removes the characters in a substring of this sequence.
* The substring begins at the specified <code>start</code> and extends to
* the character at index <code>end - 1</code> or to the end of the
* sequence if no such character exists. If
* <code>start</code> is equal to <code>end</code>, no changes are made.
*
* @param start The beginning index, inclusive.
* @param end The ending index, exclusive.
* @return This object.
* @throws StringIndexOutOfBoundsException if <code>start</code>
* is negative, greater than <code>length()</code>, or
* greater than <code>end</code>.
*/
def delete(start: Int, end: Int): StringBuilder = {
if (start < 0 || start > end)
throw new StringIndexOutOfBoundsException//(start)
val end0 = if (end > count) count else end
val len = end0 - start
if (len > 0) {
compat.Platform.arraycopy(array, start + len, array, start, count - end0)
count -= len
}
this
}
/** Replaces the characters in a substring of this sequence
* with characters in the specified <code>String</code>. The substring
* begins at the specified <code>start</code> and extends to the character
* at index <code>end - 1</code> or to the end of the sequence if no such
* character exists. First the characters in the substring are removed and
* then the specified <code>String</code> is inserted at <code>start</code>.
*
* @param start The beginning index, inclusive.
* @param end The ending index, exclusive.
* @param str String that will replace previous contents.
* @return This object.
* @throws StringIndexOutOfBoundsException if <code>start</code>
* is negative, greater than <code>length()</code>, or
* greater than <code>end</code>.
*/
def replace(start: Int, end: Int, str: String) {
if (start < 0 || start > count || start > end)
throw new StringIndexOutOfBoundsException//(start)
val end0 = if (end > count) count else end
val len = str.length()
val newCount = count + len - (end0 - start)
ensureCapacity(newCount)
compat.Platform.arraycopy(array, end, array, start + len, count - end)
compat.Platform.arraycopy(str.ToCharArray, 0, array, start, len)
count = newCount
this
}
/** Inserts the string representation of a subarray of the <code>str</code>
* array argument into this sequence. The subarray begins at the specified
* <code>offset</code> and extends <code>len</code> <code>char</code>s.
* The characters of the subarray are inserted into this sequence at
* the position indicated by <code>index</code>. The length of this
* sequence increases by <code>len</code> <code>Char</code>s.
*
* @param index position at which to insert subarray.
* @param str a <code>Char</code> array.
* @param offset the index of the first <code>char</code> in subarray to
* be inserted.
* @param len the number of <code>Char</code>s in the subarray to
* be inserted.
* @return This object
* @throws StringIndexOutOfBoundsException if <code>index</code>
* is negative or greater than <code>length()</code>, or
* <code>offset</code> or <code>len</code> are negative, or
* <code>(offset+len)</code> is greater than
* <code>str.length</code>.
*/
def insertAll(index: Int, str: Array[Char], offset: Int, len: Int): StringBuilder = {
if (index < 0 || index > count)
throw new StringIndexOutOfBoundsException//(index)
if (offset < 0 || len < 0 || offset > str.length - len)
throw new StringIndexOutOfBoundsException//(
// "offset " + offset + ", len " + len +
// ", str.length " + str.length)
ensureCapacity(count + len)
compat.Platform.arraycopy(array, index, array, index + len, count - index)
compat.Platform.arraycopy(str, offset, array, index, len)
count += len
this
}
/** @deprecated use insertAll instead. This method is deprecated
* because of the possible confusion with `insert(Int, Any, Int, Int)`.
*/
@deprecated def insert(index: Int, str: Array[Char], offset: Int, len: Int): StringBuilder =
insertAll(index, str, offset, len)
/** <p>
* Inserts the string representation of the <code>Any</code>
* argument into this character sequence.
* </p>
* <p>
* The second argument is converted to a string as if by the method
* <code>System.Convert.ToString</code>, and the characters of that
* string are then inserted into this sequence at the indicated
* offset.
* </p>
* <p>
* The offset argument must be greater than or equal to
* <code>0</code>, and less than or equal to the length of this
* sequence.
* </p>
*
* @param offset the offset.
* @param x an <code>Any</code> value.
* @return a reference to this object.
* @throws StringIndexOutOfBoundsException if the offset is invalid.
*/
def insert(at: Int, x: Any): StringBuilder =
insert(at, System.Convert.ToString(x))
/** Inserts the string into this character sequence.
*
* @param at the offset position.
* @param x a string.
* @return a reference to this object.
* @throws StringIndexOutOfBoundsException if the offset is invalid.
*/
def insert(at: Int, x: String): StringBuilder = {
if (at < 0 || at > count)
throw new StringIndexOutOfBoundsException//(at)
val str = if (x == null) "null" else x
val len = str.length
ensureCapacity(count + len)
compat.Platform.arraycopy(array, at, array, at + len, count - at)
compat.Platform.arraycopy(str.ToCharArray, 0, array, at, len)
count += len
this
}
/** Inserts the string representation of the <code>Char</code> sequence
* argument into this sequence.
*
* @param at the offset position.
* @param x a character sequence.
* @return a reference to this object.
* @throws StringIndexOutOfBoundsException if the offset is invalid.
*/
def insertAll(at: Int, x: Seq[Char]): StringBuilder =
insertAll(at, x.toArray)
/* @deprecated use insertAll instead. This method is deprecated
* because of the possible confusion with `insert(Int, Any)`.
*/
@deprecated def insert(at: Int, x: Seq[Char]): StringBuilder =
insertAll(at, x)
/** Inserts the string representation of the <code>Char</code> array
* argument into this sequence.
*
* @param at the offset position.
* @param x a character array.
* @return a reference to this object.
* @throws StringIndexOutOfBoundsException if the offset is invalid.
*/
def insertAll(at: Int, x: Array[Char]): StringBuilder = {
if (at < 0 || at > count)
throw new StringIndexOutOfBoundsException//(at)
val len = x.length
ensureCapacity(count + len)
compat.Platform.arraycopy(array, at, array, at + len, count - at)
compat.Platform.arraycopy(x, 0, array, at, len)
count += len
this
}
/* @deprecated use insertAll instead. This method is deprecated
* because of the possible confusion with `insert(Int, Any)`.
*/
@deprecated def insert(at: Int, x: Array[Char]): StringBuilder =
insertAll(at, x)
/** <p>
* Inserts the string representation of the <code>Boolean</code> argument
* into this sequence.
* </p>
* <p>
* The offset argument must be greater than or equal to 0, and less than
* or equal to the length of this sequence.
* </p>
*
* @param at the offset position.
* @param x a <code>Boolean</code> value.
* @return a reference to this object.
*/
def insert(at: Int, x: Boolean): StringBuilder =
insert(at, System.Convert.ToString(x))
/** <p>
* Inserts the string representation of the <code>Byte</code> argument
* into this sequence.
* </p>
* <p>
* The offset argument must be greater than or equal to 0, and less than
* or equal to the length of this sequence.
* </p>
*
* @param at the offset position.
* @param x a <code>Byte</code> value.
* @return a reference to this object.
*/
// def insert(at: Int, x: Byte): StringBuilder =
// insert(at, System.Convert.ToString(x))
/** <p>
* Inserts the string representation of the <code>Char</code> argument
* into this sequence.
* </p>
* <p>
* The offset argument must be greater than or equal to 0, and less than
* or equal to the length of this sequence.
* </p>
*
* @param at the offset position.
* @param x a <code>Char</code> value.
* @return a reference to this object.
*/
def insert(at: Int, x: Char): StringBuilder = {
if (at < 0 || at > count)
throw new StringIndexOutOfBoundsException//(at)
ensureCapacity(count + 1)
compat.Platform.arraycopy(array, at, array, at + 1, count - at)
array(at) = x
count += 1
this
}
/** <p>
* Inserts the string representation of the <code>Short</code> argument
* into this sequence.
* </p>
* <p>
* The offset argument must be greater than or equal to 0, and less than
* or equal to the length of this sequence.
* </p>
*
* @param at the offset position.
* @param x a <code>Short</code> value.
* @return a reference to this object.
*/
def insert(at: Int, x: Short): StringBuilder =
insert(at, System.Convert.ToString(x))
/** <p>
* Inserts the string representation of the <code>Int</code> argument
* into this sequence.
* </p>
* <p>
* The offset argument must be greater than or equal to 0, and less than
* or equal to the length of this sequence.
* </p>
*
* @param at the offset position.
* @param x a <code>Int</code> value.
* @return a reference to this object.
*/
def insert(at: Int, x: Int): StringBuilder =
insert(at, System.Convert.ToString(x))
/** <p>
* Inserts the string representation of the <code>Long</code> argument
* into this sequence.
* </p>
* <p>
* The offset argument must be greater than or equal to 0, and less than
* or equal to the length of this sequence.
* </p>
*
* @param at the offset position.
* @param x a <code>Long</code> value.
* @return a reference to this object.
*/
def insert(at: Int, x: Long): StringBuilder =
insert(at, System.Convert.ToString(x))
/** <p>
* Inserts the string representation of the <code>Float</code> argument
* into this sequence.
* </p>
* <p>
* The offset argument must be greater than or equal to 0, and less than
* or equal to the length of this sequence.
* </p>
*
* @param at the offset position.
* @param x a <code>Float</code> value.
* @return a reference to this object.
*/
def insert(at: Int, x: Float): StringBuilder =
insert(at, System.Convert.ToString(x))
/** <p>
* Inserts the string representation of the <code>Double</code> argument
* into this sequence.
* </p>
* <p>
* The offset argument must be greater than or equal to 0, and less than
* or equal to the length of this sequence.
* </p>
*
* @param at the offset position.
* @param x a <code>Double</code> value.
* @return a reference to this object.
*/
def insert(at: Int, x: Double): StringBuilder =
insert(at, System.Convert.ToString(x))
/** <p>
* Returns the index within this string of the first occurrence of the
* specified substring. The integer returned is the smallest value
* <i>k</i> such that:
* </p>
* <blockquote><pre>
* this.toString().startsWith(str, <i>k</i>)</pre>
* </blockquote>
* <p>
* is <code>true</code>.
* </p>
*
* @param str any string.
* @return if the string argument occurs as a substring within this
* object, then the index of the first character of the first
* such substring is returned; if it does not occur as a
* substring, <code>-1</code> is returned.
* @throws NullPointerException if <code>str</code> is <code>null</code>.
*/
def indexOf(str: String): Int = indexOf(str, 0)
/** <p>
* Returns the index within this string of the first occurrence of the
* specified substring, starting at the specified index. The integer
* returned is the smallest value <code>k</code> for which:
* </p><pre>
* k >= Math.min(fromIndex, str.length()) &&
* this.toString().startsWith(str, k)</pre>
* <p>
* If no such value of <code>k</code> exists, then <code>-1</code>
* is returned.
* </p>
*
* @param str the substring for which to search.
* @param fromIndex the index from which to start the search.
* @return the index within this string of the first occurrence
* of the specified substring, starting at the specified index.
*/
def indexOf(str: String, fromIndex: Int): Int =
StringBuilder.indexOf(array, 0, count, str.ToCharArray, 0, str.length(), fromIndex)
/** <p>
* Returns the index within this string of the rightmost occurrence
* of the specified substring. The rightmost empty string "" is
* considered to occur at the index value <code>this.length()</code>.
* The returned index is the largest value <i>k</i> such that
* </p>
* <blockquote><pre>
* this.toString().startsWith(str, k)</pre>
* </blockquote>
* <p>
* is true.
* </p>
*
* @param str the substring to search for.
* @return if the string argument occurs one or more times as a substring
* within this object, then the index of the first character of
* the last such substring is returned. If it does not occur as
* a substring, <code>-1</code> is returned.
* @throws NullPointerException if <code>str</code> is <code>null</code>.
*/
def lastIndexOf(str: String): Int = lastIndexOf(str, count)
/** <p>
* Returns the index within this string of the last occurrence of the
* specified substring. The integer returned is the largest value
* <code>k</code> such that:
* </p><pre>val
* k <= Math.min(fromIndex, str.length()) &&
* this.toString().startsWith(str, k)</pre>
* <p>
* If no such value of <code>k</code> exists, then <code>-1</code>
* is returned.
* </p>
*
* @param str the substring to search for.
* @param fromIndex the index to start the search from.
* @return the index within this sequence of the last occurrence
* of the specified substring.
*/
def lastIndexOf(str: String, fromIndex: Int): Int =
StringBuilder.lastIndexOf(array, 0, count, str.ToCharArray, 0, str.length(), fromIndex)
/** <p>
* Causes this character sequence to be replaced by the reverse of the
* sequence. If there are any surrogate pairs included in the sequence,
* these are treated as single characters for the reverse operation.
* Thus, the order of the high-low surrogates is never reversed.
* </p>
* <p>
* Let <i>n</i> be the character length of this character sequence
* (not the length in <code>Char</code> values) just prior to
* execution of the <code>reverse</code> method. Then the
* character at index <i>k</i> in the new character sequence is
* equal to the character at index <i>n-k-1</i> in the old
* character sequence.
* </p>
*
* @return a reference to this object.
*/
override def reverse(): StringBuilder = {
var hasSurrogate = false
val n = count - 1
var j = (n-1) >> 1
while (j >= 0) {
val temp = array(j)
val temp2 = array(n - j)
if (!hasSurrogate)
hasSurrogate =
(temp >= StringBuilder.MIN_SURROGATE && temp <= StringBuilder.MAX_SURROGATE) ||
(temp2 >= StringBuilder.MIN_SURROGATE && temp2 <= StringBuilder.MAX_SURROGATE)
array(j) = temp2
array(n - j) = temp
j -= 1
}
if (hasSurrogate) {
// Reverse back all valid surrogate pairs
var i = 0
while (i < count - 1) {
val c2 = array(i)
if (StringBuilder.isLowSurrogate(c2)) {
val c1 = array(i + 1)
if (StringBuilder.isHighSurrogate(c1)) {
array(i) = c1; i += 1
array(i) = c2
}
}
i += 1
}
}
this
}
/** Returns a string representing the data in this sequence.
* A new <code>String</code> object is allocated and initialized to
* contain the character sequence currently represented by this
* object. This <code>String</code> is then returned. Subsequent
* changes to this sequence do not affect the contents of the
* <code>String</code>.
*
* @return a string representation of this sequence of characters.
*/
override def toString: String = new String(array, 0, count)
def result(): String = toString
}
object StringBuilder
{
private val MIN_HIGH_SURROGATE = '\uD800'
private val MAX_HIGH_SURROGATE = '\uDBFF'
private val MIN_LOW_SURROGATE = '\uDC00'
private val MAX_LOW_SURROGATE = '\uDFFF'
// constants <code>java.langCharacter.MIN-/MAX_SURROGATE</code> exist since 1.5
private val MIN_SURROGATE = MIN_HIGH_SURROGATE
private val MAX_SURROGATE = MAX_LOW_SURROGATE
// methods <code>java.langCharacter.isLow-/isHighSurrogate</code> exist since 1.5
private def isLowSurrogate(ch: Char): Boolean =
MIN_LOW_SURROGATE <= ch && ch <= MAX_LOW_SURROGATE
private def isHighSurrogate(ch: Char): Boolean =
MIN_HIGH_SURROGATE <= ch && ch <= MAX_HIGH_SURROGATE
// method <code>java.util.Arrays.copyOf</code> exists since 1.6
private def copyOf(src: Array[Char], newLength: Int): Array[Char] = {
val dest = new Array[Char](newLength)
compat.Platform.arraycopy(src, 0, dest, 0, Math.min(src.length, newLength))
dest
}
private def indexOf(source: Array[Char], sourceOffset: Int, sourceCount: Int,
target: Array[Char], targetOffset: Int, targetCount: Int,
fromIndex: Int): Int =
// todo: There are faster string search algorithms than this!
// we should use at least KMP here.
if (fromIndex >= sourceCount)
if (targetCount == 0) sourceCount else -1
else {
val inx = if (fromIndex < 0) 0 else fromIndex
if (targetCount == 0)
inx
else {
val first = target(targetOffset)
val max = sourceOffset + (sourceCount - targetCount)
var i = sourceOffset + inx
while (i <= max) {
/* Look for first character. */
if (source(i) != first) {
i += 1
while (i <= max && source(i) != first) i += 1
}
/* Found first character, now look at the rest of v2 */
if (i <= max) {
var j = i + 1
val end = j + targetCount - 1
var k = targetOffset + 1
while (j < end && source(j) == target(k)) {
j += 1
k += 1
}
if (j == end) {
/* Found whole string. */
return i - sourceOffset
}
} // if
i += 1
} // while
-1
}
}
private def lastIndexOf(source: Array[Char], sourceOffset: Int, sourceCount: Int,
target: Array[Char], targetOffset: Int, targetCount: Int,
fromIndex: Int): Int = {
val rightIndex = sourceCount - targetCount
if (fromIndex < 0) return -1
val inx = if (fromIndex > rightIndex) rightIndex else fromIndex
// Empty string always matches
if (targetCount == 0) return inx
val strLastIndex = targetOffset + targetCount - 1
val strLastChar = target(strLastIndex)
val min = sourceOffset + targetCount - 1
var i = min + fromIndex
while (true) {
while (i >= min && source(i) != strLastChar) i -= 1
if (i < min) return -1
var j = i - 1
val start = j - (targetCount - 1)
var k = strLastIndex - 1
var outerWhile = false
while (j > start && !outerWhile) {
if (source(j) != target(k)) {
j -= 1
k -= 1
i -= 1
outerWhile = true
}
}
if (!outerWhile) return start - sourceOffset + 1
}
-1
}
}

View File

@ -1 +0,0 @@
/* WeakHashMap does not exist for the dotnet target */

View File

@ -1,63 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
package scala.compat
import Predef._
object Platform {
type StackOverflowError = System.StackOverflowException
type ConcurrentModificationException = System.Exception
/**
* @param src ..
* @param srcPos ..
* @param dest ..
* @param destPos ..
* @param length ..
*/
def arraycopy(src: AnyRef, srcPos: Int, dest: AnyRef, destPos: Int, length: Int) {
if (!src.isInstanceOf[System.Array]) throw new Exception("src for arraycopy is not an Array; use scala.Array.copy for boxed arrays");
if (!dest.isInstanceOf[System.Array]) throw new Exception("dest for arraycopy is not an Array; use scala.Array.copy for boxed arrays");
System.Array.Copy(src.asInstanceOf[System.Array], srcPos, dest.asInstanceOf[System.Array], destPos, length)
}
/** Create array of the same type as arrayInstance with the given
* length.
*
* @param elemClass ..
* @param length ..
* @return ..
*/
def createArray(elemClass: Class[_], length: Int): AnyRef =
System.Array.CreateInstance(elemClass, length)
def arrayclear(arr: Array[Int]) {
System.Array.Clear(arr.asInstanceOf[System.Array], 0, arr.length)
}
def getClassForName(name: String): Class[_] = System.Type.GetType(name)
val EOL = System.Environment.NewLine
def currentTime: Long = 0L
/* // compiler crash :-(
private lazy val baseTicks = (new System.DateTime(1970, 1, 1, 0, 0, 0)).Ticks
def currentTime: Long = {
val nowTicks = System.DateTime.UtcNow.Ticks
(nowTicks - baseTicks) / 10000
}
*/
def collectGarbage { System.GC.Collect() }
}

View File

@ -1 +0,0 @@
/* DelayedLazyVal does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* jolib does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* ops does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* pilib does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* BufferedSource.scala does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* BytePickle.scala does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* Codec.scala does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* Position.scala does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* Source.scala does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* UTF8Codec.scala does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* Code.scala does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* Location.scala does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* Utility does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* PhantomReference does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* ReferenceQueue does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* ReferenceWrapper does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* SoftReference does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* WeakReference does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* Invocation.scala does not exist for the dotnet target */

View File

@ -1,157 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2007-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
package scala.reflect
/** <p>
* A <code>Manifest[T]</code> is an opaque descriptor for type <code>T</code>.
* Currently, its only use is to give access to the erasure of the type as a
* <code>Class</code> instance.
* </p>
* <p>
* <b>BE AWARE</b>: The different type-relation operators are all forwarded
* to the erased type as an approximation of the final semantics where
* these operators should be on the unerased type.
* </p>
*/
trait Manifest[T] extends OptManifest[T] {
/** A class representing the type U to which T would be erased. Note
* that there is no subtyping relationship between T and U. */
def erasure: Predef.Class[U] forSome { type U }
/** Tests whether the type represented by this manifest is a subtype of
* the type represented by `that' manifest. BE AWARE: the current
* implementation is an approximation, as the test is done on the
* erasure of the type. */
def <:<(that: Manifest[_]): Boolean = {
def subtype(sub: Predef.Class[_], sup: Predef.Class[_]): Boolean = {
val subSuperClass = sub.BaseType
val subSuperInterfaces = sub.GetInterfaces.toList
val subSuper =
(if (subSuperClass == null) Nil else List(subSuperClass)) ::: subSuperInterfaces
(subSuper contains sup) || (subSuper exists (subtype(_, sup)))
}
this.erasure == that.erasure || subtype(this.erasure, that.erasure)
}
/** Tests whether the type represented by this manifest is a supertype
* of the type represented by `that' manifest. BE AWARE: the current
* implementation is an approximation, as the test is done on the
* erasure of the type. */
def >:>(that: Manifest[_]): Boolean =
that <:< this
/** Tests whether the type represented by this manifest is equal to the
* type represented by `that' manifest. BE AWARE: the current
* implementation is an approximation, as the test is done on the
* erasure of the type. */
override def equals(that: Any): Boolean = that match {
case m:Manifest[_] => this.erasure == m.erasure
case _ => false
}
private[reflect] def typeArguments: Option[List[Manifest[_]]] = None
}
/** <p>
* This object is used by the compiler and <b>should not be used in client
* code</b>. The object <code>Manifest</code> defines factory methods for
* manifests.
* </p>
* <p>
* <b>BE AWARE</b>: The factory for refinement types is missing and
* will be implemented in a later version of this class.
* </p>
*/
object Manifest {
/** Manifest for the singleton type `value.type'. */
def singleType[T](value: Any): Manifest[T] =
new Manifest[T] {
lazy val erasure =
value match {
case anyRefValue: AnyRef => anyRefValue.GetType
case anyValue => error("There is no singleton type for AnyVal values")
}
override lazy val toString = value.toString + ".type"
}
/** Manifest for the class type `clazz', where `clazz' is
* a top-level or static class. */
def classType[T](clazz: Predef.Class[T]): Manifest[T] =
new Manifest[T] {
val erasure = clazz
override lazy val toString = erasure.getName
}
/** Manifest for the class type `clazz[args]', where `clazz' is
* a top-level or static class. */
def classType[T](clazz: Predef.Class[_], args: Manifest[_]*): Manifest[T] =
new Manifest[T] {
val erasure = clazz
private[reflect] override val typeArguments = Some(args.toList)
override def <:<(that: Manifest[_]): Boolean = {
that.typeArguments match {
case Some(thatArgs) =>
super.<:<(that) && args.equalsWith(thatArgs) { (x, y) => x <:< y }
case None =>
false
}
}
override lazy val toString =
(if (erasure.isArray) "Array" else erasure.getName) +
args.toList.mkString("[", ", ", "]")
}
/** Manifest for the class type `prefix # clazz'. */
def classType[T](prefix: Manifest[_], clazz: Predef.Class[_]): Manifest[T] =
new Manifest[T] {
val erasure = clazz
override lazy val toString = prefix.toString + "#" + clazz.getName
}
/** Manifest for the class type `prefix # clazz[args]'. */
def classType[T](prefix: Manifest[_], clazz: Predef.Class[_], args: Manifest[_]*): Manifest[T] =
new Manifest[T] {
val erasure = clazz
private[reflect] override val typeArguments = Some(args.toList)
override lazy val toString =
prefix.toString + "#" + erasure.getName + typeArguments.mkString("[", ", ", "]")
}
/** Manifest for the abstract type `prefix # name'. `upperBound' is not
* strictly necessary as it could be obtained by reflection. It was
* added so that erasure can be calculated without reflection. */
def abstractType[T](prefix: Manifest[_], name: String, upperBound: Manifest[_]): Manifest[T] =
new Manifest[T] {
lazy val erasure = upperBound.erasure
override lazy val toString = prefix.toString + "#" + name
}
/** Manifest for the abstract type `prefix # name[args]'. */
def abstractType[T](prefix: Manifest[_], name: String, upperBound: Manifest[_], args: Manifest[_]*): Manifest[T] =
new Manifest[T] {
lazy val erasure = upperBound.erasure
private[reflect] override val typeArguments = Some(args.toList)
override lazy val toString =
prefix.toString + "#" + name + typeArguments.mkString("[", ", ", "]")
}
/** Manifest for the intersection type `parents_0 with ... with parents_n'. */
def intersectionType[T](parents: Manifest[_]*): Manifest[T] =
new Manifest[T] {
lazy val erasure = parents.first.erasure
override lazy val toString = parents.mkString(" with ")
}
}

View File

@ -1 +0,0 @@
/* ScalaBeanInfo does not exist for the dotnet target */

View File

@ -1,22 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
namespace scala.runtime {
using System;
[Serializable]
public class BooleanRef {
public bool elem;
public BooleanRef(bool elem) { this.elem = elem; }
override public string ToString() { return elem.ToString(); }
}
}

View File

@ -1,36 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
namespace scala.runtime {
using System;
[Serializable]
public sealed class BoxedUnit {
public static readonly BoxedUnit UNIT = new BoxedUnit();
private BoxedUnit() { }
override public bool Equals(object other) {
return this == other;
}
override public int GetHashCode() {
return 0;
}
override public string ToString() {
return "()";
}
}
}

View File

@ -1,22 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
namespace scala.runtime {
using System;
[Serializable]
public class ByteRef {
public byte elem;
public ByteRef(byte elem) { this.elem = elem; }
override public string ToString() { return elem.ToString(); }
}
}

View File

@ -1,22 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
namespace scala.runtime {
using System;
[Serializable]
public class CharRef {
public char elem;
public CharRef(char elem) { this.elem = elem; }
override public string ToString() { return elem.ToString(); }
}
}

View File

@ -1,51 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
namespace scala.runtime {
using System;
public class Comparator {
public static bool equals(object a, object b) {
if (a == null)
return b == null;
if (a.Equals(b))
return true;
if (a == b)
return true;
IConvertible aa = a as IConvertible;
IConvertible bb = b as IConvertible;
// We must check if a and b are realy convertible to numbers, because
// String is also an implementation of IConvertible...
// So we can avoid having "12" == 12 returning true !!
if((a is Decimal || a is Double || a is Single || a is Byte
|| a is SByte || a is Int16 || a is UInt16 || a is Int32
|| a is UInt32 || a is Int64 || a is UInt64)
&& (b is Decimal || b is Double || b is Single || b is Byte
|| b is SByte || b is Int16 || b is UInt16 || b is Int32
|| b is UInt32 || b is Int64 || b is UInt64)){
if (aa != null && bb != null) {
if (a is Decimal || b is Decimal)
return aa.ToDecimal(null) == bb.ToDecimal(null);
if (a is Double || b is Double)
return aa.ToDouble(null) == bb.ToDouble(null);
if (a is Single || b is Single)
return aa.ToSingle(null) == bb.ToSingle(null);
if (a is Int64 || b is Int64)
return aa.ToInt64(null) == bb.ToInt64(null);
return aa.ToInt32(null) == bb.ToInt32(null);
}
}
return false;
}
}
}

View File

@ -1,22 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
namespace scala.runtime {
using System;
[Serializable]
public class DoubleRef {
public double elem;
public DoubleRef(double elem) { this.elem = elem; }
override public string ToString() { return elem.ToString(); }
}
}

View File

@ -1,27 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
namespace scala.runtime {
using System;
public abstract class ExceptionHandling {
public static Exception tryCatch(Runnable runnable) {
try {
runnable.run();
return null;
} catch (Exception exception) {
return exception;
}
}
}
}

View File

@ -1,22 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
namespace scala.runtime {
using System;
[Serializable]
public class FloatRef {
public float elem;
public FloatRef(float elem) { this.elem = elem; }
override public string ToString() { return elem.ToString(); }
}
}

View File

@ -1,22 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
namespace scala.runtime {
using System;
[Serializable]
public class IntRef {
public int elem;
public IntRef(int elem) { this.elem = elem; }
override public string ToString() { return elem.ToString(); }
}
}

View File

@ -1,22 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
namespace scala.runtime {
using System;
[Serializable]
public class LongRef {
public long elem;
public LongRef(long elem) { this.elem = elem; }
override public string ToString() { return elem.ToString(); }
}
}

View File

@ -1 +0,0 @@
/* MethodCache does not exist for the dotnet target */

View File

@ -1,17 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
package scala.runtime
import Predef.RuntimeException
class NonLocalReturnException[T](val key: AnyRef, val value: T) extends RuntimeException

View File

@ -1,22 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
namespace scala.runtime {
using System;
[Serializable]
public class ObjectRef {
public Object elem;
public ObjectRef(Object elem) { this.elem = elem; }
override public string ToString() { return "" + elem; }
}
}

View File

@ -1,74 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2006-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
package scala.runtime
//import java.lang.Character
import collection.Vector
import collection.generic.VectorView
import Predef.{require, NoSuchElementException}
/** <p>
* For example, in the following code
* </p>
* <pre>
* <b>object</b> test <b>extends</b> Application {
* Console.println(<chr>'\40'</chr>.isWhitespace)
* Console.println('\011'.isWhitespace)
* Console.println('1'.asDigit == 1)
* Console.println('A'.asDigit == 10)
* }</pre>
* <p>
* the implicit conversions are performed using the predefined view
* <a href="../Predef$object.html#charWrapper(scala.Char)"
* target="contentFrame"><code>Predef.charWrapper</code></a>.
* </p>
*/
final class RichChar(x: Char) extends Proxy with Ordered[Char] {
// Proxy.self
def self: Any = x
// Ordered[Char].compare
def compare (y: Char): Int = if (x < y) -1 else if (x > y) 1 else 0
def asDigit: Int = System.Char.GetNumericValue(x).toInt
def isControl: Boolean = System.Char.IsControl(x)
def isDigit: Boolean = System.Char.IsDigit(x)
def isLetter: Boolean = System.Char.IsLetter(x)
def isLetterOrDigit: Boolean = System.Char.IsLetterOrDigit(x)
def isLowerCase: Boolean = System.Char.IsLower(x)
def isUpperCase: Boolean = System.Char.IsUpper(x)
def isWhitespace: Boolean = System.Char.IsWhiteSpace(x)
def toLowerCase: Char = System.Char.ToLower(x)
def toUpperCase: Char = System.Char.ToUpper(x)
/** Create a <code>[Char]</code> over the characters from 'x' to 'y' - 1
*/
def until(limit: Char): VectorView[Char, Vector[Char]] =
if (limit <= x) Vector.empty.view
else
new VectorView[Char, Vector[Char]] {
protected def underlying = Vector.empty[Char]
def length = limit - x
def apply(i: Int): Char = {
require(i >= 0 && i < length)
(x + i).toChar
}
}
/** Create a <code>VectorView[Char]</code> over the characters from 'x' to 'y'
*/
def to(y: Char): VectorView[Char, Vector[Char]] = until((y + 1).toChar)
}

View File

@ -1,26 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
package scala.runtime
import Predef.Class
final class RichClass(val self: Class[_]) extends Proxy
{
def isPrimitive(): Boolean = self.IsPrimitive
def isArray(): Boolean = self.IsArray
def getClass(): RichClass = this
def getName(): String = self.Name
def getComponentType(): Class[_] = self.GetElementType
def isAssignableFrom(other: RichClass) = self.IsAssignableFrom(other.self)
}

View File

@ -1,52 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
package scala.runtime
final class RichDouble(x: Double) extends Proxy with Ordered[Double] {
// Proxy.self
def self: Any = x
// Ordered[Double].compare
def compare(y: Double): Int = if (x < y) -1 else if (x > y) 1 else 0
def min(y: Double): Double = Math.min(x, y)
def max(y: Double): Double = Math.max(x, y)
def abs: Double = Math.abs(x)
def round: Long = Math.round(x)
def ceil: Double = Math.ceil(x)
def floor: Double = Math.floor(x)
/** Converts an angle measured in degrees to an approximately equivalent
* angle measured in radians.
*
* @param x an angle, in degrees
* @return the measurement of the angle <code>x</code> in radians.
*/
def toRadians: Double = Math.toRadians(x)
/** Converts an angle measured in radians to an approximately equivalent
* angle measured in degrees.
*
* @param x angle, in radians
* @return the measurement of the angle <code>x</code> in degrees.
*/
def toDegrees: Double = Math.toDegrees(x)
def isNaN: Boolean = System.Double.IsNaN(x)
def isInfinity: Boolean = System.Double.IsInfinity(x)
def isPosInfinity: Boolean = System.Double.IsPositiveInfinity(x)
def isNegInfinity: Boolean = System.Double.IsNegativeInfinity(x)
}

View File

@ -1,21 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
package scala.runtime
final class RichException(exc: System.Exception) {
def printStackTrace() = System.Console.WriteLine(exc.StackTrace)
def getMessage() = exc.Message
def getStackTraceString: String = exc.StackTrace
}

View File

@ -1,54 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
package scala.runtime
import Predef._
final class RichFloat(x: Float) extends Proxy with Ordered[Float] {
// Proxy.self
def self: Any = x
// Ordered[Float].compare
def compare (y: Float): Int = if (x < y) -1 else if (x > y) 1 else 0
def min(y: Float) = Math.min(x, y)
def max(y: Float) = Math.max(x, y)
def abs: Float = Math.abs(x)
def round: Int = Math.round(x)
def ceil: Float = Math.ceil(x).toFloat
def floor: Float = Math.floor(x).toFloat
/** Converts an angle measured in degrees to an approximately equivalent
* angle measured in radians.
*
* @param x an angle, in degrees
* @return the measurement of the angle <code>x</code> in radians.
*/
def toRadians: Float = Math.toRadians(x).toFloat
/** Converts an angle measured in radians to an approximately equivalent
* angle measured in degrees.
*
* @param x angle, in radians
* @return the measurement of the angle <code>x</code> in degrees.
*/
def toDegrees: Float = Math.toDegrees(x).toFloat
def isNaN: Boolean = System.Single.IsNaN(x)
def isInfinity: Boolean = System.Single.IsInfinity(x)
def isPosInfinity: Boolean = System.Single.IsPositiveInfinity(x)
def isNegInfinity: Boolean = System.Single.IsNegativeInfinity(x)
}

View File

@ -1,36 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
package scala.runtime
final class RichInt(val start: Int) extends Proxy with Ordered[Int] {
// Proxy
def self: Any = start
// Ordered[Int]
def compare(that: Int): Int = if (start < that) -1 else if (start > that) 1 else 0
/** See <code>Iterator.range</code>. */
def until(end: Int, step: Int = 1): Range = new Range(start, end, step)
/** like <code>until</code>, but includes the last index */
def to(end: Int, step: Int = 1) = Range.inclusive(start, end, step)
def min(that: Int): Int = if (start < that) start else that
def max(that: Int): Int = if (start > that) start else that
def abs: Int = if (start < 0) -start else start
def toBinaryString: String = System.Convert.ToString(start, 2)
def toHexString: String = System.Convert.ToString(start, 16)
def toOctalString: String = System.Convert.ToString(start, 8)
}

View File

@ -1,30 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
package scala.runtime
final class RichLong(x: Long) extends Proxy with Ordered[Long] {
// Proxy.self
def self: Any = x
// Ordered[Long].compare
def compare(y: Long): Int = if (x < y) -1 else if (x > y) 1 else 0
def min(y: Long): Long = if (x < y) x else y
def max(y: Long): Long = if (x > y) x else y
def abs: Long = if (x < 0) -x else x
def toBinaryString: String = System.Convert.ToString(x, 2)
def toHexString: String = System.Convert.ToString(x, 16)
def toOctalString: String = System.Convert.ToString(x, 8)
}

View File

@ -1,218 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
package scala.runtime
//import scala.util.matching.Regex
import collection.generic._
//import collection.mutable.StringBuilder
import collection.immutable.Vector
object RichString {
def newBuilder: Builder[Char, RichString] = new StringBuilder() mapResult (new RichString(_))
implicit def builderFactory: BuilderFactory[Char, RichString, RichString] = new BuilderFactory[Char, RichString, RichString] { def apply(from: RichString) = newBuilder }
implicit def builderFactory2: BuilderFactory[Char, RichString, String] = new BuilderFactory[Char, RichString, String] { def apply(from: String) = newBuilder }
// just statics for rich string.
private final val LF: Char = 0x0A
private final val FF: Char = 0x0C
private final val CR: Char = 0x0D
private final val SU: Char = 0x1A
}
import RichString._
class RichString(val self: String) extends Proxy with Vector[Char] with VectorTemplate[Char, RichString] with PartialFunction[Int, Char] with Ordered[String] {
/** Creates a string builder buffer as builder for this class */
override protected[this] def newBuilder = RichString.newBuilder
/** Return element at index `n`
* @throws IndexOutofBoundsException if the index is not valid
*/
def apply(n: Int): Char = self charAt n
def length: Int = self.length
override def mkString = self
override def toString = self
/** return n times the current string
*/
def * (n: Int): String = {
val buf = new StringBuilder
for (i <- 0 until n) buf append self
buf.toString
}
override def compare(other: String) = self compareTo other
private def isLineBreak(c: Char) = c == LF || c == FF
/** <p>
* Strip trailing line end character from this string if it has one.
* A line end character is one of
* </p>
* <ul style="list-style-type: none;">
* <li>LF - line feed (0x0A hex)</li>
* <li>FF - form feed (0x0C hex)</li>
* </ul>
* <p>
* If a line feed character LF is preceded by a carriage return CR
* (0x0D hex), the CR character is also stripped (Windows convention).
* </p>
*/
def stripLineEnd: String = {
val len = self.length
if (len == 0) self
else {
val last = apply(len - 1)
if (isLineBreak(last))
self.substring(0, if (last == LF && len >= 2 && apply(len - 2) == CR) len - 2 else len - 1)
else
self
}
}
/** <p>
* Return all lines in this string in an iterator, including trailing
* line end characters.
* </p>
* <p>
* The number of strings returned is one greater than the number of line
* end characters in this string. For an empty string, a single empty
* line is returned. A line end character is one of
* </p>
* <ul style="list-style-type: none;">
* <li>LF - line feed (0x0A hex)</li>
* <li>FF - form feed (0x0C hex)</li>
* </ul>
*/
def linesWithSeparators = new Iterator[String] {
val len = self.length
var index = 0
def hasNext: Boolean = index < len
def next(): String = {
if (index >= len) throw new NoSuchElementException("next on empty iterator")
val start = index
while (index < len && !isLineBreak(apply(index))) index += 1
index += 1
self.substring(start, index min len)
}
}
/** Return all lines in this string in an iterator, excluding trailing line
* end characters, i.e. apply <code>.stripLineEnd</code> to all lines
* returned by <code>linesWithSeparators</code>.
*/
def lines: Iterator[String] =
linesWithSeparators map (line => new RichString(line).stripLineEnd)
/** Returns this string with first character converted to upper case */
def capitalize: String =
if (self == null) null
else if (self.length == 0) ""
else {
val chars = self.toCharArray
chars(0) = chars(0).toUpperCase
new String(chars)
}
/** <p>
* For every line in this string:
* </p>
* <blockquote>
* Strip a leading prefix consisting of blanks or control characters
* followed by <code>marginChar</code> from the line.
* </blockquote>
*/
def stripMargin(marginChar: Char): String = {
val buf = new StringBuilder
for (line <- linesWithSeparators) {
val len = line.length
var index = 0
while (index < len && line.charAt(index) <= ' ') index += 1
buf append
(if (index < len && line.charAt(index) == marginChar) line.substring(index + 1) else line)
}
buf.toString
}
/** <p>
* For every line in this string:
* </p>
* <blockquote>
* Strip a leading prefix consisting of blanks or control characters
* followed by <code>|</code> from the line.
* </blockquote>
*/
def stripMargin: String = stripMargin('|')
// private def escape(ch: Char): String = "\\Q" + ch + "\\E"
// @throws(classOf[java.util.regex.PatternSyntaxException])
// def split(separator: Char): Array[String] = self.split(escape(separator))
// @throws(classOf[java.util.regex.PatternSyntaxException])
// def split(separators: Array[Char]): Array[String] = {
// val re = separators.foldLeft("[")(_+escape(_)) + "]"
// self.split(re)
// }
/** You can follow a string with `.r', turning
* it into a Regex. E.g.
*
* """A\w*""".r is the regular expression for identifiers starting with `A'.
*/
// def r: Regex = new Regex(self)
def toBoolean: Boolean = System.Boolean.Parse(self)
def toByte: Byte = System.Byte.Parse(self)
def toShort: Short = System.Int16.Parse(self)
def toInt: Int = System.Int32.Parse(self)
def toLong: Long = System.Int64.Parse(self)
def toFloat: Float = System.Single.Parse(self)
def toDouble: Double = System.Double.Parse(self)
private def parseBoolean(s: String): Boolean =
if (s != null) s.toLowerCase match {
case "true" => true
case "false" => false
case _ => throw new NumberFormatException("For input string: \""+s+"\"")
}
else
throw new NumberFormatException("For input string: \"null\"")
def toArray: Array[Char] = {
val result = new Array[Char](length)
compat.Platform.arraycopy(self.ToCharArray, 0, result, 0, length)
result
}
/** <p>
* Uses the underlying string as a pattern (in a fashion similar to
* printf in C), and uses the supplied arguments to fill in the
* holes.
* </p>
* <p>
* The interpretation of the formatting patterns is described in
* <a href="" target="contentFrame" class="java/util/Formatter">
* <code>java.util.Formatter</code></a>.
* </p>
*
* @param args the arguments used to instantiating the pattern.
* @throws java.lang.IllegalArgumentException
*/
// def format(args : Any*) : String =
// java.lang.String.format(self, args.toArray[Any].asInstanceOf[Array[AnyRef]]: _*)
}

View File

@ -1,17 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
namespace scala.runtime {
public interface Runnable {
void run();
}
}

View File

@ -1,22 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
namespace scala.runtime {
using System;
[Serializable]
public class ShortRef {
public short elem;
public ShortRef(short elem) { this.elem = elem; }
override public string ToString() { return elem.ToString(); }
}
}

View File

@ -1,28 +0,0 @@
/* *\
** ________ ___ __ ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ |_| **
** **
\* */
// $Id$
package scala.runtime
import Predef._
final class StringAdd(self: Any) {
def +(other: String) = self.toString + other
/** Formats string according to given <code>format</code> string.
* Format strings are as for <code>String.format</code> (@see
* http://msdn2.microsoft.com/en-us/library/system.string.format(VS.71).aspx
* and http://www.codeproject.com/books/0735616485.asp).
*/
def formatted(format: String): String =
String.Format(format, Array(self.asInstanceOf[Object]))
}

View File

@ -1,22 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
namespace scala.runtime {
using System;
public class SymtabAttribute : Attribute {
public byte[] symtab;
public SymtabAttribute(byte[] symtab) { this.symtab = symtab; }
public SymtabAttribute() {}
}
}

View File

@ -1 +0,0 @@
/* Benchmark does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* SUnit does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* scala.testing.Show does not exist for the dotnet target */

View File

@ -1,122 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
package scala.text
import System.IO.TextWriter
case object DocNil extends Document
case object DocBreak extends Document
case class DocText(txt: String) extends Document
case class DocGroup(doc: Document) extends Document
case class DocNest(indent: Int, doc: Document) extends Document
case class DocCons(hd: Document, tl: Document) extends Document
/**
* A basic pretty-printing library, based on Lindig's strict version
* of Wadler's adaptation of Hughes' pretty-printer.
*
* @author Michel Schinz
* @version 1.0
*/
abstract class Document {
def ::(hd: Document): Document = DocCons(hd, this)
def ::(hd: String): Document = DocCons(DocText(hd), this)
def :/:(hd: Document): Document = hd :: DocBreak :: this
def :/:(hd: String): Document = hd :: DocBreak :: this
/**
* Format this document on <code>writer</code> and try to set line
* breaks so that the result fits in <code>width</code> columns.
*
* @param width ...
* @param writer ...
*/
def format(width: Int, writer: TextWriter) {
type FmtState = (Int, Boolean, Document)
def fits(w: Int, state: List[FmtState]): Boolean = state match {
case _ if w < 0 =>
false
case List() =>
true
case (_, _, DocNil) :: z =>
fits(w, z)
case (i, b, DocCons(h, t)) :: z =>
fits(w, (i,b,h) :: (i,b,t) :: z)
case (_, _, DocText(t)) :: z =>
fits(w - t.length(), z)
case (i, b, DocNest(ii, d)) :: z =>
fits(w, (i + ii, b, d) :: z)
case (_, false, DocBreak) :: z =>
fits(w - 1, z)
case (_, true, DocBreak) :: z =>
true
case (i, _, DocGroup(d)) :: z =>
fits(w, (i, false, d) :: z)
}
def spaces(n: Int) {
var rem = n
while (rem >= 16) { writer Write " "; rem -= 16 }
if (rem >= 8) { writer Write " "; rem -= 8 }
if (rem >= 4) { writer Write " "; rem -= 4 }
if (rem >= 2) { writer Write " "; rem -= 2}
if (rem == 1) { writer Write " " }
}
def fmt(k: Int, state: List[FmtState]): Unit = state match {
case List() => ()
case (_, _, DocNil) :: z =>
fmt(k, z)
case (i, b, DocCons(h, t)) :: z =>
fmt(k, (i, b, h) :: (i, b, t) :: z)
case (i, _, DocText(t)) :: z =>
writer Write t
fmt(k + t.length(), z)
case (i, b, DocNest(ii, d)) :: z =>
fmt(k, (i + ii, b, d) :: z)
case (i, true, DocBreak) :: z =>
writer Write "\n"
spaces(i);
fmt(i, z)
case (i, false, DocBreak) :: z =>
writer Write " "
fmt(k + 1, z)
case (i, b, DocGroup(d)) :: z =>
val fitsFlat = fits(width - k, (i, false, d) :: z)
fmt(k, (i, !fitsFlat, d) :: z)
}
fmt(0, (0, false, DocGroup(this)) :: Nil)
}
}
object Document {
/** The empty document */
def empty = DocNil
/** A break, which will either be turned into a space or a line break */
def break = DocBreak
/** A document consisting of some text literal */
def text(s: String): Document = DocText(s)
/**
* A group, whose components will either be printed with all breaks
* rendered as spaces, or with all breaks rendered as line breaks.
*/
def group(d: Document): Document = DocGroup(d)
/** A nested document, which will be indented as specified. */
def nest(i: Int, d: Document): Document = DocNest(i, d)
}

View File

@ -1,83 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2006-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
package scala.util
import Predef._
import System.Threading.Thread
import System.LocalDataStoreSlot
/** <p>
* DynamicVariables provide a binding mechanism where the current
* value is found through <em>dynamic scope</em>, but where
* access to the variable itself is resolved through <em>static
* scope</em>.
* </p>
* <p>
* The current value can be retrieved with the
* <code>value</code> method. New values should be
* pushed using the <code>withValue</code> method.
* Values pushed via <code>withValue</code> only
* stay valid while the <code>withValue</code>'s
* <em>second</em> argument, a parameterless closure,
* executes. When the second argument finishes,
* the variable reverts to the previous value.
* </p>
* <p>
* Usage of <code>withValue</code> looks like this:
* </p>
* <blockquote><pre>
* someDynamicVariable.withValue(newValue) {
* // ... code called in here that calls value ...
* // ... will be given back the newValue ...
* }
* </pre></blockquote>
* <p>
* Each thread gets its own stack of bindings. When a
* new thread is created, the fluid gets a copy of
* the stack of bindings from the parent thread, and
* from then on the bindings for the new thread
* are independent of those for the original thread.
* </p>
*
* @author Lex Spoon
* @version 1.1, 2007-5-21
*/
class DynamicVariable[T](init: T) {
private val slot: LocalDataStoreSlot = Thread.AllocateDataSlot()
value = init
/** Retrieve the current value */
def value: T = Thread.GetData(slot).asInstanceOf[T]
/** Set the value of the fluid while executing the specified
* thunk.
*
* @param newval The value to which to set the fluid
* @param thunk The code to evaluate under the new setting
*/
def withValue[S](newval: T)(thunk: =>S): S = {
val oldval = value
value = newval
try { thunk } finally {
value = oldval
}
}
/** Change the currently bound value, discarding the old value.
* Usually withValue() gives better semantics.
*/
def value_=(newval: T) = { Thread.SetData(slot, newval.asInstanceOf[AnyRef]) }
override def toString: String = "DynamicVariable(" + value +")"
}

View File

@ -1 +0,0 @@
/* Marshal does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* NameTransformer does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* Properties does not exist for the dotnet target */

View File

@ -1,98 +0,0 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2006-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
package scala.util
/**
* @author Stephane Micheloud
*/
class Random(self0: System.Random) {
private var rnd = self0 // see setSeed(seed)
def self = rnd
/** Creates a new random number generator using a single long seed. */
def this(seed: Long) = this(new System.Random(seed.toInt))
/** Creates a new random number generator using a single integer seed. */
def this(seed: Int) = this(new System.Random(seed))
/** Creates a new random number generator. */
def this() = this(new System.Random(System.Environment.TickCount))
/** Returns the next pseudorandom, uniformly distributed boolean value
* from this random number generator's sequence.
*/
def nextBoolean(): Boolean = (nextInt() & 0x1) == 1
/** Generates random bytes and places them into a user-supplied byte
* array.
*/
def nextBytes(bytes: Array[Byte]) { rnd.NextBytes(bytes) }
/** Returns the next pseudorandom, uniformly distributed double value
* between 0.0 and 1.0 from this random number generator's sequence.
*/
def nextDouble(): Double = rnd.NextDouble()
/** Returns the next pseudorandom, uniformly distributed float value
* between 0.0 and 1.0 from this random number generator's sequence.
*/
def nextFloat(): Float = nextDouble().toFloat
/** Returns the next pseudorandom, Gaussian ("normally") distributed
* double value with mean 0.0 and standard deviation 1.0 from this
* random number generator's sequence.
* This implements the Box-Muller transformation on the pseudorandom
* `nextDouble` method of this class, and should be equivalent to
* the implementation of `nextGaussian` in the Java API.
*/
def nextGaussian(): Double = synchronized {
if (nextGaussianAvailable) {
nextGaussianAvailable = false
nextGaussianCache
} else {
var u: Double = 0.0
var v: Double = 0.0
var s: Double = 0.0
do {
u = 2 * nextDouble() - 1 // [-1, +1]
v = 2 * nextDouble() - 1 // [-1, +1]
s = Math.pow(u, 2) + Math.pow(v, 2)
} while (s >= 1 || s == 0);
val mul = Math.sqrt((-2 * Math.log(s)) / s)
nextGaussianCache = u * mul
nextGaussianAvailable = true
v * mul
}
}
private var nextGaussianAvailable: Boolean = false
private var nextGaussianCache: Double = _
/** Returns the next pseudorandom, uniformly distributed int value
* from this random number generator's sequence.
*/
def nextInt(): Int = rnd.Next()
/** Returns a pseudorandom, uniformly distributed int value between 0
* (inclusive) and the specified value (exclusive), drawn from this
* random number generator's sequence.
*/
def nextInt(n: Int): Int = rnd.Next(0, n)
/** Returns the next pseudorandom, uniformly distributed long value
* from this random number generator's sequence.
*/
def nextLong(): Long = nextInt().toLong // 2x nextInt() ?!
def setSeed(seed: Long) { rnd = new System.Random(seed.toInt) }
}

View File

@ -1 +0,0 @@
/* ScalaClassLoader does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* BaseBerrySethi.scala does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* DetWordAutom.scala does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* Inclusion.scala does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* NondetWordAutom.scala does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* SubsetConstruction.scala does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* WordBerrySethi.scala does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* Exception does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* HedgeRHS.scala does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* TreeRHS.scala does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* ConsoleLogger.scala does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* Logged.scala does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* Regex does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* AbstractSyntax.scala does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* Binders does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* ImplicitConversions.scala does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* JavaTokenParsers does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* PackratParsers does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* Parsers does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* RegexParsers does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* Lexical.scala does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* Scanners does not exist for the dotnet target */

View File

@ -1 +0,0 @@
/* StdLexical does not exist for the dotnet target */

Some files were not shown because too many files have changed in this diff Show More