From 450425c96412a8b7ae52513dbe99af5732a19bfb Mon Sep 17 00:00:00 2001 From: Gilles Dubochet Date: Fri, 29 May 2009 11:35:44 +0000 Subject: Removed CLDC library, since we've stopper suppo... Removed CLDC library, since we've stopper supporting CLDC. --- src/cldc-library/scala/Array.scala | 430 ------- src/cldc-library/scala/Console.scala | 96 -- src/cldc-library/scala/List.scala | 1225 -------------------- src/cldc-library/scala/Math.scala | 56 - src/cldc-library/scala/Predef.scala | 188 --- src/cldc-library/scala/Random.scala | 41 - src/cldc-library/scala/StringBuilder.scala | 862 -------------- src/cldc-library/scala/Symbol.scala | 48 - .../collection/mutable/CloneableCollection.scala | 19 - src/cldc-library/scala/compat/Platform.scala | 56 - src/cldc-library/scala/runtime/BooleanRef.java | 19 - src/cldc-library/scala/runtime/BoxedAnyArray.scala | 234 ---- .../scala/runtime/BoxedObjectArray.scala | 73 -- src/cldc-library/scala/runtime/BoxedUnit.java | 33 - src/cldc-library/scala/runtime/BoxesRunTime.java | 361 ------ src/cldc-library/scala/runtime/BoxesUtility.java | 147 --- src/cldc-library/scala/runtime/ByteRef.java | 19 - src/cldc-library/scala/runtime/CharRef.java | 19 - src/cldc-library/scala/runtime/Comparator.java | 53 - src/cldc-library/scala/runtime/IntRef.java | 19 - src/cldc-library/scala/runtime/LongRef.java | 19 - src/cldc-library/scala/runtime/ObjectRef.java | 19 - src/cldc-library/scala/runtime/RichChar.scala | 71 -- src/cldc-library/scala/runtime/RichException.scala | 29 - src/cldc-library/scala/runtime/RichLong.scala | 30 - src/cldc-library/scala/runtime/RichString.scala | 219 ---- src/cldc-library/scala/runtime/ScalaRunTime.scala | 142 --- src/cldc-library/scala/runtime/ShortRef.java | 19 - src/cldc-library/scala/runtime/SquareRoot.scala | 151 --- src/cldc-library/scala/runtime/StringAdd.scala | 22 - 30 files changed, 4719 deletions(-) delete mode 100644 src/cldc-library/scala/Array.scala delete mode 100644 src/cldc-library/scala/Console.scala delete mode 100644 src/cldc-library/scala/List.scala delete mode 100644 src/cldc-library/scala/Math.scala delete mode 100644 src/cldc-library/scala/Predef.scala delete mode 100644 src/cldc-library/scala/Random.scala delete mode 100644 src/cldc-library/scala/StringBuilder.scala delete mode 100644 src/cldc-library/scala/Symbol.scala delete mode 100644 src/cldc-library/scala/collection/mutable/CloneableCollection.scala delete mode 100644 src/cldc-library/scala/compat/Platform.scala delete mode 100644 src/cldc-library/scala/runtime/BooleanRef.java delete mode 100644 src/cldc-library/scala/runtime/BoxedAnyArray.scala delete mode 100644 src/cldc-library/scala/runtime/BoxedObjectArray.scala delete mode 100644 src/cldc-library/scala/runtime/BoxedUnit.java delete mode 100644 src/cldc-library/scala/runtime/BoxesRunTime.java delete mode 100644 src/cldc-library/scala/runtime/BoxesUtility.java delete mode 100644 src/cldc-library/scala/runtime/ByteRef.java delete mode 100644 src/cldc-library/scala/runtime/CharRef.java delete mode 100644 src/cldc-library/scala/runtime/Comparator.java delete mode 100644 src/cldc-library/scala/runtime/IntRef.java delete mode 100644 src/cldc-library/scala/runtime/LongRef.java delete mode 100644 src/cldc-library/scala/runtime/ObjectRef.java delete mode 100644 src/cldc-library/scala/runtime/RichChar.scala delete mode 100644 src/cldc-library/scala/runtime/RichException.scala delete mode 100644 src/cldc-library/scala/runtime/RichLong.scala delete mode 100644 src/cldc-library/scala/runtime/RichString.scala delete mode 100644 src/cldc-library/scala/runtime/ScalaRunTime.scala delete mode 100644 src/cldc-library/scala/runtime/ShortRef.java delete mode 100644 src/cldc-library/scala/runtime/SquareRoot.scala delete mode 100644 src/cldc-library/scala/runtime/StringAdd.scala diff --git a/src/cldc-library/scala/Array.scala b/src/cldc-library/scala/Array.scala deleted file mode 100644 index f37c7f56b0..0000000000 --- a/src/cldc-library/scala/Array.scala +++ /dev/null @@ -1,430 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala - - -import Predef._ -import compat.Platform.arraycopy - -/** This object contains utility methods operating on arrays. - * - * @author Martin Odersky - * @version 1.0 - */ -object Array { - - /** Copy one array to another. - * Equivalent to - * System.arraycopy(src, srcPos, dest, destPos, length), - * except that this works also for polymorphic and boxed arrays. - * - * @param src ... - * @param srcPos ... - * @param dest ... - * @param destPos ... - * @param length ... - */ - def copy(src: AnyRef, srcPos: Int, dest: AnyRef, destPos: Int, length: Int): Unit = src match { - case xs: runtime.BoxedArray => - xs.copyTo(srcPos, dest, destPos, length) - case _ => - dest match { - case xs: runtime.BoxedArray => - xs.copyFrom(src, srcPos, destPos, length) - case _ => - arraycopy(src, srcPos, dest, destPos, length) - } - } - - /** Concatenate all argument arrays into a single array. - * - * @param xs ... - */ - def concat[T](xs: Array[T]*) = { - var len = 0 - for (x <- xs) len += x.length - val result = new Array[T](len) - var start = 0 - for (x <- xs) { - copy(x, 0, result, start, x.length) - start += x.length - } - result - } - - /** Create a an array containing of successive integers. - * - * @param from the value of the first element of the array - * @param end the value of the last element fo the array plus 1 - * @return the sorted array of all integers in range [from;end). - */ - def range(start: Int, end: Int): Array[Int] = { - val result = new Array[Int](end - start) - for (i <- start until end) result(i - start) = i - result - } - - /** Create an array with given elements. - * - * @param xs the elements to put in the array - * @return the array containing elements xs. - */ - def apply[A <: AnyRef](xs: A*): Array[A] = { - val array = new Array[A](xs.length) - var i = 0 - for (x <- xs.iterator) { array(i) = x; i += 1 } - array - } - - -/* The following metod clashes with the previous one, and has therefore been - * removed. Note that this is a choice between efficiency and generality. - * The previous factory method is more efficient than the one that has been - * commented out. Since it is anyway possible to create a polymorphic array - * using - * new Array[T] - * it was preferred to restrict the definition of the factory method. - - def Array[A](xs: A*): Array[A] = { - val array = new Array[A](xs.length) - var i = 0 - for (x <- xs.iterator) { array(i) = x; i += 1 } - array - } -*/ - - def apply(xs: Boolean*): Array[Boolean] = { - val array = new Array[Boolean](xs.length) - var i = 0 - for (x <- xs.iterator) { array(i) = x; i += 1 } - array - } - def apply(xs: Byte*): Array[Byte] = { - val array = new Array[Byte](xs.length) - var i = 0 - for (x <- xs.iterator) { array(i) = x; i += 1 } - array - } - def apply(xs: Short*): Array[Short] = { - val array = new Array[Short](xs.length) - var i = 0 - for (x <- xs.iterator) { array(i) = x; i += 1 } - array - } - def apply(xs: Char*): Array[Char] = { - val array = new Array[Char](xs.length) - var i = 0 - for (x <- xs.iterator) { array(i) = x; i += 1 } - array - } - def apply(xs: Int*): Array[Int] = { - val array = new Array[Int](xs.length) - var i = 0 - for (x <- xs.iterator) { array(i) = x; i += 1 } - array - } - def apply(xs: Long*): Array[Long] = { - val array = new Array[Long](xs.length) - var i = 0 - for (x <- xs.iterator) { array(i) = x; i += 1 } - array - } - def apply(xs: Unit*): Array[Unit] = { - val array = new Array[Unit](xs.length) - var i = 0 - for (x <- xs.iterator) { array(i) = x; i += 1 } - array - } - - /** Create an array containing several copies of an element. - * - * @param n the length of the resulting array - * @param elem the element composing the resulting array - * @return an array composed of n elements all equal to elem - */ - def make[A](n: Int, elem: A): Array[A] = { - val a = new Array[A](n) - var i = 0 - while (i < n) { - a(i) = elem - i += 1 - } - a - } - - /** This method is called as a result of a pattern match { case Array(...) => } or val Array(...) = .... - * - * @param x the selector value - * @return array wrapped in an option - */ - def unapplySeq[A](x: Array[A]): Option[Seq[A]] = Some(x) - - trait Projection[A] extends RandomAccessSeq.MutableProjection[A] { - protected def newArray[B >: A](length : Int, elements : Iterator[A]) : Array[B] - override def toArray[B >: A] = (newArray(length, elements))//:Any).asInstanceOf[Array[B]] - override def force : Array[A] = toArray - override def drop( from: Int) = slice(from, length) - override def take(until: Int) = slice(0, until) - override def slice(from0 : Int, until0 : Int) : Projection[A] = new RandomAccessSeq.MutableSlice[A] with Projection[A] { - override def from = from0 - override def until = until0 - override def underlying = Projection.this - override protected def newArray[B >: A](length : Int, elements : Iterator[A]) = - underlying.newArray(length, elements) - override def slice(from0 : Int, until0 : Int) = - Projection.this.slice(from + from0, from + until0) - } - override def reverse : Projection[A] = new Projection[A] { - override protected def newArray[B >: A](length : Int, elements : Iterator[A]) = - Projection.this.newArray(length, elements) - def update(idx : Int, what : A) : Unit = Projection.this.update(length - idx - 1, what) - def length = Projection.this.length - def apply(idx : Int) = Projection.this.apply(length - idx - 1) - override def stringPrefix = Projection.this.stringPrefix + "R" - } - } - trait Array0[A] extends RandomAccessSeq.Mutable[A] { - override def projection : Projection[A] = throw new Error - override def slice(from : Int, until : Int) : Projection[A] = projection.slice(from, until) - override def take(until : Int) : Projection[A] = projection.take(until) - override def drop(from : Int) : Projection[A] = projection.drop(from) - override def reverse = projection.reverse - } -} - -/** This class represents polymorphic arrays. Array[T] is Scala's representation - * for Java's T[]. - * - * @author Martin Odersky - * @version 1.0 - */ -final class Array[A](_length: Int) extends Array.Array0[A] { - - /** Multidimensional array creation */ - def this(dim1: Int, dim2: Int) = { - this(dim1); - throw new Error() - } - - /** Multidimensional array creation */ - def this(dim1: Int, dim2: Int, dim3: Int) = { - this(dim1); - throw new Error() - } - - /** Multidimensional array creation */ - def this(dim1: Int, dim2: Int, dim3: Int, dim4: Int) = { - this(dim1); - throw new Error() - } - - /** Multidimensional array creation */ - def this(dim1: Int, dim2: Int, dim3: Int, dim4: Int, dim5: Int) = { - this(dim1); - throw new Error() - } - - /** Multidimensional array creation */ - def this(dim1: Int, dim2: Int, dim3: Int, dim4: Int, dim5: Int, dim6: Int) = { - this(dim1); - throw new Error() - } - - /** Multidimensional array creation */ - def this(dim1: Int, dim2: Int, dim3: Int, dim4: Int, dim5: Int, dim6: Int, dim7: Int) = { - this(dim1); - throw new Error() - } - - /** Multidimensional array creation */ - def this(dim1: Int, dim2: Int, dim3: Int, dim4: Int, dim5: Int, dim6: Int, dim7: Int, dim8: Int) = { - this(dim1); - throw new Error() - } - - /** Multidimensional array creation */ - def this(dim1: Int, dim2: Int, dim3: Int, dim4: Int, dim5: Int, dim6: Int, dim7: Int, dim8: Int, dim9: Int) = { - this(dim1); - throw new Error() - } - - /** The length of the array */ - def length: Int = throw new Error() - - /** The element at given index. - *

- * Indices start a 0; xs.apply(0) is the first - * element of array xs. - *

- *

- * Note the indexing syntax xs(i) is a shorthand for - * xs.apply(i). - *

- * - * @param i the index - * @throws ArrayIndexOutOfBoundsException if i < 0 or - * length <= i - */ - def apply(i: Int): A = throw new Error() - - /**

- * Update the element at given index. - *

- *

- * Indices start a 0; xs.apply(0) is the first - * element of array xs. - *

- *

- * Note the indexing syntax xs(i) = x is a shorthand - * for xs.update(i, x). - *

- * - * @param i the index - * @param x the value to be written at index i - * @throws ArrayIndexOutOfBoundsException if i < 0 or - * length <= i - */ - override def update(i: Int, x: A): Unit = throw new Error() - - /** An iterator returning the elements of this array, starting from 0. - */ - override def iterator: Iterator[A] = throw new Error() - - /** @deprecated use slice(from,end).force instead */ - def subArray(from: Int, end: Int): Array[A] = throw new Error() - - /** Returns an array consisting of all elements of this array that satisfy the - * predicate p. The order of the elements is preserved. - * - * @param p the predicate used to filter the array. - * @return the elements of this array satisfying p. - */ - override def filter(p: A => Boolean): Array[A] = throw new Error() - - /** Returns the longest prefix of this array whose elements satisfy - * the predicate p. - * - * @param p the test predicate. - * @return the longest prefix of this array whose elements satisfy - * the predicate p. - */ - override def takeWhile(p: A => Boolean): Array[A] = throw new Error() - - /** Returns the longest suffix of this array whose first element - * does not satisfy the predicate p. - * - * @param p the test predicate. - * @return the longest suffix of the array whose first element - * does not satisfy the predicate p. - */ - override def dropWhile(p: A => Boolean): Array[A] = throw new Error() - - /** Returns an array consisting of all elements of this array followed - * by all elements of the argument iterable. - */ - override def ++[B >: A](that: Iterable[B]): Array[B] = throw new Error() - - /** Returns the array resulting from applying the given function f to each - * element of this array. - * - * @param f function to apply to each element. - * @return [f(a0), ..., f(an)] if this array is [a0, ..., an]. - */ - override def map[B](f: A => B): Array[B] = throw new Error() - - /** Applies the given function f to each element of - * this array, then concatenates the results. - * - * @param f the function to apply on each element. - * @return f(a0) ::: ... ::: f(an) if - * this array is [a0, ..., an]. - */ - override def flatMap[B](f: A => Iterable[B]): Array[B] = throw new Error() - - /** Returns an array formed from this array and the specified array - * that by associating each element of the former with - * the element at the same position in the latter. - * If one of the two arrays is longer than the other, its remaining elements are ignored. - * - * @return Array({a0,b0}, ..., - * {amin(m,n),bmin(m,n)}) when - * Array(a0, ..., am) - * zip Array(b0, ..., bn) is invoked. - */ - def zip[B](that: Array[B]): Array[Tuple2[A,B]] = throw new Error() - - /** Returns an array that pairs each element of this array - * with its index, counting from 0. - * - * @return the array Array({a0,0}, {a1,1},...) - * where ai are the elements of this stream. - */ - def zipWithIndex: Array[Tuple2[A,Int]] = throw new Error() - - /** Returns an array that contains all indices of this array */ - def indices: Array[Int] = throw new Error() - - /** - * @return a deep string representation of this array. - */ - def deepToString(): String = throw new Error() - - /**

- * Returns a string representation of this array object. The resulting string - * begins with the string start and is finished by the string - * end. Inside, the string representations of elements (w.r.t. - * the method deepToString()) are separated by the string - * sep. For example: - *

- *

- * Array(Array(1, 2), Array(3)).deepMkString("[", "; ", "]") = "[[1; 2]; [3]]" - *

- * - * @param start starting string. - * @param sep separator string. - * @param end ending string. - * @return a string representation of this array object. - */ - def deepMkString(start: String, sep: String, end: String): String = - throw new Error() - - /** Returns a string representation of this array object. The string - * representations of elements (w.r.t. the method deepToString()) - * are separated by the string sep. - * - * @param sep separator string. - * @return a string representation of this array object. - */ - def deepMkString(sep: String): String = throw new Error() - - /**

- * Returns true if the two specified arrays are - * deeply equal to one another. - *

- *

- * Two array references are considered deeply equal if both are null, - * or if they refer to arrays that contain the same number of elements - * and all corresponding pairs of elements in the two arrays are deeply - * equal. - *

- *

- * See also method deepEquals in the Java class - * java.utils.Arrays - *

- * - * @param that the second - * @return true iff both arrays are deeply equal. - */ - def deepEquals(that: Any): Boolean = throw new Error() - -} diff --git a/src/cldc-library/scala/Console.scala b/src/cldc-library/scala/Console.scala deleted file mode 100644 index 1b359359c2..0000000000 --- a/src/cldc-library/scala/Console.scala +++ /dev/null @@ -1,96 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala - -import java.io.{OutputStream, PrintStream} - -import Predef._ - - -/** The Console object implements functionality for - * printing Scala values on the terminal. There are also functions - * for reading specific values. Console 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" - - var out: PrintStream = java.lang.System.out - val err = java.lang.System.err - - /** Set the default output stream. - * - * @param out the new output stream. - */ - def setOut(out: PrintStream): Unit = this.out = out - - /** Set the default output stream. - * - * @param@ out the new output stream. - */ - def setOut(out: OutputStream): Unit = - setOut(new PrintStream(out)) - - /** Print an object on the terminal. - * - * @param obj the object to print. - */ - def print(obj: Any): Unit = - out.print(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(): Unit = out.flush() - - /** Print a new line character on the terminal. - */ - def println(): Unit = out.println() - - /** Print out an object followed by a new line character. - * - * @param x the object to print. - */ - def println(x: Any): Unit = out.println(x) - -} diff --git a/src/cldc-library/scala/List.scala b/src/cldc-library/scala/List.scala deleted file mode 100644 index 35f8d45760..0000000000 --- a/src/cldc-library/scala/List.scala +++ /dev/null @@ -1,1225 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala - -import scala.collection.mutable.ListBuffer -import Predef._ - -/** This object provides methods for creating specialized lists, and for - * transforming special kinds of lists (e.g. lists of lists). - * - * @author Martin Odersky and others - * @version 1.0, 15/07/2003 - */ -object List { - - /** Create a list with given elements. - * - * @param xs the elements to put in the list - * @return the list containing elements xs. - */ - def apply[A](xs: A*): List[A] = xs.toList - - /** for unapply matching - */ - def unapplySeq[A](x: List[A]): Some[List[A]] = Some(x) - - /** Create a sorted list of all integers in a range. - * - * @param from the start value of the list - * @param end the end value of the list - * @return the sorted list of all integers in range [from;end). - */ - def range(from: Int, end: Int): List[Int] = - range(from, end, 1) - - /** Create a sorted list of all integers in a range. - * - * @param from the start value of the list - * @param end the end value of the list - * @param step the increment value of the list - * @return the sorted list of all integers in range [from;end). - */ - def range(from: Int, end: Int, step: Int): List[Int] = { - val b = new ListBuffer[Int] - var i = from - while (i < end) { - b += i - i += step - } - b.toList - } - - /** Create a sorted list of all integers in a range. - * - * @param from the start value of the list - * @param end the end value of the list - * @param step the increment function of the list - * @return the sorted list of all integers in range [from;end). - */ - def range(from: Int, end: Int, step: Int => Int): List[Int] = { - val b = new ListBuffer[Int] - var i = from - while (i < end) { - b += i - i += step(i) - } - b.toList - } - - /** Create a list containing several copies of an element. - * - * @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 - */ - 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 - } - - /** Create a list by applying a function to successive integers. - * - * @param n the length of the resulting list - * @param maker the procedure which, given an integer n, - * returns the nth element of the resulting list, where - * n is in interval [0;n). - * @return the list obtained by applying the maker function to - * successive integers from 0 to n (exclusive). - */ - def tabulate[A](n: Int, maker: Int => A): List[A] = { - val b = new ListBuffer[A] - var i = 0 - while (i < n) { - b += maker(i) - i += 1 - } - b.toList - } - - /** Concatenate all the elements of a given list of lists. - * - * @param xss the list of lists that are to be concatenated - * @return the concatenation of all the lists - */ - def flatten[A](xss: List[List[A]]): List[A] = concat(xss: _*) - - /** Concatenate all the argument lists into a single list. - * - * @param xss the lists that are to be concatenated - * @return the concatenation of all the lists - */ - def concat[A](xss: 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 pair into a pair of lists. - * - * @param xs the list of pairs to unzip - * @return a pair of lists: the first list in the pair contains the list - */ - 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) - } - - /** Converts an iterator to a list. - * - * @param it the iterator to convert - * @return a list that contains the elements returned by successive - * calls to it.next - */ - 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 arr - * in the same order - */ - 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 arr - * in the same order - */ - 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 - */ - 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 str.toList 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. - */ - 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 xs unchanged if function - * f maps all elements to themselves. - * - * @param xs ... - * @param f ... - * @return ... - */ - 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 f - * to corresponding elements of the argument lists. - * - * @param f function to apply to each pair of elements. - * @return [f(a0,b0), ..., f(an,bn)] if the lists are - * [a0, ..., ak], [b0, ..., bl] and - * n = min(k,l) - */ - 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 - * f to corresponding elements of the argument lists. - * - * @param f function to apply to each pair of elements. - * @return [f(a0,b0,c0), - * ..., f(an,bn,cn)] - * if the lists are [a0, ..., ak], - * [b0, ..., bl], - * [c0, ..., cm] and - * n = min(k,l,m) - */ - 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 p holds - * for all corresponding elements of the argument lists. - * - * @param p function to apply to each pair of elements. - * @return (p(a0,b0) && - * ... && p(an,bn))] - * if the lists are [a0, ..., ak]; - * [b0, ..., bl] - * and n = min(k,l) - */ - 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 p holds - * for some corresponding elements of the argument lists. - * - * @param p function to apply to each pair of elements. - * @return n != 0 && (p(a0,b0) || - * ... || p(an,bn))] if the lists are - * [a0, ..., ak], - * [b0, ..., bl] and - * n = min(k,l) - */ - 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 - */ - def transpose[A](xss: List[List[A]]): List[List[A]] = - if (xss.head.isEmpty) List() - else (xss map (xs => xs.head)) :: transpose(xss map (xs => xs.tail)) -} - -/** A class representing an ordered collection of elements of type - * a. This class comes with two implementing case - * classes scala.Nil and scala.:: that - * implement the abstract members isEmpty, - * head and tail. - * - * @author Martin Odersky and others - * @version 1.0, 16/07/2003 - */ -sealed abstract class List[+A] extends Seq[A] { - - /** Returns true if the list does not contain any elements. - * @return true, iff the list is empty. - */ - override 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 length - l, without calling length - */ - override def lengthCompare(l: Int) = { - if (isEmpty) 0 - l - else if (l <= 0) 1 - else tail.lengthCompare(l - 1) - } - - /** 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] - - /**

- * Add an element x at the beginning of this list. - *

- * - * @param x the element to append. - * @return the list with x appended at the beginning. - * @ex 1 :: List(2, 3) = List(2, 3).::(1) = List(1, 2, 3) - */ - def ::[B >: A] (x: B): List[B] = - new scala.::(x, this) - - /**

- * Returns a list resulting from the concatenation of the given - * list prefix and this list. - *

- * - * @param prefix the list to concatenate at the beginning of this list. - * @return the concatenation of the two lists. - * @ex List(1, 2) ::: List(3, 4) = List(3, 4).:::(List(1, 2)) = List(1, 2, 3, 4) - */ - def :::[B >: A](prefix: List[B]): List[B] = - if (isEmpty) prefix - else { - val b = new ListBuffer[B] - var those = prefix - while (!those.isEmpty) { - b += those.head - those = those.tail - } - b.prependToList(this) - } - - /** Reverse the given prefix and append the current list to that. - * This function is equivalent to an application of reverse - * on the prefix followed by a call to :::, but more - * efficient (and tail recursive). - * - * @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 - } - - /** Returns the number of elements in the list. - * - * @return the number of elements in the list. - */ - def length: Int = { - var these = this - var len = 0 - while (!these.isEmpty) { - len += 1 - these = these.tail - } - len - } - - /** Creates a list with all indices in the list. This is - * equivalent to a call to List.range(0, xs.length). - * - * @return a list of all indices in the list. - */ - def indices: List[Int] = { - val b = new ListBuffer[Int] - var i = 0 - var these = this - while (!these.isEmpty) { - b += i - i += 1 - these = these.tail - } - b.toList - } - - /** Returns the elements in the list as an iterator - * - * @return an iterator on the list elements. - */ - override def iterator: Iterator[A] = new Iterator[A] { - var these = List.this - def hasNext: Boolean = !these.isEmpty - def next: A = - if (!hasNext) - throw new NoSuchElementException("next on empty Iterator") - else { - val result = these.head; these = these.tail; result - } - override def toList: List[A] = these - } - - /** Overrides the method in Iterable for efficiency. - * - * @return the list itself - */ - override def toList: List[A] = this - - /** Returns the list without its last element. - * - * @return the list without its last element. - * @throws Predef.UnsupportedOperationException if the list is empty. - */ - def init: List[A] = - if (isEmpty) throw new UnsupportedOperationException("Nil.init") - else { - val b = new ListBuffer[A] - var elem = head - var next = tail - while (!next.isEmpty) { - b += elem - elem = next.head - next = next.tail - } - b.toList - } - - /** Returns the last element of this list. - * - * @return the last element of the list. - * @throws Predef.UnsupportedOperationException if the list is empty. - */ - override def last: A = - if (isEmpty) throw new Predef.NoSuchElementException("Nil.last") - else { - var cur = this - var next = this.tail - while (!next.isEmpty) { - cur = next - next = next.tail - } - cur.head - } - - /** Returns the n first elements of this list, or else the whole - * list, if it has less than n elements. - * - * @param n the number of elements to take. - * @return the n 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 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] = { - val s = start max 0 - val e = end min this.length - drop(s) take (e - s) - } - - /** Returns the list without its n first elements. - * If this list has less than n elements, the empty list is returned. - * - * @param n the number of elements to drop. - * @return the list without its n 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 rightmost n elements from this list. - * - * @param n the number of elements to take - * @return the suffix of length n of the list - */ - 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) - } - - /** Returns the list wihout its rightmost n elements. - * - * @param n the number of elements to take - * @return the suffix of length n of the list - */ - def dropRight(n: Int): List[A] = { - def loop(lead: List[A], lag: List[A]): List[A] = lead match { - case Nil => Nil - case _ :: tail => lag.head :: loop(tail, lag.tail) - } - loop(drop(n), this) - } - - /** 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 n - * elements, and the other elements. - */ - 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 p. - * - * @param p the test predicate. - * @return the longest prefix of this list whose elements satisfy - * the predicate p. - */ - 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 p. - * - * @param p the test predicate. - * @return the longest suffix of the list whose first element - * does not satisfy the predicate p. - */ - 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 p, and the rest of the list. - */ - 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) - } - - /** Like span but with the predicate inverted. - */ - def break(p: A => Boolean): (List[A], List[A]) = span { x => !p(x) } - - /** Returns the n-th element of this list. The first element - * (head of the list) is at position 0. - * - * @param n index of the element to return - * @return the element at position n in this list. - * @throws Predef.NoSuchElementException if the list is too short. - */ - def apply(n: Int): A = drop(n).head - - /** Returns the list resulting from applying the given function f to each - * element of this list. - * - * @param f function to apply to each element. - * @return [f(a0), ..., f(an)] if this list is [a0, ..., an]. - */ - final override def map[B](f: A => B): List[B] = { - val b = new ListBuffer[B] - var these = this - while (!these.isEmpty) { - b += f(these.head) - these = these.tail - } - b.toList - } - - /** Apply a function to all the elements of the list, and return the - * reversed list of results. This is equivalent to a call to map - * followed by a call to reverse, but more efficient. - * - * @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) - } - - /** Apply the given function f to each element of this list - * (while respecting the order of the elements). - * - * @param f the treatment to apply to each element. - */ - final override def foreach(f: A => Unit) { - var these = this - while (!these.isEmpty) { - f(these.head) - these = these.tail - } - } - - /** Returns all the elements of this list that satisfy the - * predicate p. The order of the elements is preserved. - * It is guarenteed that the receiver list itself is returned iff all its - * elements satisfy the predicate `p'. Hence the following equality is valid: - * - * (xs filter p) eq xs == xs forall p - * - * @param p the predicate used to filter the list. - * @return the elements of this list satisfying p. - */ - final override def filter(p: A => Boolean): List[A] = { - // return same list if all elements satisfy p - var these = this - while (!these.isEmpty && p(these.head)) { - these = these.tail - } - if (these.isEmpty) this - else { - val b = new ListBuffer[A] - var these1 = this - while (these1 ne these) { - b += these1.head - these1 = these1.tail - } - - these = these.tail // prevent the second evaluation of the predicate - // on the element on which it first failed - while (!these.isEmpty) { - if (p(these.head)) b += these.head - these = these.tail - } - b.toList - } - } - -// final def filterMap[B](f: PartialFunction[A, B]): List[B] = -// this filter f.isDefinedAt map f - - /** Removes all elements of the list which satisfy the predicate - * p. This is like filter with the - * predicate inversed. - * - * @param p the predicate to use to test elements - * @return the list without all elements which satisfy p - */ - def remove(p: A => Boolean): List[A] = filter (x => !p(x)) - - /** Partition the list in two sub-lists according to a predicate. - * - * @param p the predicate on which to partition - * @return a pair of lists: the list of all elements which satisfy - * p and the list of all elements which do not. - * The relative order of the elements in the sub-lists is the - * same as in the original list. - */ - override def partition(p: A => Boolean): (List[A], List[A]) = { - val btrue = new ListBuffer[A] - val bfalse = new ListBuffer[A] - var these = this - while (!these.isEmpty) { - (if (p(these.head)) btrue else bfalse) += these.head - these = these.tail - } - (btrue.toList, bfalse.toList) - } - - /**

- * Sort the list according to the comparison function - * <(e1: a, e2: a) => Boolean, - * which should be true iff e1 is smaller than - * e2. - *

- * - * @param lt the comparison function - * @return a list sorted according to the comparison function - * <(e1: a, e2: a) => Boolean. - * @ex
-   *    List("Steve", "Tom", "John", "Bob")
-   *      .sort((e1, e2) => (e1 compareTo e2) < 0) =
-   *    List("Bob", "John", "Steve", "Tom")
- */ - 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) - } - - - /** Count the number of elements in the list which satisfy a predicate. - * - * @param p the predicate for which to count - * @return the number of elements satisfying the predicate p. - */ - def count(p: A => Boolean): Int = { - var cnt = 0 - var these = this - while (!these.isEmpty) { - if (p(these.head)) cnt += 1 - these = these.tail - } - cnt - } - - /** Tests if the predicate p is satisfied by all elements - * in this list. - * - * @param p the test predicate. - * @return true iff all elements of this list satisfy the - * predicate p. - */ - override def forall(p: A => Boolean): Boolean = { - var these = this - while (!these.isEmpty) { - if (!p(these.head)) return false - these = these.tail - } - true - } - - /** Tests the existence in this list of an element that satisfies the - * predicate p. - * - * @param p the test predicate. - * @return true iff there exists an element in this list that - * satisfies the predicate p. - */ - override def exists(p: A => Boolean): Boolean = { - var these = this - while (!these.isEmpty) { - if (p(these.head)) return true - these = these.tail - } - false - } - - /** Find and return the first element of the list satisfying a - * predicate, if any. - * - * @param p the predicate - * @return the first element in the list satisfying p, - * or None if none exists. - */ - override def find(p: A => Boolean): Option[A] = { - var these = this - while (!these.isEmpty) { - if (p(these.head)) return Some(these.head) - these = these.tail - } - None - } - - /** Combines the elements of this list together using the binary - * function f, from left to right, and starting with - * the value z. - * - * @return f(... (f(f(z, a0), a1) ...), - * an) if the list is - * [a0, a1, ..., an]. - */ - override def foldLeft[B](z: B)(f: (B, A) => B): B = { - var acc = z - var these = this - while (!these.isEmpty) { - acc = f(acc, these.head) - these = these.tail - } - acc - } - - /** Combines the elements of this list together using the binary - * function f, from right to left, and starting with - * the value z. - * - * @return f(a0, f(a1, f(..., f(an, z)...))) - * if the list is [a0, a1, ..., an]. - */ - override def foldRight[B](z: B)(f: (A, B) => B): B = this match { - case Nil => z - case x :: xs => f(x, xs.foldRight(z)(f)) - } - - /** Combines the elements of this list together using the binary - * operator op, from left to right - * @param op The operator to apply - * @return op(... op(a0,a1), ..., an) - if the list has elements - * a0, a1, ..., an. - * @throws Predef.UnsupportedOperationException if the list is empty. - */ - override def reduceLeft[B >: A](f: (B, B) => B): B = this match { - case Nil => throw new UnsupportedOperationException("Nil.reduceLeft") - case x :: xs => ((xs: List[B]) foldLeft (x: B))(f) - } - - /** Combines the elements of this list together using the binary - * operator op, from right to left - * @param op The operator to apply - * - * @return a0 op (... op (an-1 op an)...) - * if the list has elements a0, a1, ..., - * an. - * - * @throws Predef.UnsupportedOperationException if the list is empty. - */ - override def reduceRight[B >: A](f: (B, B) => B): B = this match { - case Nil => throw new UnsupportedOperationException("Nil.reduceRight") - case x :: Nil => x: B - case x :: xs => f(x, xs reduceRight f) - } - - /** Applies the given function f to each element of - * this list, then concatenates the results. - * - * @param f the function to apply on each element. - * @return f(a0) ::: ... ::: f(an) if - * this list is [a0, ..., an]. - */ - final override def flatMap[B](f: A => Iterable[B]): List[B] = { - val b = new ListBuffer[B] - var these = this - while (!these.isEmpty) { - var those = f(these.head).iterator - while (those.hasNext) { - b += those.next - } - these = these.tail - } - b.toList - } - - /** 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 - } - - /** Returns a list formed from this list and the specified list - * that by associating each element of the former with - * the element at the same position in the latter. - * If one of the two lists is longer than the other, its remaining elements are ignored. - * - * @return List((a0,b0), ..., - * (amin(m,n),bmin(m,n))) when - * List(a0, ..., am) - * zip List(b0, ..., bn) is invoked. - */ - def zip[B](that: List[B]): List[(A, B)] = { - val b = new ListBuffer[(A, B)] - var these = this - var those = that - while (!these.isEmpty && !those.isEmpty) { - b += (these.head, those.head) - these = these.tail - those = those.tail - } - b.toList - } - - /** Returns a list that pairs each element of this list - * with its index, counting from 0. - * - * @return the list List((a0,0), (a1,1), ...) - * where ai are the elements of this list. - */ - def zipWithIndex: List[(A, Int)] = { - val b = new ListBuffer[(A, Int)] - var these = this - var idx = 0 - - while(!these.isEmpty) { - b += (these.head, idx) - these = these.tail - idx += 1 - } - - b.toList - } - - /** Returns a list formed from this list and the specified list - * that by associating each element of the former with - * the element at the same position in the latter. - * - * @param that list that may have a different length - * as the self list. - * @param thisElem element thisElem is used to fill up the - * resulting list if the self list is shorter than - * that - * @param thatElem element thatElem is used to fill up the - * resulting list if that is shorter than - * the self list - * @return List((a0,b0), ..., - * (an,bn), (elem,bn+1), - * ..., {elem,bm}) - * when [a0, ..., an] zip - * [b0, ..., bm] is - * invoked where m > n. - */ - def zipAll[B, C >: A, D >: B](that: List[B], thisElem: C, thatElem: D): List[(C, D)] = { - val b = new ListBuffer[(C, D)] - var these = this - var those = that - while (!these.isEmpty && !those.isEmpty) { - b += (these.head, those.head) - these = these.tail - those = those.tail - } - while (!these.isEmpty) { - b += (these.head, thatElem) - these = these.tail - } - while (!those.isEmpty) { - b += (thisElem, those.head) - those = those.tail - } - b.toList - } - - /** Computes the union of this list and the given list - * that. - * - * @param that the list of elements to add to the list. - * @return a list without doubles containing the elements of this - * list and those of the given list that. - */ - def union[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.prependToList(that) - } - - /** Computes the difference between this list and the given list - * that. - * - * @param that the list of elements to remove from this list. - * @return this list without the elements of the given list - * that. - */ - def diff[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 - } - - def flatten[B](implicit f : A => Iterable[B]) : List[B] = { - val buf = new ListBuffer[B] - foreach(f(_).foreach(buf += _)) - buf.toList - } - - - /** Computes the intersection between this list and the given list - * that. - * - * @param that the list to intersect. - * @return the list of elements contained both in this list and - * in the given list that. - */ - def intersect[B >: A](that: List[B]): List[B] = filter(x => that contains x) - - /** Removes redundant elements from the list. Uses the method == - * to decide if two elements are identical. - * - * @return the list without doubles. - */ - def removeDuplicates: List[A] = { - val b = new ListBuffer[A] - var these = this - while (!these.isEmpty) { - if (!these.tail.contains(these.head)) b += these.head - these = these.tail - } - b.toList - } - - override protected def stringPrefix = "List" - override def projection = toStream - override def toStream : Stream[A] = new Stream.Definite[A] { - override def force : List[A] = List.this - override def isEmpty = List.this.isEmpty - override def head = List.this.head - override def tail = List.this.tail.toStream - protected def addDefinedElems(buf: StringBuilder, prefix: String): StringBuilder = if (!isEmpty) { - var prefix0 = prefix - var buf1 = buf.append(prefix0).append(head) - prefix0 = ", " - var tail0 = tail - while (!tail0.isEmpty) { - buf1 = buf.append(prefix0).append(tail0.head) - tail0 = tail0.tail - } - buf1 - } else buf - } - -} - -/** 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 - def head: Nothing = - throw new NoSuchElementException("head of empty list") - def tail: List[Nothing] = - throw new NoSuchElementException("tail of empty list") -} - -/** 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] { - def head : B = hd - def tail : List[B] = tl - override def isEmpty: Boolean = false -} - diff --git a/src/cldc-library/scala/Math.scala b/src/cldc-library/scala/Math.scala deleted file mode 100644 index 7161e0a53a..0000000000 --- a/src/cldc-library/scala/Math.scala +++ /dev/null @@ -1,56 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala - -/** The object Math contains methods for performing basic numeric - * operations such as the elementary exponential, logarithm, square root, and - * trigonometric functions. - */ -object Math { - - /** The smalles possible value for scala.Byte. */ - val MIN_BYTE = java.lang.Byte.MIN_VALUE - /** The greatest possible value for scala.Byte. */ - val MAX_BYTE = java.lang.Byte.MAX_VALUE - - /** The smalles possible value for scala.Short. */ - val MIN_SHORT = java.lang.Short.MIN_VALUE - /** The greatest possible value for scala.Short. */ - val MAX_SHORT = java.lang.Short.MAX_VALUE - - /** The smalles possible value for scala.Char. */ - val MIN_CHAR = java.lang.Character.MIN_VALUE - /** The greatest possible value for scala.Char. */ - val MAX_CHAR = java.lang.Character.MAX_VALUE - - /** The smalles possible value for scala.Int. */ - val MIN_INT = java.lang.Integer.MIN_VALUE - /** The greatest possible value for scala.Int. */ - val MAX_INT = java.lang.Integer.MAX_VALUE - - /** The smalles possible value for scala.Long. */ - val MIN_LONG = java.lang.Long.MIN_VALUE - /** The greatest possible value for scala.Long. */ - val MAX_LONG = java.lang.Long.MAX_VALUE - - - def abs(x: Int): Int = java.lang.Math.abs(x) - def abs(x: Long): Long = java.lang.Math.abs(x) - - def max(x: Int, y: Int): Int = java.lang.Math.max(x, y) - def max(x: Long, y: Long): Long = java.lang.Math.max(x, y) - - def min(x: Int, y: Int): Int = java.lang.Math.min(x, y) - def min(x: Long, y: Long): Long = java.lang.Math.min(x, y) - - def sqrt(x: Int): Int = runtime.SquareRoot.accurateSqrt(x) -} diff --git a/src/cldc-library/scala/Predef.scala b/src/cldc-library/scala/Predef.scala deleted file mode 100644 index 94adbe0bde..0000000000 --- a/src/cldc-library/scala/Predef.scala +++ /dev/null @@ -1,188 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala - - -/** The Predef 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 ------------------------------------------------------------ - - type byte = scala.Byte - type short = scala.Short - type char = scala.Char - type int = scala.Int - type long = scala.Long - type boolean = scala.Boolean - type unit = scala.Unit - - /** @deprecated use Int instead */ - @deprecated type Integer = java.lang.Integer - /** @deprecated use Char instead */ - @deprecated type Character = java.lang.Character - - type String = java.lang.String - type Class[T] = java.lang.Class[T] - type Runnable = java.lang.Runnable - - type Throwable = java.lang.Throwable - type Exception = java.lang.Exception - type Error = java.lang.Error - - type AssertionError = java.lang.Error - type RuntimeException = java.lang.RuntimeException - type NullPointerException = java.lang.NullPointerException - type ClassCastException = java.lang.ClassCastException - type IndexOutOfBoundsException = java.lang.IndexOutOfBoundsException - type ArrayIndexOutOfBoundsException = java.lang.ArrayIndexOutOfBoundsException - type StringIndexOutOfBoundsException = java.lang.StringIndexOutOfBoundsException - type UnsupportedOperationException = RuntimeException //java.lang.UnsupportedOperationException - type IllegalArgumentException = java.lang.IllegalArgumentException - type NoSuchElementException = java.util.NoSuchElementException - type NumberFormatException = java.lang.NumberFormatException - - // miscelleaneous ----------------------------------------------------- - - //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 Error(message) - - def exit: Nothing = exit(0) - - def exit(status: Int): Nothing = { - java.lang.System.exit(status) - throw new Throwable() - } - - def assert(assertion: Boolean) { - if (!assertion) - throw new AssertionError("assertion failed") - } - - def assert(assertion: Boolean, message: Any) { - if (!assertion) - throw new AssertionError("assertion failed: " + message) - } - - def assume(assumption: Boolean) { - if (!assumption) - throw new IllegalArgumentException("assumption failed") - } - - def assume(assumption: Boolean, message: Any) { - if (!assumption) - throw new IllegalArgumentException("assumption 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 ArrowAssoc[A](x: A) { - def -> [B](y: B): Tuple2[A, B] = Tuple2(x, 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) - - // 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 booleanWrapper(x: Boolean) = new runtime.RichBoolean(x) - - implicit def stringWrapper(x: String) = new runtime.RichString(x) - implicit def stringBuilderWrapper(x : StringBuilder) = new runtime.RichStringBuilder(x) - - implicit def any2stringadd(x: Any) = new runtime.StringAdd(x) - - implicit def exceptionWrapper(exc: Throwable) = new runtime.RichException(exc) - - /** 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 short2int(x: Short): Int = x.toInt - implicit def short2long(x: Short): Long = x.toLong - - implicit def char2int(x: Char): Int = x.toInt - implicit def char2long(x: Char): Long = x.toLong - - implicit def int2long(x: Int): Long = x.toLong - - implicit def byte2Byte(x: Byte) = new java.lang.Byte(x) - implicit def short2Short(x: Short) = new java.lang.Short(x) - implicit def char2Character(x: Char) = new java.lang.Character(x) - implicit def int2Integer(x: Int) = new java.lang.Integer(x) - implicit def long2Long(x: Long) = new java.lang.Long(x) - implicit def boolean2Boolean(x: Boolean) = new java.lang.Boolean(x) - - /** any array projection can be automatically converted into an array */ - implicit def forceArrayProjection[A](x: Array.Projection[A]): Array[A] = x.force - /** any random access character seq (including rich string can be converted into a string */ - implicit def forceRandomAccessCharSeq(x: runtime.RichString): String = x.mkString - - def currentThread = java.lang.Thread.currentThread() - -} diff --git a/src/cldc-library/scala/Random.scala b/src/cldc-library/scala/Random.scala deleted file mode 100644 index 0d14703a68..0000000000 --- a/src/cldc-library/scala/Random.scala +++ /dev/null @@ -1,41 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2006-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala - -/** (see http://java.sun.com/javame/reference/apis/jsr030/) - * - * @author Stephane Micheloud - */ -class Random(val self: java.util.Random) { - - /** Creates a new random number generator using a single long seed. */ - def this(seed: Long) = this(new java.util.Random(seed)) - - /** Creates a new random number generator using a single integer seed. */ - def this(seed: Int) = this(seed.toLong) - - /** Creates a new random number generator. */ - def this() = this(compat.Platform.currentTime) - - /** Returns the next pseudorandom, uniformly distributed int value - * from this random number generator's sequence. - */ - def nextInt(): Int = self.nextInt() - - /** Returns the next pseudorandom, uniformly distributed long value - * from this random number generator's sequence. - */ - def nextLong(): Long = self.nextLong() - - def setSeed(seed: Long) { self.setSeed(seed) } - -} diff --git a/src/cldc-library/scala/StringBuilder.scala b/src/cldc-library/scala/StringBuilder.scala deleted file mode 100644 index 271d9b9306..0000000000 --- a/src/cldc-library/scala/StringBuilder.scala +++ /dev/null @@ -1,862 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2006-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala - -import Predef._ - -/**

- * A mutable sequence of characters. This class provides an API compatible - * with java.lang.StringBuilder, but with no guarantee of - * synchronization. - *

- * - * @author Stephane Micheloud - * @version 1.0 - */ -final class StringBuilder(initCapacity: Int, private val initValue: String) -extends (Int => Char) with Proxy { - if (initCapacity < 0) throw new IllegalArgumentException - if (initValue eq null) throw new NullPointerException - - /** The value is used for character storage. */ - private var value = 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 capacity argument. - * - * @param capacity the initial capacity. - * @throws NegativeArraySizeException if the capacity - * argument is less than 0. - */ - def this(capacity: Int) = this(capacity, "") - - def this(str: String) = this(16, str) - - append(initValue) - - def self = this - - def toArray: Array[Char] = value - - def length: Int = count - - def length_=(n: Int) { setLength(n) } - - /** Sets the length of the character sequence. - * - * @param newLength the new length - * @throws IndexOutOfBoundsException if the n argument is negative. - */ - def setLength(n: Int) { - if (n < 0) - throw new StringIndexOutOfBoundsException(n) - if (n > value.length) expandCapacity(n) - if (count < n) - while (count < n) { - value(count) = '\0'; count += 1 - } - else - 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 = value.length - - /** Same as ensureCapacity. */ - def capacity_=(n: Int) { ensureCapacity(n) } - - /**

- * 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: - *

- * - *

- * If the n argument is non-positive, this - * method takes no action and simply returns. - *

- * - * @param n the minimum desired capacity. - */ - def ensureCapacity(n: Int) { - if (n > value.length) expandCapacity(n) - } - - private def expandCapacity(n: Int) { - val newCapacity = (value.length + 1) * 2 - value = StringBuilder.copyOf( - value, - if (newCapacity < 0) Math.MAX_INT else if (n > newCapacity) n else newCapacity - ) - } - - /**

- * Returns the Char value in this sequence at the specified index. - * The first Char value is at index 0, the next at index - * 1, and so on, as in array indexing. - *

- *

- * The index argument must be greater than or equal to - * 0, and less than the length of this sequence. - *

- * - * @param index the index of the desired Char value. - * @return the Char value at the specified index. - * @throws IndexOutOfBoundsException if index is - * negative or greater than or equal to length(). - */ - def charAt(index: Int): Char = { - if (index < 0 || index >= count) - throw new StringIndexOutOfBoundsException(index) - value(index) - } - - /** Same as charAt. */ - def apply(i: Int): Char = charAt(i) - - /**

- * Removes the Char at the specified position in this - * sequence. This sequence is shortened by one Char. - *

- * - * @param index Index of Char to remove - * @return This object. - * @throws StringIndexOutOfBoundsException if the index - * is negative or greater than or equal to length(). - */ - def deleteCharAt(index: Int): StringBuilder = { - if (index < 0 || index >= count) - throw new StringIndexOutOfBoundsException(index) - compat.Platform.arraycopy(value, index + 1, value, index, count - index - 1) - count -= 1 - this - } - - /**

- * The character at the specified index is set to ch. This - * sequence is altered to represent a new character sequence that is - * identical to the old character sequence, except that it contains the - * character ch at position index. - *

- *

- * The index argument must be greater than or equal to - * 0, and less than the length of this sequence. - *

- * - * @param index the index of the character to modify. - * @param ch the new character. - * @throws IndexOutOfBoundsException if index is - * negative or greater than or equal to length(). - */ - def setCharAt(index: Int, c: Char) { - if (index < 0 || index >= count) - throw new StringIndexOutOfBoundsException(index) - value(index) = c - } - - /** Same as setCharAt. */ - def update(i: Int, c: Char) { setCharAt(i, c) } - - /** Returns a new String 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 start is - * less than zero, or greater than the length of this object. - */ - def substring(start: Int): String = substring(start, count) - - /** Returns a new String that contains a subsequence of - * characters currently contained in this sequence. The - * substring begins at the specified start and - * extends to the character at index end - 1. - * - * @param start The beginning index, inclusive. - * @param end The ending index, exclusive. - * @return The new string. - * @throws StringIndexOutOfBoundsException if start - * or end are negative or greater than - * length(), or start is - * greater than end. - */ - 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(value, start, end - start) - } - - /**

- * Appends the string representation of the Any - * argument. - *

- *

- * The argument is converted to a string as if by the method - * String.valueOf, and the characters of that - * string are then appended to this sequence. - *

- * - * @param x an Any object. - * @return a reference to this object. - */ - def append(x: Any): StringBuilder = - append(String.valueOf(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 - if (len > 0) { - val newCount = count + len - if (newCount > value.length) expandCapacity(newCount) - compat.Platform.arraycopy(str.toCharArray, 0, value, count, len) - count = newCount - } - 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 - val newCount = count + len - if (newCount > value.length) expandCapacity(newCount) - compat.Platform.arraycopy(sb.toArray, 0, value, count, len) - count = newCount - this - } - - /**

- * Appends the string representation of the Char sequence - * argument to this sequence. - *

- *

- * 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. - *

- * - * @param x the characters to be appended. - * @return a reference to this object. - */ - def append(x: Seq[Char]): StringBuilder = - append(x.toArray, 0, x.length) - - /**

- * Appends the string representation of the Char array - * argument to this sequence. - *

- *

- * 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. - *

- * - * @param x the characters to be appended. - * @return a reference to this object. - */ - def append(x: Array[Char]): StringBuilder = - append(x, 0, x.length) - - /**

- * Appends the string representation of a subarray of the - * char array argument to this sequence. - *

- *

- * Characters of the Char array x, starting at - * index offset, are appended, in order, to the contents - * of this sequence. The length of this sequence increases - * by the value of len. - *

- * - * @param x the characters to be appended. - * @param offset the index of the first Char to append. - * @param len the number of Chars to append. - * @return a reference to this object. - */ - def append(x: Array[Char], offset: Int, len: Int): StringBuilder = { - val newCount = count + len - if (newCount > value.length) expandCapacity(newCount) - compat.Platform.arraycopy(x, offset, value, count, len) - count = newCount - this - } - - /**

- * Appends the string representation of the Boolean - * argument to the sequence. - *

- *

- * The argument is converted to a string as if by the method - * String.valueOf, and the characters of that - * string are then appended to this sequence. - *

- * - * @param x a Boolean. - * @return a reference to this object. - */ - def append(x: Boolean): StringBuilder = { - if (x) { - val newCount = count + 4 - if (newCount > value.length) expandCapacity(newCount) - value(count) = 't'; count += 1 - value(count) = 'r'; count += 1 - value(count) = 'u'; count += 1 - value(count) = 'e'; count += 1 - } else { - val newCount = count + 5 - if (newCount > value.length) expandCapacity(newCount) - value(count) = 'f'; count += 1 - value(count) = 'a'; count += 1 - value(count) = 'l'; count += 1 - value(count) = 's'; count += 1 - value(count) = 'e'; count += 1 - } - this - } - - def append(x: Byte): StringBuilder = - append(String.valueOf(x)) - - def append(x: Char): StringBuilder = { - val newCount = count + 1 - if (newCount > value.length) expandCapacity(newCount) - value(count) = x; count += 1 - this - } - - def append(x: Short): StringBuilder = - append(String.valueOf(x)) - - def append(x: Int): StringBuilder = - append(String.valueOf(x)) - - def append(x: Long): StringBuilder = - append(String.valueOf(x)) - - /** Removes the characters in a substring of this sequence. - * The substring begins at the specified start and extends to - * the character at index end - 1 or to the end of the - * sequence if no such character exists. If - * start is equal to end, no changes are made. - * - * @param start The beginning index, inclusive. - * @param end The ending index, exclusive. - * @return This object. - * @throws StringIndexOutOfBoundsException if start - * is negative, greater than length(), or - * greater than end. - */ - 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(value, start + len, value, start, count - end0) - count -= len - } - this - } - - /** Replaces the characters in a substring of this sequence - * with characters in the specified String. The substring - * begins at the specified start and extends to the character - * at index end - 1 or to the end of the sequence if no such - * character exists. First the characters in the substring are removed and - * then the specified String is inserted at start. - * - * @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 start - * is negative, greater than length(), or - * greater than end. - */ - 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) - if (newCount > value.length) expandCapacity(newCount) - - compat.Platform.arraycopy(value, end, value, start + len, count - end) - compat.Platform.arraycopy(str.toArray, 0, value, start, len) - count = newCount - this - } - - /** Inserts the string representation of a subarray of the str - * array argument into this sequence. The subarray begins at the specified - * offset and extends len chars. - * The characters of the subarray are inserted into this sequence at - * the position indicated by index. The length of this - * sequence increases by len Chars. - * - * @param index position at which to insert subarray. - * @param str a Char array. - * @param offset the index of the first char in subarray to - * be inserted. - * @param len the number of Chars in the subarray to - * be inserted. - * @return This object - * @throws StringIndexOutOfBoundsException if index - * is negative or greater than length(), or - * offset or len are negative, or - * (offset+len) is greater than - * str.length. - */ - def insert(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) - val newCount = count + len - if (newCount > value.length) expandCapacity(newCount) - compat.Platform.arraycopy(value, index, value, index + len, count - index) - compat.Platform.arraycopy(str, offset, value, index, len) - count = newCount - this - } - - /**

- * Inserts the string representation of the Any - * argument into this character sequence. - *

- *

- * The second argument is converted to a string as if by the method - * String.valueOf, and the characters of that - * string are then inserted into this sequence at the indicated - * offset. - *

- *

- * The offset argument must be greater than or equal to - * 0, and less than or equal to the length of this - * sequence. - *

- * - * @param offset the offset. - * @param x an Any value. - * @return a reference to this object. - * @throws StringIndexOutOfBoundsException if the offset is invalid. - */ - def insert(at: Int, x: Any): StringBuilder = - insert(at, String.valueOf(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 - val newCount = count + len - if (newCount > value.length) expandCapacity(newCount) - compat.Platform.arraycopy(value, at, value, at + len, count - at) - compat.Platform.arraycopy(str.toArray: Array[Char], 0, value, at, len) - count = newCount - this - } - - /** Inserts the string representation of the Char 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 insert(at: Int, x: Seq[Char]): StringBuilder = - insert(at, x.toArray) - - /** Inserts the string representation of the Char 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 insert(at: Int, x: Array[Char]): StringBuilder = { - if (at < 0 || at > count) - throw new StringIndexOutOfBoundsException(at) - val len = x.length - val newCount = count + len - if (newCount > value.length) expandCapacity(newCount) - compat.Platform.arraycopy(value, at, value, at + len, count - at) - compat.Platform.arraycopy(x, 0, value, at, len) - count = newCount - this - } - - /**

- * Inserts the string representation of the Boolean argument - * into this sequence. - *

- *

- * The offset argument must be greater than or equal to 0, and less than - * or equal to the length of this sequence. - *

- * - * @param at the offset position. - * @param x a Boolean value. - * @return a reference to this object. - */ - def insert(at: Int, x: Boolean): StringBuilder = - insert(at, String.valueOf(x)) - - /**

- * Inserts the string representation of the Byte argument - * into this sequence. - *

- *

- * The offset argument must be greater than or equal to 0, and less than - * or equal to the length of this sequence. - *

- * - * @param at the offset position. - * @param x a Byte value. - * @return a reference to this object. - */ - def insert(at: Int, x: Byte): StringBuilder = - insert(at, String.valueOf(x)) - - /**

- * Inserts the string representation of the Char argument - * into this sequence. - *

- *

- * The offset argument must be greater than or equal to 0, and less than - * or equal to the length of this sequence. - *

- * - * @param at the offset position. - * @param x a Char value. - * @return a reference to this object. - */ - def insert(at: Int, x: Char): StringBuilder = { - if (at < 0 || at > count) - throw new StringIndexOutOfBoundsException(at) - val newCount = count + 1 - if (newCount > value.length) expandCapacity(newCount) - compat.Platform.arraycopy(value, at, value, at + 1, count - at) - value(at) = x - count = newCount - this - } - - /**

- * Inserts the string representation of the Short argument - * into this sequence. - *

- *

- * The offset argument must be greater than or equal to 0, and less than - * or equal to the length of this sequence. - *

- * - * @param at the offset position. - * @param x a Short value. - * @return a reference to this object. - */ - def insert(at: Int, x: Short): StringBuilder = - insert(at, String.valueOf(x)) - - /**

- * Inserts the string representation of the Int argument - * into this sequence. - *

- *

- * The offset argument must be greater than or equal to 0, and less than - * or equal to the length of this sequence. - *

- * - * @param at the offset position. - * @param x a Int value. - * @return a reference to this object. - */ - def insert(at: Int, x: Int): StringBuilder = - insert(at, String.valueOf(x)) - - /**

- * Inserts the string representation of the Long argument - * into this sequence. - *

- *

- * The offset argument must be greater than or equal to 0, and less than - * or equal to the length of this sequence. - *

- * - * @param at the offset position. - * @param x a Long value. - * @return a reference to this object. - */ - def insert(at: Int, x: Long): StringBuilder = - insert(at, String.valueOf(x)) - - /**

- * Returns the index within this string of the first occurrence of the - * specified substring. The integer returned is the smallest value - * k such that: - *

- *
-   *  this.toString().startsWith(str, k)
- *
- *

- * is true. - *

- * - * @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, -1 is returned. - * @throws NullPointerException if str is null. - */ - def indexOf(str: String): Int = indexOf(str, 0) - - /**

- * 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 k for which: - *

-   *    k >= Math.min(fromIndex, str.length()) &&
-   *                   this.toString().startsWith(str, k)
- *

- * If no such value of k exists, then -1 - * is returned. - *

- * - * @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(value, 0, count, str.toArray, 0, str.length(), fromIndex) - - /**

- * 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 this.length(). - * The returned index is the largest value k such that - *

- *
-   *  this.toString().startsWith(str, k)
- *
- *

- * is true. - *

- * - * @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, -1 is returned. - * @throws NullPointerException if str is null. - */ - def lastIndexOf(str: String): Int = lastIndexOf(str, count) - - /**

- * Returns the index within this string of the last occurrence of the - * specified substring. The integer returned is the largest value - * k such that: - *

-   *    k <= Math.min(fromIndex, str.length()) &&
-   *                   this.toString().startsWith(str, k)
- *

- * If no such value of k exists, then -1 - * is returned. - *

- * - * @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(value, 0, count, str.toArray, 0, str.length(), fromIndex) - - /**

- * 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. - *

- *

- * Let n be the character length of this character sequence - * (not the length in Char values) just prior to - * execution of the reverse method. Then the - * character at index k in the new character sequence is - * equal to the character at index n-k-1 in the old - * character sequence. - *

- * - * @return a reference to this object. - */ - def reverse(): StringBuilder = { - val n = count - 1 - var j = (n-1) >> 1 - while (j >= 0) { - val temp = value(j) - val temp2 = value(n - j) - value(j) = temp2 - value(n - j) = temp - j -= 1 - } - this - } - - /** Returns a string representing the data in this sequence. - * A new String object is allocated and initialized to - * contain the character sequence currently represented by this - * object. This String is then returned. Subsequent - * changes to this sequence do not affect the contents of the - * String. - * - * @return a string representation of this sequence of characters. - */ - override def toString(): String = new String(value, 0, count) - -} - - -object StringBuilder { - - // method java.util.Arrays.copyOf exists since 1.6 - private def copyOf(src: Array[Char], newLength: Int): Array[Char] = { - val dest = new Array[Char](newLength) - val (start, end) = - if (src.length < newLength) (src.length, newLength) - else (newLength, src.length) - compat.Platform.arraycopy(src, 0, dest, 0, start) - // For any indices that are valid in the copy but not the original, - // the copy will contain '\\u000'. - for (i <- start until end) dest(i) = '\0' - dest - } - - private def indexOf(source: Array[Char], sourceOffset: Int, sourceCount: Int, - target: Array[Char], targetOffset: Int, targetCount: Int, - fromIndex: Int): Int = - 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 - } -} diff --git a/src/cldc-library/scala/Symbol.scala b/src/cldc-library/scala/Symbol.scala deleted file mode 100644 index 60010cacfe..0000000000 --- a/src/cldc-library/scala/Symbol.scala +++ /dev/null @@ -1,48 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala - -/**

- * Instances of Symbol can be created easily with - * Scala's built-in quote mechanism. - *

- *

- * For instance, the Scala - * term 'mysym will invoke the constructor of the - * Symbol class in the following way: - * new Symbol("mysym"). - *

- * - * @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 - } - - /**

- * Makes this symbol into a unique reference. - *

- *

- * If two interened symbols are equal (i.e. they have the same name) - * then they must be identical (wrt reference equality). - *

- * - * @return the unique reference to this symbol. - */ - def intern: Symbol = this - -} diff --git a/src/cldc-library/scala/collection/mutable/CloneableCollection.scala b/src/cldc-library/scala/collection/mutable/CloneableCollection.scala deleted file mode 100644 index 6dc8ed7f8e..0000000000 --- a/src/cldc-library/scala/collection/mutable/CloneableCollection.scala +++ /dev/null @@ -1,19 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala.collection.mutable - -/** The J2ME version of the library defined this trait with a clone method - * to substitute for the lack of Object.clone there - */ -trait CloneableCollection { - def clone(): AnyRef = Predef.error("Cloning not supported") -} diff --git a/src/cldc-library/scala/compat/Platform.scala b/src/cldc-library/scala/compat/Platform.scala deleted file mode 100644 index 79b07ba0a1..0000000000 --- a/src/cldc-library/scala/compat/Platform.scala +++ /dev/null @@ -1,56 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala.compat - - -import java.lang.System -import Predef._ - -object Platform { - - //type StackOverflowError = java.lang.StackOverflowError - type ConcurrentModificationException = java.lang.RuntimeException - - /** - * @param src .. - * @param srcPos .. - * @param dest .. - * @param destPos .. - * @param length .. - */ - def arraycopy(src: AnyRef, srcPos: Int, dest: AnyRef, destPos: Int, length: Int): Unit = - System.arraycopy(src, srcPos, dest, 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 = - throw new RuntimeException("" + elemClass + "[" + length+ "]") - //java.lang.reflect.Array.newInstance(elemClass, length) - - //def arrayclear(arr: Array[Int]): Unit = java.util.Arrays.fill(arr, 0) - def arrayclear(arr: Array[Int]): Unit = for (i <- 0 to arr.length) arr(i) = 0 - - def getClassForName(name: String): Class[_] = java.lang.Class.forName(name) - - val EOL = "\n" - - def currentTime: Long = System.currentTimeMillis() - - def collectGarbage: Unit = System.gc() - -} - diff --git a/src/cldc-library/scala/runtime/BooleanRef.java b/src/cldc-library/scala/runtime/BooleanRef.java deleted file mode 100644 index dc9b6f8ca6..0000000000 --- a/src/cldc-library/scala/runtime/BooleanRef.java +++ /dev/null @@ -1,19 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala.runtime; - - -public class BooleanRef { - public boolean elem; - public BooleanRef(boolean elem) { this.elem = elem; } - public String toString() { return String.valueOf(elem); } -} diff --git a/src/cldc-library/scala/runtime/BoxedAnyArray.scala b/src/cldc-library/scala/runtime/BoxedAnyArray.scala deleted file mode 100644 index 751f1a1e14..0000000000 --- a/src/cldc-library/scala/runtime/BoxedAnyArray.scala +++ /dev/null @@ -1,234 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala.runtime - - -import Predef._ -import compat.Platform - -/** - * Arrays created by new Array[T](length) where T - * is a type variable. - */ -@serializable -final class BoxedAnyArray(val length: Int) extends BoxedArray { - - private var boxed = new Array[AnyRef](length) - private val hash = boxed.hashCode() - private var unboxed: AnyRef = null - private var elemClass: Class[_] = null - - def apply(index: Int): Any = synchronized { - if (unboxed eq null) - boxed(index); - else if (elemClass eq classOf[Int]) - Int.box(unboxed.asInstanceOf[Array[Int]](index)) - else if (elemClass eq classOf[Long]) - Long.box(unboxed.asInstanceOf[Array[Long]](index)) - else if (elemClass eq classOf[Char]) - Char.box(unboxed.asInstanceOf[Array[Char]](index)) - else if (elemClass eq classOf[Byte]) - Byte.box(unboxed.asInstanceOf[Array[Byte]](index)) - else if (elemClass eq classOf[Short]) - Short.box(unboxed.asInstanceOf[Array[Short]](index)) - else if (elemClass eq classOf[Boolean]) - Boolean.box(unboxed.asInstanceOf[Array[Boolean]](index)) - else - unboxed.asInstanceOf[Array[AnyRef]](index) - } - - def update(index: Int, _elem: Any): Unit = synchronized { - val elem = _elem.asInstanceOf[AnyRef] - if (unboxed eq null) - boxed(index) = elem - else if (elemClass eq classOf[Int]) - unboxed.asInstanceOf[Array[Int]](index) = Int.unbox(elem) - else if (elemClass eq classOf[Long]) - unboxed.asInstanceOf[Array[Long]](index) = Long.unbox(elem) - else if (elemClass eq classOf[Char]) - unboxed.asInstanceOf[Array[Char]](index) = Char.unbox(elem) - else if (elemClass eq classOf[Byte]) - unboxed.asInstanceOf[Array[Byte]](index) = Byte.unbox(elem) - else if (elemClass eq classOf[Short]) - unboxed.asInstanceOf[Array[Short]](index) = Short.unbox(elem) - else if (elemClass eq classOf[Boolean]) - unboxed.asInstanceOf[Array[Boolean]](index) = Boolean.unbox(elem) - else - unboxed.asInstanceOf[Array[AnyRef]](index) = elem - } - - def unbox(elemTag: String): AnyRef = - if (elemTag eq ScalaRunTime.IntTag) unbox(classOf[Int]) - else if (elemTag eq ScalaRunTime.LongTag) unbox(classOf[Long]) - else if (elemTag eq ScalaRunTime.CharTag) unbox(classOf[Char]) - else if (elemTag eq ScalaRunTime.ByteTag) unbox(classOf[Byte]) - else if (elemTag eq ScalaRunTime.ShortTag) unbox(classOf[Short]) - else if (elemTag eq ScalaRunTime.BooleanTag) unbox(classOf[Boolean]) - else unbox(Platform.getClassForName(elemTag)) - - def unbox(elemClass: Class[_]): AnyRef = synchronized { - if (unboxed eq null) { - this.elemClass = elemClass - if (elemClass eq classOf[Int]) { - val newvalue = new Array[Int](length) - var i = 0 - while (i < length) { - newvalue(i) = Int.unbox(boxed(i)) - i += 1 - } - unboxed = newvalue - } else if (elemClass eq classOf[Long]) { - val newvalue = new Array[Long](length) - var i = 0 - while (i < length) { - newvalue(i) = Long.unbox(boxed(i)) - i += 1 - } - unboxed = newvalue; - } else if (elemClass eq classOf[Char]) { - val newvalue = new Array[Char](length) - var i = 0 - while (i < length) { - newvalue(i) = Char.unbox(boxed(i)) - i += 1 - } - unboxed = newvalue - } else if (elemClass eq classOf[Byte]) { - val newvalue = new Array[Byte](length) - var i = 0 - while (i < length) { - newvalue(i) = Byte.unbox(boxed(i)) - i += 1 - } - unboxed = newvalue - } else if (elemClass eq classOf[Short]) { - val newvalue = new Array[Short](length) - var i = 0 - while (i < length) { - newvalue(i) = Short.unbox(boxed(i)) - i += 1 - } - unboxed = newvalue - } else if (elemClass eq classOf[Boolean]) { - val newvalue = new Array[Boolean](length) - var i = 0 - while (i < length) { - newvalue(i) = Boolean.unbox(boxed(i)) - i += 1 - } - unboxed = newvalue; -// } else if (elemClass == boxed.getClass().getComponentType()) { -// // todo: replace with ScalaRunTime.AnyRef.class -// unboxed = boxed - } else { - unboxed = Platform.createArray(elemClass, length) - Platform.arraycopy(boxed, 0, unboxed, 0, length) - } - boxed = null - } - unboxed - } - - override def equals(other: Any): Boolean = ( - other.isInstanceOf[BoxedAnyArray] && (this eq (other.asInstanceOf[BoxedAnyArray])) || - (if (unboxed eq null) boxed == other else unboxed == other) - ) - - override def hashCode(): Int = hash - - def value: AnyRef = { - if (unboxed eq null) throw new NotDefinedError("BoxedAnyArray.value") - unboxed - } - - private def adapt(other: AnyRef): AnyRef = - if (this.unboxed eq null) - other match { - case that: BoxedAnyArray => - if (that.unboxed eq null) { - that.boxed - } else { - if (ScalaRunTime.isValueClass(that.elemClass)) unbox(that.elemClass); - that.unboxed - } - case that: BoxedArray => - adapt(that.value) - case that: Array[Int] => - unbox(ScalaRunTime.IntTag); that - case that: Array[Long] => - unbox(ScalaRunTime.LongTag); that - case that: Array[Char] => - unbox(ScalaRunTime.CharTag); that - case that: Array[Short] => - unbox(ScalaRunTime.ShortTag); that - case that: Array[Byte] => - unbox(ScalaRunTime.ByteTag); that - case that: Array[Boolean] => - unbox(ScalaRunTime.BooleanTag); that - case _ => - other - } - else - other match { - case that: BoxedAnyArray => - if (that.unboxed ne null) that.unboxed - else if (ScalaRunTime.isValueClass(this.elemClass)) that.unbox(this.elemClass) - else that.boxed - case that: BoxedArray => - adapt(that.value) - case _ => - other - } - - override def copyFrom(src: AnyRef, from: Int, to: Int, len: Int) { - val src1 = adapt(src) - Array.copy(src1, from, if (unboxed ne null) unboxed else boxed, to, len) - } - - override def copyTo(from: Int, dest: AnyRef, to: Int, len: Int) { - var dest1 = adapt(dest) - Array.copy(if (unboxed ne null) unboxed else boxed, from, dest1, to, len) - } - - override def subArray(start: Int, end: Int): AnyRef = { - val result = new BoxedAnyArray(end - start); - Array.copy(this, start, result, 0, end - start) - result - } - - final override def filter(p: Any => Boolean): BoxedArray = { - val include = new Array[Boolean](length) - var len = 0 - var i = 0 - while (i < length) { - if (p(this(i))) { include(i) = true; len += 1 } - i += 1 - } - val result = new BoxedAnyArray(len) - len = 0 - i = 0 - while (len < result.length) { - if (include(i)) { result(len) = this(i); len += 1 } - i += 1 - } - result - } - override protected def newArray(length : Int, elements : Iterator[Any]) = { - val result = new BoxedAnyArray(length) - var i = 0 - while (elements.hasNext) { - result(i) = elements.next - i += 1 - } - result - } -} diff --git a/src/cldc-library/scala/runtime/BoxedObjectArray.scala b/src/cldc-library/scala/runtime/BoxedObjectArray.scala deleted file mode 100644 index c79a3ee32a..0000000000 --- a/src/cldc-library/scala/runtime/BoxedObjectArray.scala +++ /dev/null @@ -1,73 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala.runtime - - -import Predef._ -import compat.Platform.createArray - -@serializable -final class BoxedObjectArray(val value: Array[AnyRef]) extends BoxedArray { - - def length: Int = value.length - - def apply(index: Int): Any = value(index) - - def update(index: Int, elem: Any) { - value(index) = elem.asInstanceOf[AnyRef] - } - - def unbox(elemTag: String): AnyRef = value - def unbox(elemClass: Class[_]): AnyRef = value - - override def equals(other: Any): Boolean = - value == other || - other.isInstanceOf[BoxedObjectArray] && value == other.asInstanceOf[BoxedObjectArray].value - - override def hashCode(): Int = value.hashCode() - - private def create(length: Int): Array[AnyRef] = { - //createArray(value.getClass().getComponentType(), length).asInstanceOf[Array[AnyRef]] - new Array[AnyRef](length) - } - - override def subArray(start: Int, end: Int): Array[AnyRef] = { - val result = create(end - start) - Array.copy(value, start, result, 0, end - start) - result - } - - final override def filter(p: Any => Boolean): BoxedArray = { - val include = new Array[Boolean](value.length) - var len = 0 - var i = 0 - while (i < value.length) { - if (p(value(i))) { include(i) = true; len += 1 } - i += 1 - } - val result = create(len) - len = 0 - i = 0 - while (len < result.length) { - if (include(i)) { result(len) = value(i); len += 1 } - i += 1 - } - new BoxedObjectArray(result) - } - - override protected def newArray(length: Int, elements: Iterator[Any]) = { - val result = create(length) - elements.map(_.asInstanceOf[AnyRef]).copyToArray(result, 0) - new BoxedObjectArray(result) - } -} - diff --git a/src/cldc-library/scala/runtime/BoxedUnit.java b/src/cldc-library/scala/runtime/BoxedUnit.java deleted file mode 100644 index f8cded3e83..0000000000 --- a/src/cldc-library/scala/runtime/BoxedUnit.java +++ /dev/null @@ -1,33 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala.runtime; - - -public final class BoxedUnit -{ - - public final static BoxedUnit UNIT = new BoxedUnit(); - - private BoxedUnit() { } - - public boolean equals(java.lang.Object other) { - return this == other; - } - - public int hashCode() { - return 0; - } - - public String toString() { - return "()"; - } -} diff --git a/src/cldc-library/scala/runtime/BoxesRunTime.java b/src/cldc-library/scala/runtime/BoxesRunTime.java deleted file mode 100644 index 9ab3e3c548..0000000000 --- a/src/cldc-library/scala/runtime/BoxesRunTime.java +++ /dev/null @@ -1,361 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2006-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala.runtime; - -/** An object (static class) that defines methods used for creating, - * reverting, and calculating with, boxed values. There are four classes - * of methods in this object: - * - High-performance value boxing methods that feed from a pre- - * computed map of instances for the most common instanciations. - * - Convenience unboxing methods returning default value on null. - * - The generalised comparison method to be used when an object may - * be a boxed value. - * - Standard value operators for boxed number and quasi-number values. - * - * @author Gilles Dubochet - * @author Martin Odersky - * @contributor Stepan Koltsov - * @version 2.0 */ -public class BoxesRunTime { - - private static final int CHAR = 0, BYTE = 1, SHORT = 2, INT = 3, LONG = 4, OTHER = 7; - - private static int typeCode(Object a) { - if (a instanceof Integer) return INT; - if (a instanceof Character) return CHAR; - if (a instanceof Long) return LONG; - if (a instanceof Byte) return BYTE; - if (a instanceof Short) return SHORT; - return OTHER; - } - -/* BOXING ... BOXING ... BOXING ... BOXING ... BOXING ... BOXING ... BOXING ... BOXING */ - - private static int charLowBound = 0; - private static int charUpBound = 255; - private static Character[] charCache = new Character[charUpBound - charLowBound + 1]; - - private static int byteLowBound = -128; - private static int byteUpBound = 127; - private static Byte[] byteCache = new Byte[byteUpBound - byteLowBound + 1]; - - private static int shortLowBound = -128; - private static int shortUpBound = 127; - private static Short[] shortCache = new Short[shortUpBound - shortLowBound + 1]; - - private static int intLowBound = -128; - private static int intUpBound = 1024; - private static Integer[] intCache = new Integer[intUpBound - intLowBound + 1]; - - private static int longLowBound = -128; - private static int longUpBound = 1024; - private static Long[] longCache = new Long[longUpBound - longLowBound + 1]; - - static { - int idx = 0; - while (idx <= charUpBound - charLowBound) { - charCache[idx] = new Character((char)(idx + charLowBound)); - idx = idx + 1; - } - idx = 0; - while (idx <= byteUpBound - byteLowBound) { - byteCache[idx] = new Byte((byte)(idx + byteLowBound)); - idx = idx + 1; - } - idx = 0; - while (idx <= shortUpBound - shortLowBound) { - shortCache[idx] = new Short((short)(idx + shortLowBound)); - idx = idx + 1; - } - idx = 0; - while (idx <= intUpBound - intLowBound) { - intCache[idx] = new Integer((int)(idx + intLowBound)); - idx = idx + 1; - } - idx = 0; - while (idx <= longUpBound - longLowBound) { - longCache[idx] = new Long((long)(idx + longLowBound)); - idx = idx + 1; - } - } - - private static final Boolean TRUE = new Boolean(true); - private static final Boolean FALSE = new Boolean(false); - public static Boolean boxToBoolean(boolean b) { - return b ? TRUE : FALSE; - } - - public static Character boxToCharacter(char c) { - if (c >= charLowBound && c <= charUpBound) - return charCache[(int)c - charLowBound]; - return new Character(c); - } - - public static Byte boxToByte(byte b) { - if (b >= byteLowBound && b <= byteUpBound) - return byteCache[(int)b - byteLowBound]; - return new Byte(b); - } - - public static Short boxToShort(short s) { - if (s >= shortLowBound && s <= shortUpBound) - return shortCache[(int)s - shortLowBound]; - return new Short(s); - } - - public static Integer boxToInteger(int i) { - if (i >= intLowBound && i <= intUpBound) - return intCache[(int)i - intLowBound]; - return new Integer(i); - } - - public static Long boxToLong(long l) { - if (l >= longLowBound && l <= longUpBound) - return longCache[(int)l - longLowBound]; - return new Long(l); - } - -/* UNBOXING ... UNBOXING ... UNBOXING ... UNBOXING ... UNBOXING ... UNBOXING ... UNBOXING */ - - public static boolean unboxToBoolean(Object b) { - return b == null ? false : ((Boolean)b).booleanValue(); - } - - public static char unboxToChar(Object c) { - return c == null ? 0 : ((Character)c).charValue(); - } - - public static byte unboxToByte(Object b) { - return b == null ? 0 : ((Byte)b).byteValue(); - } - - public static short unboxToShort(Object s) { - return s == null ? 0 : ((Short)s).shortValue(); - } - - public static int unboxToInt(Object i) { - return i == null ? 0 : ((Integer)i).intValue(); - } - - public static long unboxToLong(Object l) { - return l == null ? 0 : ((Long)l).longValue(); - } - - /* - public static boolean unboxToBoolean(Object b) { - if (b == null) - throw new ClassCastException("null is no Boolean value"); - return ((Boolean)b).booleanValue(); - } - - public static char unboxToChar(Object c) { - if (c == null) - throw new ClassCastException("null is no Char value"); - return ((Character)c).charValue(); - } - - public static byte unboxToByte(Object b) { - if (b == null) - throw new ClassCastException("null is no Byte value"); - return ((Byte)b).byteValue(); - } - - public static short unboxToShort(Object s) { - if (s == null) - throw new ClassCastException("null is no Short value"); - return ((Short)s).shortValue(); - } - - public static int unboxToInt(Object i) { - if (i == null) - throw new ClassCastException("null is no Int value"); - return ((Integer)i).intValue(); - } - - public static long unboxToLong(Object l) { - if (l == null) - throw new ClassCastException("null is no Long value"); - return ((Long)l).longValue(); - } - */ - -/* COMPARISON ... COMPARISON ... COMPARISON ... COMPARISON ... COMPARISON ... COMPARISON */ - - /** A rich implementation of the equals method that overrides the - * default equals because Java's boxed primitives are utterly broken. This equals - * is inserted instead of a normal equals by the Scala compiler (in the - * ICode phase, method genEqEqPrimitive) only when either - * side of the comparison is a subclass of AnyVal, of - * java.lang.Number, of java.lang.Character or - * is exactly Any or AnyRef. */ - public static boolean equals(Object a, Object b) { - if (a == null) - return b == null; - if (b == null) - return false; - if (a.equals(b)) - return true; - - final long left = - (a instanceof Integer) ? ((Integer)a).intValue() : - (a instanceof Character) ? ((Character)a).charValue() : - (a instanceof Long) ? ((Long)a).longValue() : - (a instanceof Byte) ? ((Byte)a).byteValue() : - ((Short)a).shortValue(); - - final long right = - (b instanceof Integer) ? ((Integer)b).intValue() : - (b instanceof Character) ? ((Character)b).charValue() : - (b instanceof Long) ? ((Long)b).longValue() : - (b instanceof Byte) ? ((Byte)b).byteValue() : - ((Short)b).shortValue(); - - return left == right; - } - -/* OPERATORS ... OPERATORS ... OPERATORS ... OPERATORS ... OPERATORS ... OPERATORS ... OPERATORS ... OPERATORS */ - - /** arg1 + arg2 */ - public static Object add(Object arg1, Object arg2) throws Error { - throw new Error(); - } - - /** arg1 - arg2 */ - public static Object subtract(Object arg1, Object arg2) throws Error { - throw new Error(); - } - - /** arg1 * arg2 */ - public static Object multiply(Object arg1, Object arg2) throws Error { - throw new Error(); - } - - /** arg1 / arg2 */ - public static Object divide(Object arg1, Object arg2) throws Error { - throw new Error(); - } - - /** arg1 % arg2 */ - public static Object takeModulo(Object arg1, Object arg2) throws Error { - throw new Error(); - } - - /** arg1 >> arg2 */ - public static Object shiftSignedRight(Object arg1, Object arg2) throws Error { - throw new Error(); - } - - /** arg1 << arg2 */ - public static Object shiftSignedLeft(Object arg1, Object arg2) throws Error { - throw new Error(); - } - - /** arg1 >>> arg2 */ - public static Object shiftLogicalRight(Object arg1, Object arg2) throws Error { - throw new Error(); - } - - /** -arg */ - public static Object negate(Object arg) throws Error { - throw new Error(); - } - - /** +arg */ - public static Object positive(Object arg) throws Error { - throw new Error(); - } - - /** arg1 & arg2 */ - public static Object takeAnd(Object arg1, Object arg2) throws Error { - throw new Error(); - } - - /** arg1 | arg2 */ - public static Object takeOr(Object arg1, Object arg2) throws Error { - throw new Error(); - } - - /** arg1 ^ arg2 */ - public static Object takeXor(Object arg1, Object arg2) throws Error { - throw new Error(); - } - - /** arg1 && arg2 */ - public static Object takeConditionalAnd(Object arg1, Object arg2) throws Error { - throw new Error(); - } - - /** arg1 || arg2 */ - public static Object takeConditionalOr(Object arg1, Object arg2) throws Error { - throw new Error(); - } - - /** ~arg */ - public static Object complement(Object arg) throws Error { - throw new Error(); - } - - /** !arg */ - public static Object takeNot(Object arg) throws Error { - throw new Error(); - } - - public static Object testEqual(Object arg1, Object arg2) throws Error { - throw new Error(); - } - - public static Object testNotEqual(Object arg1, Object arg2) throws Error { - throw new Error(); - } - - public static Object testLessThan(Object arg1, Object arg2) throws Error { - throw new Error(); - } - - public static Object testLessOrEqualThan(Object arg1, Object arg2) throws Error { - throw new Error(); - } - - public static Object testGreaterOrEqualThan(Object arg1, Object arg2) throws Error { - throw new Error(); - } - - public static Object testGreaterThan(Object arg1, Object arg2) throws Error { - throw new Error(); - } - - /** arg.toChar */ - public static Character toCharacter(Object arg) throws Error { - throw new Error(); - } - - /** arg.toByte */ - public static Byte toByte(Object arg) throws Error { - throw new Error(); - } - - /** arg.toShort */ - public static Short toShort(Object arg) throws Error { - throw new Error(); - } - - /** arg.toInt */ - public static Integer toInteger(Object arg) throws Error { - throw new Error(); - } - - /** arg.toLong */ - public static Long toLong(Object arg) throws Error { - throw new Error(); - } - -} diff --git a/src/cldc-library/scala/runtime/BoxesUtility.java b/src/cldc-library/scala/runtime/BoxesUtility.java deleted file mode 100644 index 6ebc7e4d14..0000000000 --- a/src/cldc-library/scala/runtime/BoxesUtility.java +++ /dev/null @@ -1,147 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2006-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala.runtime; - -/** - * @author Gilles Dubochet - * @version 1.0 - */ -public class BoxesUtility { - - private static int charLowBound = 0; - private static int charUpBound = 255; - private static Character[] charCache = new Character[charUpBound - charLowBound + 1]; - - private static int byteLowBound = -128; - private static int byteUpBound = 127; - private static Byte[] byteCache = new Byte[byteUpBound - byteLowBound + 1]; - - private static int shortLowBound = -128; - private static int shortUpBound = 127; - private static Short[] shortCache = new Short[shortUpBound - shortLowBound + 1]; - - private static int intLowBound = -128; - private static int intUpBound = 1024; - private static Integer[] intCache = new Integer[intUpBound - intLowBound + 1]; - - private static int longLowBound = -128; - private static int longUpBound = 1024; - private static Long[] longCache = new Long[longUpBound - longLowBound + 1]; - - static { - int idx = 0; - while (idx <= charUpBound - charLowBound) { - charCache[idx] = new Character((char)(idx + charLowBound)); - idx = idx + 1; - } - idx = 0; - while (idx <= byteUpBound - byteLowBound) { - byteCache[idx] = new Byte((byte)(idx + byteLowBound)); - idx = idx + 1; - } - idx = 0; - while (idx <= shortUpBound - shortLowBound) { - shortCache[idx] = new Short((short)(idx + shortLowBound)); - idx = idx + 1; - } - idx = 0; - while (idx <= intUpBound - intLowBound) { - intCache[idx] = new Integer((int)(idx + intLowBound)); - idx = idx + 1; - } - idx = 0; - while (idx <= longUpBound - longLowBound) { - longCache[idx] = new Long((long)(idx + longLowBound)); - idx = idx + 1; - } - } - private static final Boolean TRUE = new Boolean(true); - private static final Boolean FALSE = new Boolean(false); - public static Boolean boxToBoolean(boolean b) { - return b ? TRUE : FALSE; - } - - public static Character boxToCharacter(char c) { - if (c >= charLowBound && c <= charUpBound) - return charCache[(int)c - charLowBound]; - else - return new Character(c); - } - - public static Byte boxToByte(byte b) { - if (b >= byteLowBound && b <= byteUpBound) - return byteCache[(int)b - byteLowBound]; - else - return new Byte(b); - } - - public static Short boxToShort(short s) { - if (s >= shortLowBound && s <= shortUpBound) - return shortCache[(int)s - shortLowBound]; - else - return new Short(s); - } - - public static Integer boxToInteger(int i) { - if (i >= intLowBound && i <= intUpBound) - return intCache[(int)i - intLowBound]; - else - return new Integer(i); - } - - public static Long boxToLong(long l) { - if (l >= longLowBound && l <= longUpBound) - return longCache[(int)l - longLowBound]; - else - return new Long(l); - } - - public static boolean unboxToBoolean(Object b) { - return b == null ? false : ((Boolean)b).booleanValue(); - } - - public static char unboxToChar(Object c) { - if (c == null) - return 0; - else - return ((Character)c).charValue(); - } - - public static byte unboxToByte(Object b) { - if (b == null) - return 0; - else - return ((Byte)b).byteValue(); - } - - public static short unboxToShort(Object s) { - if (s == null) - return 0; - else - return ((Short)s).shortValue(); - } - - public static int unboxToInt(Object i) { - if (i == null) - return 0; - else - return ((Integer)i).intValue(); - } - - public static long unboxToLong(Object l) { - if (l == null) - return 0; - else - return ((Long)l).longValue(); - } - -} diff --git a/src/cldc-library/scala/runtime/ByteRef.java b/src/cldc-library/scala/runtime/ByteRef.java deleted file mode 100644 index 1704d92f8a..0000000000 --- a/src/cldc-library/scala/runtime/ByteRef.java +++ /dev/null @@ -1,19 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala.runtime; - - -public class ByteRef { - public byte elem; - public ByteRef(byte elem) { this.elem = elem; } - public String toString() { return String.valueOf(elem); } -} diff --git a/src/cldc-library/scala/runtime/CharRef.java b/src/cldc-library/scala/runtime/CharRef.java deleted file mode 100644 index 7100978b62..0000000000 --- a/src/cldc-library/scala/runtime/CharRef.java +++ /dev/null @@ -1,19 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala.runtime; - - -public class CharRef { - public char elem; - public CharRef(char elem) { this.elem = elem; } - public String toString() { return String.valueOf(elem); } -} diff --git a/src/cldc-library/scala/runtime/Comparator.java b/src/cldc-library/scala/runtime/Comparator.java deleted file mode 100644 index 0e6f8ecff7..0000000000 --- a/src/cldc-library/scala/runtime/Comparator.java +++ /dev/null @@ -1,53 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2006-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala.runtime; - -/** - * @author Gilles Dubochet - * @author Martin Odersky - * @version 1.2 */ -public class Comparator { - - /** A rich implementation of the equals method that overrides the default - * equals because Java's boxed primitives are utterly broken. This equals - * is inserted instead of a normal equals by the Scala compiler (in the - * ICode phase, method genEqEqPrimitive) only when either - * side of the comparison is a subclass of AnyVal, of - * java.lang.Number, of java.lang.Character or - * is exactly Any or AnyRef, but when both sides - * have different types. */ - public static boolean equals(Object a, Object b) { - if (a == null) - return b == null; - if (b == null) - return false; - if (a.equals(b)) - return true; - - final long left = - (a instanceof Integer) ? ((Integer)a).intValue() : - (a instanceof Character) ? ((Character)a).charValue() : - (a instanceof Long) ? ((Long)a).longValue() : - (a instanceof Byte) ? ((Byte)a).byteValue() : - ((Short)a).shortValue(); - - final long right = - (b instanceof Integer) ? ((Integer)b).intValue() : - (b instanceof Character) ? ((Character)b).charValue() : - (b instanceof Long) ? ((Long)b).longValue() : - (b instanceof Byte) ? ((Byte)b).byteValue() : - ((Short)b).shortValue(); - - return left == right; - } - -} diff --git a/src/cldc-library/scala/runtime/IntRef.java b/src/cldc-library/scala/runtime/IntRef.java deleted file mode 100644 index 47e7eb9411..0000000000 --- a/src/cldc-library/scala/runtime/IntRef.java +++ /dev/null @@ -1,19 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala.runtime; - - -public class IntRef { - public int elem; - public IntRef(int elem) { this.elem = elem; } - public String toString() { return String.valueOf(elem); } -} diff --git a/src/cldc-library/scala/runtime/LongRef.java b/src/cldc-library/scala/runtime/LongRef.java deleted file mode 100644 index 80972014c3..0000000000 --- a/src/cldc-library/scala/runtime/LongRef.java +++ /dev/null @@ -1,19 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala.runtime; - - -public class LongRef { - public long elem; - public LongRef(long elem) { this.elem = elem; } - public String toString() { return String.valueOf(elem); } -} diff --git a/src/cldc-library/scala/runtime/ObjectRef.java b/src/cldc-library/scala/runtime/ObjectRef.java deleted file mode 100644 index 9d7aa0998c..0000000000 --- a/src/cldc-library/scala/runtime/ObjectRef.java +++ /dev/null @@ -1,19 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala.runtime; - - -public class ObjectRef { - public Object elem; - public ObjectRef(Object elem) { this.elem = elem; } - public String toString() { return "" + elem; } -} diff --git a/src/cldc-library/scala/runtime/RichChar.scala b/src/cldc-library/scala/runtime/RichChar.scala deleted file mode 100644 index 019c01ede2..0000000000 --- a/src/cldc-library/scala/runtime/RichChar.scala +++ /dev/null @@ -1,71 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2006-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala.runtime - - -import java.lang.Character -import Predef.NoSuchElementException - -/**

- * For example, in the following code - *

- *
- *    object test extends Application {
- *      Console.println('\40'.isWhitespace)
- *      Console.println('\011'.isWhitespace)
- *      Console.println('1'.asDigit == 1)
- *      Console.println('A'.asDigit == 10)
- *    }
- *

- * the implicit conversions are performed using the predefined view - * Predef.charWrapper. - *

- */ -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 = Character.digit(x, Character.MAX_RADIX) - - //def isControl: Boolean = Character.isISOControl(x) - def isDigit: Boolean = Character.isDigit(x) - //def isLetter: Boolean = Character.isLetter(x) - //def isLetterOrDigit: Boolean = Character.isLetterOrDigit(x) - def isLowerCase: Boolean = Character.isLowerCase(x) - def isUpperCase: Boolean = Character.isUpperCase(x) - //def isWhitespace: Boolean = Character.isWhitespace(x) - - def toLowerCase: Char = Character.toLowerCase(x) - def toUpperCase: Char = Character.toUpperCase(x) - - /** Create an Iterator[Char] over the characters from 'x' to 'y' - 1 - */ - def until(limit: Char): Iterator[Char] = new Iterator[Char] { - private var ch = x - def hasNext: Boolean = ch < limit - def next: Char = - if (hasNext) { val j = ch; ch = (ch + 1).toChar; j } - else throw new NoSuchElementException("next on empty iterator") - } - - //def until(y: Char): Iterator[Char] = to(y) - - /** Create an Iterator[Char] over the characters from 'x' to 'y' - */ - def to(y: Char): Iterator[Char] = until((y + 1).toChar) - -} diff --git a/src/cldc-library/scala/runtime/RichException.scala b/src/cldc-library/scala/runtime/RichException.scala deleted file mode 100644 index 7f0df60417..0000000000 --- a/src/cldc-library/scala/runtime/RichException.scala +++ /dev/null @@ -1,29 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id - - -package scala.runtime - -import Predef._ -import compat.Platform.EOL - -final class RichException(exc: Throwable) { - - def getStackTraceString: String = { - throw new UnsupportedOperationException(exc.toString) -// val s = new StringBuilder() -// for (trElem <- exc.getStackTrace()) { -// s.append(trElem.toString()) -// s.append(EOL) -// } -// s.toString() - } - -} diff --git a/src/cldc-library/scala/runtime/RichLong.scala b/src/cldc-library/scala/runtime/RichLong.scala deleted file mode 100644 index 7c3a13c912..0000000000 --- a/src/cldc-library/scala/runtime/RichLong.scala +++ /dev/null @@ -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 = java.lang.Long.toString(x, 2) - def toHexString: String = java.lang.Long.toString(x, 16) - def toOctalString: String = java.lang.Long.toString(x, 8) -} diff --git a/src/cldc-library/scala/runtime/RichString.scala b/src/cldc-library/scala/runtime/RichString.scala deleted file mode 100644 index 2a2dd85410..0000000000 --- a/src/cldc-library/scala/runtime/RichString.scala +++ /dev/null @@ -1,219 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala.runtime - - -import Predef._ - -final class RichString(val self: String) extends Proxy with RandomAccessSeq[Char] with Ordered[String] { - import RichString._ - override def apply(n: Int) = self charAt n - override def length = self.length - override def toString = self - override def mkString = self - - override def slice(from: Int, until: Int): RichString = { - val len = self.length - new RichString( - if (from >= until || from >= len) - "" - else { - val from0 = if (from < 0) 0 else from - val until0 = if (until > len) len else until - self.substring(from0, until0) - } - ) - } - - //override def ++ [B >: A](that: Iterable[B]): Seq[B] = { - override def ++[B >: Char](that: Iterable[B]): RandomAccessSeq[B] = that match { - case that: RichString => new RichString(self + that.self) - case that => super.++(that) - } - - override def take(until: Int): RichString = slice(0, until) - - override def drop(from: Int): RichString = slice(from, self.length) - - override def startsWith[B](that: Seq[B]) = that match { - case that: RichString => self startsWith that.self - case that => super.startsWith(that) - } - - override def endsWith[B](that: Seq[B]) = that match { - case that: RichString => self endsWith that.self - case that => super.endsWith(that) - } - - override def indexOf[B](that: Seq[B]) = that match { - case that: RichString => self indexOf that.self - case that => super.indexOf(that) - } - - override def containsSlice[B](that: Seq[B]) = that match { - case that: RichString => self contains that.self - case that => super.containsSlice(that) - } - - override def reverse: RichString = { - val buf = new StringBuilder - var i = self.length - 1 - while (i >= 0) { - buf append (self charAt i) - i -= 1 - } - new RichString(buf.toString) - } - - override def compare(other: String) = self compareTo other - - private def isLineBreak(c: Char) = c == LF || c == FF - - /**

- * Strip trailing line end character from this string if it has one. - * A line end character is one of - *

- * - *

- * If a line feed character LF is preceded by a carriage return CR - * (0x0D hex), the CR character is also stripped (Windows convention). - *

- */ - 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 - } - } - - /**

- * Return all lines in this string in an iterator, including trailing - * line end characters. - *

- *

- * 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 - *

- * - */ - 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 .stripLineEnd to all lines - * returned by linesWithSeparators. - */ - 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) - } - - /**

- * For every line in this string: - *

- *
- * Strip a leading prefix consisting of blanks or control characters - * followed by marginChar from the line. - *
- */ - 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 - } - - /**

- * For every line in this string: - *

- *
- * Strip a leading prefix consisting of blanks or control characters - * followed by | from the line. - *
- */ - def stripMargin: String = stripMargin('|') -/* - private def escape(ch: Char): String = ch match { - case '.' | '$' | '^' | '\\' => "\\" + ch - case _ => "" + ch - } - - @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("[")(_+_) + "]" - self.split(re) - } -*/ - def toBoolean: Boolean = parseBoolean(self) - def toByte: Byte = java.lang.Byte.parseByte(self) - def toShort: Short = java.lang.Short.parseShort(self) - def toInt: Int = java.lang.Integer.parseInt(self) - def toLong: Long = java.lang.Long.parseLong(self) - //def toFloat: Float = java.lang.Float.parseFloat(self) - //def toDouble: Double = java.lang.Double.parseDouble(self) -} - -object RichString { - // 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 - - 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\"") -} - diff --git a/src/cldc-library/scala/runtime/ScalaRunTime.scala b/src/cldc-library/scala/runtime/ScalaRunTime.scala deleted file mode 100644 index af6739de7d..0000000000 --- a/src/cldc-library/scala/runtime/ScalaRunTime.scala +++ /dev/null @@ -1,142 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala.runtime - - -import Predef._ - -/* The object ScalaRunTime provides ... - */ -object ScalaRunTime { - - /** Names for primitive types, used by array unboxing */ - val ByteTag = ".Byte" - val ShortTag = ".Short" - val CharTag = ".Char" - val IntTag = ".Int" - val LongTag = ".Long" - val BooleanTag = ".Boolean" - - def isArray(x: AnyRef): Boolean = - (x != null && x.getClass.isArray) || (x != null && x.isInstanceOf[BoxedArray]) - - def isValueTag(tag: String) = tag.charAt(0) == '.' - - def isValueClass(clazz: Class[_]) = - clazz == classOf[Boolean] || clazz == classOf[Byte] || - clazz == classOf[Short ] || clazz == classOf[Char] || - clazz == classOf[Int ] || clazz == classOf[Long] - - def checkInitialized[T <: AnyRef](x: T): T = - if (x == null) throw new UninitializedError else x - - abstract class Try[A] { - def Catch[B >: A](handler: PartialFunction[Throwable, B]): B - def Finally(handler: Unit): A - } - - def Try[A](block: => A): Try[A] = new Try[A] with Runnable { - var result: A = _ - var exception: Throwable = ExceptionHandling.tryCatch(this) - - def run() { result = block } - - def Catch[B >: A](handler: PartialFunction[Throwable, B]): B = - if (exception eq null) - result.asInstanceOf[B] - // !!! else if (exception is LocalReturn) - // !!! // ... - else if (handler isDefinedAt exception) - handler(exception) - else - throw exception - - def Finally(handler: Unit): A = - if (exception eq null) - result.asInstanceOf[A] - else - throw exception - } - - def caseFields(x: Product): List[Any] = { - val arity = x.productArity - def fields(from: Int): List[Any] = - if (from == arity) List() - else x.productElement(from) :: fields(from + 1) - fields(0) - } - - def _toString(x: Product): String = - caseFields(x).mkString(x.productPrefix + "(", ",", ")") - - def _hashCode(x: Product): Int = { - var code = x.getClass().hashCode() - val arr = x.productArity - var i = 0 - while (i < arr) { - code = code * 41 + x.productElement(i).hashCode() - i += 1 - } - code - } - - def _equals(x: Product, y: Any): Boolean = y match { - case y1: Product if x.productArity == y1.productArity => - val arity = x.productArity - var i = 0 - while (i < arity && x.productElement(i) == y1.productElement(i)) - i += 1 - i == arity - case _ => - false - } - - def _equalsWithVarArgs(x: Product, y: Any): Boolean = y match { - case y1: Product if x.productArity == y1.productArity => - val arity = x.productArity - var i = 0 - while (i < arity - 1 && x.productElement(i) == y1.productElement(i)) - i += 1 - i == arity - 1 && { - x.productElement(i) match { - case xs: Seq[_] => - y1.productElement(i) match { - case ys: Seq[_] => xs sameElements ys - } - } - } - case _ => - false - } - - //def checkDefined[T >: Null](x: T): T = - // if (x == null) throw new UndefinedException else x - - def Seq[A](xs: A*): Seq[A] = null // interpreted specially by new backend. - - def arrayValue(x: BoxedArray, elemTag: String): AnyRef = - if (x eq null) null else x.unbox(elemTag) - - def arrayValue(x: BoxedArray, elemClass: Class[_]): AnyRef = - if (x eq null) null else x.unbox(elemClass) - - def boxArray(value: AnyRef): BoxedArray = value match { - case x: Array[Byte] => new BoxedByteArray(x) - case x: Array[Short] => new BoxedShortArray(x) - case x: Array[Char] => new BoxedCharArray(x) - case x: Array[Int] => new BoxedIntArray(x) - case x: Array[Long] => new BoxedLongArray(x) - case x: Array[Boolean] => new BoxedBooleanArray(x) - case x: Array[AnyRef] => new BoxedObjectArray(x) - case x: BoxedArray => x - } -} diff --git a/src/cldc-library/scala/runtime/ShortRef.java b/src/cldc-library/scala/runtime/ShortRef.java deleted file mode 100644 index ae689c044f..0000000000 --- a/src/cldc-library/scala/runtime/ShortRef.java +++ /dev/null @@ -1,19 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala.runtime; - - -public class ShortRef { - public short elem; - public ShortRef(short elem) { this.elem = elem; } - public String toString() { return String.valueOf(elem); } -} diff --git a/src/cldc-library/scala/runtime/SquareRoot.scala b/src/cldc-library/scala/runtime/SquareRoot.scala deleted file mode 100644 index f6b593f7c6..0000000000 --- a/src/cldc-library/scala/runtime/SquareRoot.scala +++ /dev/null @@ -1,151 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2007-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala.runtime - -import Predef._ - -/** - *

- * Integer Square Root function (see http://atoms.alife.co.uk/sqrt/index.html). - *

- *

- * Contributors include Arne Steinarson for the basic approximation idea, Dann - * Corbit and Mathew Hendry for the first cut at the algorithm, Lawrence Kirby - * for the rearrangement, improvments and range optimization, Paul Hsieh - * for the round-then-adjust idea, Tim Tyler, for the Java port - * and Jeff Lawson for a bug-fix and some code to improve accuracy. - *

- * - * @version v0.02 - 2003/09/07 - */ - -/** - * Faster replacements for (int)(java.lang.Math.sqrt(integer)) - */ -object SquareRoot { - private val table = Array( - 0, 16, 22, 27, 32, 35, 39, 42, 45, 48, 50, 53, 55, 57, - 59, 61, 64, 65, 67, 69, 71, 73, 75, 76, 78, 80, 81, 83, - 84, 86, 87, 89, 90, 91, 93, 94, 96, 97, 98, 99, 101, 102, - 103, 104, 106, 107, 108, 109, 110, 112, 113, 114, 115, 116, 117, 118, - 119, 120, 121, 122, 123, 124, 125, 126, 128, 128, 129, 130, 131, 132, - 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 144, 145, - 146, 147, 148, 149, 150, 150, 151, 152, 153, 154, 155, 155, 156, 157, - 158, 159, 160, 160, 161, 162, 163, 163, 164, 165, 166, 167, 167, 168, - 169, 170, 170, 171, 172, 173, 173, 174, 175, 176, 176, 177, 178, 178, - 179, 180, 181, 181, 182, 183, 183, 184, 185, 185, 186, 187, 187, 188, - 189, 189, 190, 191, 192, 192, 193, 193, 194, 195, 195, 196, 197, 197, - 198, 199, 199, 200, 201, 201, 202, 203, 203, 204, 204, 205, 206, 206, - 207, 208, 208, 209, 209, 210, 211, 211, 212, 212, 213, 214, 214, 215, - 215, 216, 217, 217, 218, 218, 219, 219, 220, 221, 221, 222, 222, 223, - 224, 224, 225, 225, 226, 226, 227, 227, 228, 229, 229, 230, 230, 231, - 231, 232, 232, 233, 234, 234, 235, 235, 236, 236, 237, 237, 238, 238, - 239, 240, 240, 241, 241, 242, 242, 243, 243, 244, 244, 245, 245, 246, - 246, 247, 247, 248, 248, 249, 249, 250, 250, 251, 251, 252, 252, 253, - 253, 254, 254, 255 - ) - - /** - *

- * A faster replacement for (int)(java.lang.Math.sqrt(x)). - * Completely accurate for x < 2147483648 (i.e. 2^31)... - *

- *

- * Adjusted to more closely approximate "(int)(java.lang.Math.sqrt(x) + 0.5)" - * by Jeff Lawson. - *

- */ - @throws(classOf[IllegalArgumentException]) - def accurateSqrt(x: Int): Int = { - if (x >= 0x10000) { - val xn = if (x >= 0x1000000) { - var xn0 = - if (x >= 0x10000000) - if (x >= 0x40000000) table(x >> 24) << 8 - else table(x >> 22) << 7 - else - if (x >= 0x4000000) table(x >> 20) << 6 - else table(x >> 18) << 5 - - xn0 = (xn0 + 1 + (x / xn0)) >> 1 - (xn0 + 1 + (x / xn0)) >> 1 - } else { - var xn0 = - if (x >= 0x100000) - if (x >= 0x400000) table(x >> 16) << 4 - else table(x >> 14) << 3 - else - if (x >= 0x40000) table(x >> 12) << 2 - else table(x >> 10) << 1 - - (xn0 + 1 + (x / xn0)) >> 1 - } - adjustment(x, xn) - } - else if (x >= 0x100) { - val xn = - if (x >= 0x1000) - if (x >= 0x4000) (table(x >> 8)) + 1 - else (table(x >> 6) >> 1) + 1 - else - if (x >= 0x400) (table(x >> 4) >> 2) + 1 - else (table(x >> 2) >> 3) + 1 - - adjustment(x, xn) - } - else if (x >= 0) { - adjustment(x, table(x) >> 4) - } - else { - throw new IllegalArgumentException("Attempt to take the square root of negative number") - -1 - } - } - - private def adjustment(x: Int, xn: Int): Int = { - // Added by Jeff Lawson: - // need to test: - // if |xn * xn - x| > |x - (xn-1) * (xn-1)| then xn-1 is more accurate - // if |xn * xn - x| > |(xn+1) * (xn+1) - x| then xn+1 is more accurate - // or, for all cases except x == 0: - // if |xn * xn - x| > x - xn * xn + 2 * xn - 1 then xn-1 is more accurate - // if |xn * xn - x| > xn * xn + 2 * xn + 1 - x then xn+1 is more accurate - val xn2 = xn * xn - - // |xn * xn - x| - var comparitor0 = xn2 - x - if (comparitor0 < 0) comparitor0 = -comparitor0 - - val twice_xn = xn << 1 - - // |x - (xn-1) * (xn-1)| - var comparitor1 = x - xn2 + twice_xn - 1 - if (comparitor1 < 0) comparitor1 = -comparitor1 // only gets here when x == 0 - - // |(xn+1) * (xn+1) - x| - val comparitor2 = xn2 + twice_xn + 1 - x - - if (comparitor0 > comparitor1) - if (comparitor1 > comparitor2) xn+1 else xn-1 - else - if (comparitor0 > comparitor2) xn+1 else xn - } - - def main(args: Array[String]) { - def toInt(s: String): Option[Int] = - try { Some(s.toInt) } catch { case e: NumberFormatException => None } - for (arg <- args; val x = toInt(arg); if !x.isEmpty) { - val n = x.get - println("sqrt("+n+") = "+accurateSqrt(n)) - } - } -} diff --git a/src/cldc-library/scala/runtime/StringAdd.scala b/src/cldc-library/scala/runtime/StringAdd.scala deleted file mode 100644 index 791048b5f2..0000000000 --- a/src/cldc-library/scala/runtime/StringAdd.scala +++ /dev/null @@ -1,22 +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 - -} - -- cgit v1.2.3