diff options
91 files changed, 1080 insertions, 531 deletions
diff --git a/src/actors/scala/actors/AbstractReactor.scala b/src/actors/scala/actors/AbstractReactor.scala index 602639cbf6..4ff20eaf3c 100644 --- a/src/actors/scala/actors/AbstractReactor.scala +++ b/src/actors/scala/actors/AbstractReactor.scala @@ -8,6 +8,12 @@ // $Id$ +/** + * The <code>AbstractReactor</code> trait. + * + * @version 0.9.18 + * @author Philipp Haller + */ package scala.actors trait AbstractReactor[-T] { diff --git a/src/actors/scala/actors/Actor.scala b/src/actors/scala/actors/Actor.scala index f8da909459..3467b65738 100644 --- a/src/actors/scala/actors/Actor.scala +++ b/src/actors/scala/actors/Actor.scala @@ -376,7 +376,7 @@ object Actor { * * @author Philipp Haller */ -@serializable +@serializable @SerialVersionUID(-781154067877019505L) trait Actor extends AbstractActor with ReplyReactor with ReplyableActor { /* The following two fields are only used when the actor diff --git a/src/actors/scala/actors/MessageQueue.scala b/src/actors/scala/actors/MessageQueue.scala index 6e69f1cdac..4435759264 100644 --- a/src/actors/scala/actors/MessageQueue.scala +++ b/src/actors/scala/actors/MessageQueue.scala @@ -17,7 +17,7 @@ package scala.actors * @version 0.9.9 * @author Philipp Haller */ -@serializable +@serializable @SerialVersionUID(7124278808020037465L) class MessageQueueElement(val msg: Any, val session: OutputChannel[Any], var next: MessageQueueElement) { def this() = this(null, null, null) def this(msg: Any, session: OutputChannel[Any]) = this(msg, session, null) @@ -32,7 +32,7 @@ class MessageQueueElement(val msg: Any, val session: OutputChannel[Any], var nex * @version 0.9.9 * @author Philipp Haller */ -@serializable +@serializable @SerialVersionUID(2168935872884095767L) class MessageQueue(protected val label: String) { protected var first: MessageQueueElement = null protected var last: MessageQueueElement = null // last eq null iff list is empty @@ -41,7 +41,7 @@ class MessageQueue(protected val label: String) { def size = _size final def isEmpty = last eq null - protected def changeSize(diff: Int) = { + protected def changeSize(diff: Int) { _size += diff } @@ -73,7 +73,7 @@ class MessageQueue(protected val label: String) { acc } - /** Returns the n-th msg that satisfies the predicate + /** Returns the n-th message that satisfies the predicate <code>p</code> * without removing it. */ def get(n: Int)(p: Any => Boolean): Option[Any] = { @@ -90,11 +90,14 @@ class MessageQueue(protected val label: String) { None } - /** Removes the n-th msg that satisfies the predicate. + /** Removes the n-th message that satisfies the predicate <code>p</code>. */ def remove(n: Int)(p: Any => Boolean): Option[(Any, OutputChannel[Any])] = removeInternal(n)(p) map (x => (x.msg, x.session)) + /** Extracts the first message that satisfies the predicate <code>p</code> + * or <code>null</code> if <code>p</code> fails for all of them. + */ def extractFirst(p: Any => Boolean): MessageQueueElement = removeInternal(0)(p) orNull @@ -185,4 +188,4 @@ object MessageQueueTracer { queueNumberAssigner += 1 queueNumberAssigner } -}
\ No newline at end of file +} diff --git a/src/actors/scala/actors/Reactor.scala b/src/actors/scala/actors/Reactor.scala index 6db795569c..9c8a7a223e 100644 --- a/src/actors/scala/actors/Reactor.scala +++ b/src/actors/scala/actors/Reactor.scala @@ -114,7 +114,7 @@ trait Reactor extends OutputChannel[Any] { var tmpMbox = startMbox var done = false while (!done) { - val qel = tmpMbox.extractFirst((m: Any) => handlesMessage(m)) + val qel = tmpMbox.extractFirst(handlesMessage) if (tmpMbox ne mailbox) tmpMbox.foreach((m, s) => mailbox.append(m, s)) if (null eq qel) { diff --git a/src/library/scala/Array.scala b/src/library/scala/Array.scala index 9877fb59d4..bb711be10f 100644 --- a/src/library/scala/Array.scala +++ b/src/library/scala/Array.scala @@ -44,7 +44,7 @@ object Array { val destArray = boxArray(dest).asInstanceOf[BoxedArray[AnyRef]] var i = 0; - while(i < length) { + while (i < length) { destArray(destPos + i) = srcArray(srcPos + i) i += 1 } @@ -72,7 +72,7 @@ object Array { /** Returns array of length 0 */ def empty[A: ClassManifest]: Array[A] = new Array[A](0) - /** Create an array with given elements. + /** Create an array with given elements. * * @param xs the elements to put in the array * @return the array containing elements xs. @@ -171,7 +171,9 @@ object Array { b.result } - /** An array that contains the results of some element computation a number of times. + /** An array that contains the results of some element computation a number + * of times. + * * @param n the number of elements returned * @param elem the element computation */ @@ -185,7 +187,9 @@ object Array { b.result } - /** A two-dimensional array that contains the results of some element computation a number of times. + /** A two-dimensional array that contains the results of some element + * computation a number of times. + * * @param n1 the number of elements in the 1st dimension * @param n2 the number of elements in the 2nd dimension * @param elem the element computation @@ -193,7 +197,9 @@ object Array { def fill[A: ClassManifest](n1: Int, n2: Int)(elem: => A): Array[Array[A]] = tabulate(n1)(_ => fill(n2)(elem)) - /** A three-dimensional array that contains the results of some element computation a number of times. + /** A three-dimensional array that contains the results of some element + * computation a number of times. + * * @param n1 the number of elements in the 1st dimension * @param n2 the number of elements in the 2nd dimension * @param n3 the number of elements in the 3nd dimension @@ -202,7 +208,9 @@ object Array { def fill[A: ClassManifest](n1: Int, n2: Int, n3: Int)(elem: => A): Array[Array[Array[A]]] = tabulate(n1)(_ => fill(n2, n3)(elem)) - /** A four-dimensional array that contains the results of some element computation a number of times. + /** A four-dimensional array that contains the results of some element + * computation a number of times. + * * @param n1 the number of elements in the 1st dimension * @param n2 the number of elements in the 2nd dimension * @param n3 the number of elements in the 3nd dimension @@ -212,7 +220,9 @@ object Array { def fill[A: ClassManifest](n1: Int, n2: Int, n3: Int, n4: Int)(elem: => A): Array[Array[Array[Array[A]]]] = tabulate(n1)(_ => fill(n2, n3, n4)(elem)) - /** A five-dimensional array that contains the results of some element computation a number of times. + /** A five-dimensional array that contains the results of some element + * computation a number of times. + * * @param n1 the number of elements in the 1st dimension * @param n2 the number of elements in the 2nd dimension * @param n3 the number of elements in the 3nd dimension @@ -223,7 +233,9 @@ object Array { def fill[A: ClassManifest](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int)(elem: => A): Array[Array[Array[Array[Array[A]]]]] = tabulate(n1)(_ => fill(n2, n3, n4, n5)(elem)) - /** An array containing values of a given function over a range of integer values starting from 0. + /** An array containing values of a given function over a range of integer + * values starting from 0. + * * @param n The number of elements in the traversable * @param f The function computing element values * @return A traversable consisting of elements `f(0), ..., f(n -1)` @@ -238,7 +250,9 @@ object Array { b.result } - /** A two-dimensional array containing values of a given function over ranges of integer values starting from 0. + /** A two-dimensional array containing values of a given function over + * ranges of integer values starting from 0. + * * @param n1 the number of elements in the 1st dimension * @param n2 the number of elements in the 2nd dimension * @param f The function computing element values @@ -246,7 +260,9 @@ object Array { def tabulate[A: ClassManifest](n1: Int, n2: Int)(f: (Int, Int) => A): Array[Array[A]] = tabulate(n1)(i1 => tabulate(n2)(f(i1, _))) - /** A three-dimensional array containing values of a given function over ranges of integer values starting from 0. + /** A three-dimensional array containing values of a given function over + * ranges of integer values starting from 0. + * * @param n1 the number of elements in the 1st dimension * @param n2 the number of elements in the 2nd dimension * @param n3 the number of elements in the 3nd dimension @@ -255,7 +271,9 @@ object Array { def tabulate[A: ClassManifest](n1: Int, n2: Int, n3: Int)(f: (Int, Int, Int) => A): Array[Array[Array[A]]] = tabulate(n1)(i1 => tabulate(n2, n3)(f(i1, _, _))) - /** A four-dimensional array containing values of a given function over ranges of integer values starting from 0. + /** A four-dimensional array containing values of a given function over + * ranges of integer values starting from 0. + * * @param n1 the number of elements in the 1st dimension * @param n2 the number of elements in the 2nd dimension * @param n3 the number of elements in the 3nd dimension @@ -265,7 +283,9 @@ object Array { def tabulate[A: ClassManifest](n1: Int, n2: Int, n3: Int, n4: Int)(f: (Int, Int, Int, Int) => A): Array[Array[Array[Array[A]]]] = tabulate(n1)(i1 => tabulate(n2, n3, n4)(f(i1, _, _, _))) - /** A five-dimensional array containing values of a given function over ranges of integer values starting from 0. + /** A five-dimensional array containing values of a given function over + * ranges of integer values starting from 0. + * * @param n1 the number of elements in the 1st dimension * @param n2 the number of elements in the 2nd dimension * @param n3 the number of elements in the 3nd dimension @@ -285,8 +305,9 @@ object Array { */ def range(start: Int, end: Int): Array[Int] = range(start, end, 1) - /** An array containing equally spaced values in some integer interval. - * @param start the start value of the array + /** An array containing equally spaced values in some integer interval. + * + * @param start the start value of the array * @param end the end value of the array (the first value NOT returned) * @param step the increment value of the array (must be positive or negative) * @return the array with values in `start, start + step, ...` up to, but excluding `end` diff --git a/src/library/scala/Either.scala b/src/library/scala/Either.scala index d67f436f69..e78bf63a68 100644 --- a/src/library/scala/Either.scala +++ b/src/library/scala/Either.scala @@ -1,17 +1,28 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + + package scala -/** - * <p> - * The <code>Either</code> type represents a value of one of two possible types (a disjoint union). - * The data constructors; <code>Left</code> and <code>Right</code> represent the two possible - * values. The <code>Either</code> type is often used as an alternative to - * <code>scala.Option</code> where <code>Left</code> represents failure (by convention) and - * <code>Right</code> is akin to <code>Some</code>. - * </p> +/** <p> + * The <code>Either</code> type represents a value of one of two possible + * types (a disjoint union). The data constructors <code>Left</code> and + * <code>Right</code> represent the two possible values. + * The <code>Either</code> type is often used as an alternative to + * <code>scala.Option</code> where <code>Left</code> represents failure + * (by convention) and <code>Right</code> is akin to <code>Some</code>. + * </p> * - * @author <a href="mailto:research@workingmouse.com">Tony Morris</a>, Workingmouse - * @version 1.0, 11/10/2008 - * @since 2.7 + * @author <a href="mailto:research@workingmouse.com">Tony Morris</a>, Workingmouse + * @version 1.0, 11/10/2008 + * @since 2.7 */ sealed abstract class Either[+A, +B] { /** @@ -50,6 +61,7 @@ sealed abstract class Either[+A, +B] { */ def isRight = false // Default here, overriden in Right. } + /** * The left side of the disjoint union, as opposed to the <code>Right</code> side. * @@ -57,6 +69,7 @@ sealed abstract class Either[+A, +B] { * @version 1.0, 11/10/2008 */ final case class Left[+A, +B](a: A) extends Either[A, B] { override def isLeft = true } + /** * The right side of the disjoint union, as opposed to the <code>Left</code> side. * @@ -273,27 +286,25 @@ object Either { case Right(b) => Right(f(b)) } - /** - * Returns <code>None</code> if this is a <code>Left</code> or if the given predicate - * <code>p</code> does not hold for the right value, otherwise, returns a <code>Right</code>. + /** Returns <code>None</code> if this is a <code>Left</code> or if the + * given predicate <code>p</code> does not hold for the right value, + * otherwise, returns a <code>Right</code>. */ def filter[X](p: B => Boolean): Option[Either[X, B]] = e match { case Left(_) => None case Right(b) => if(p(b)) Some(Right(b)) else None } - /** - * Returns a <code>Seq</code> containing the <code>Right</code> value if it exists or an empty - * <code>Seq</code> if this is a <code>Left</code>. + /** Returns a <code>Seq</code> containing the <code>Right</code> value if + * it exists or an empty <code>Seq</code> if this is a <code>Left</code>. */ def toSeq = e match { case Left(_) => Seq.empty case Right(b) => Seq(b) } - /** - * Returns a <code>Some</code> containing the <code>Right</code> value if it exists or a - * <code>None</code> if this is a <code>Left</code>. + /** Returns a <code>Some</code> containing the <code>Right</code> value + * if it exists or a <code>None</code> if this is a <code>Left</code>. */ def toOption = e match { case Left(_) => None @@ -322,9 +333,8 @@ object Either { case Right(t) => t } - /** - * If the condition satisfies, return the given A in <code>Left</code>, otherwise, return the - * given B in <code>Right</code>. + /** If the condition satisfies, return the given A in <code>Left</code>, + * otherwise, return the given B in <code>Right</code>. */ def cond[A, B](test: Boolean, right: => B, left: => A) = if(test) Right(right) else Left(left) diff --git a/src/library/scala/Equiv.scala b/src/library/scala/Equiv.scala index b573875a14..a13530eb35 100644 --- a/src/library/scala/Equiv.scala +++ b/src/library/scala/Equiv.scala @@ -1,37 +1,41 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** ** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ // $Id$ + package scala -/** A trait for representing equivalence relations. It is important to - * distinguish between a type that can be compared for equality or - * equivalence and a representation of equivalence on some type. This - * trait is for representing the latter. - * - * An <a href="http://en.wikipedia.org/wiki/Equivalence_relation">equivalence - * relation</a> is a binary relation on a type. This relation is exposed as - * the <code>equiv</code> method of the <code>Equiv</code> trait. This - * relation must be: - * <ul> - * <li>reflexive: <code>equiv(x, x) == true</code>, for any <code>x</code> of - * type <code>T</code>.</li> - * <li>symmetric: <code>equiv(x, y) == equiv(y, x)</code>, for any <code>x</code> - * and <code>y</code> of type <code>T</code>.</li> - * <li>transitive: if <code>equiv(x, y) == true</code> and <code>equiv(y, z) == true</code> - * then <code>equiv(x, z) == true</code>, for any <code>x</code>, <code>y</code>, - * and <code>z</code> of type <code>T</code>.</li> - * </ul> +/** <p> + * A trait for representing equivalence relations. It is important to + * distinguish between a type that can be compared for equality or + * equivalence and a representation of equivalence on some type. This + * trait is for representing the latter. + * </p> + * <p> + * An <a href="http://en.wikipedia.org/wiki/Equivalence_relation">equivalence + * relation</a> is a binary relation on a type. This relation is exposed as + * the <code>equiv</code> method of the <code>Equiv</code> trait. This + * relation must be: + * </p> + * <ul> + * <li>reflexive: <code>equiv(x, x) == true</code>, for any <code>x</code> of + * type <code>T</code>.</li> + * <li>symmetric: <code>equiv(x, y) == equiv(y, x)</code>, for any + * <code>x</code> and <code>y</code> of type <code>T</code>.</li> + * <li>transitive: if <code>equiv(x, y) == true</code> and <code>equiv(y, z) == true</code> + * then <code>equiv(x, z) == true</code>, for any <code>x</code>, <code>y</code>, + * and <code>z</code> of type <code>T</code>.</li> + * </ul> * - * @author Geoffrey Washburn - * @version 1.0, 2008-04-03 - * @since 2.7 + * @author Geoffrey Washburn + * @version 1.0, 2008-04-03 + * @since 2.7 */ trait Equiv[T] { diff --git a/src/library/scala/Fractional.scala b/src/library/scala/Fractional.scala index 1edab0ae5e..46899e5274 100644 --- a/src/library/scala/Fractional.scala +++ b/src/library/scala/Fractional.scala @@ -1,3 +1,14 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + + package scala /** @@ -9,5 +20,6 @@ trait Fractional[T] extends Numeric[T] { class FractionalOps(lhs: T) extends Ops(lhs) { def /(rhs: T) = div(lhs, rhs) } - override implicit def mkNumericOps(lhs: T): FractionalOps = new FractionalOps(lhs) + override implicit def mkNumericOps(lhs: T): FractionalOps = + new FractionalOps(lhs) } diff --git a/src/library/scala/Immutable.scala b/src/library/scala/Immutable.scala index d7068e08cd..441e304b21 100644 --- a/src/library/scala/Immutable.scala +++ b/src/library/scala/Immutable.scala @@ -5,9 +5,15 @@ ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ + +// $Id$ + + package scala -/** A marker trait for all immutable datastructures such as imutable collections +/** A marker trait for all immutable datastructures such as imutable + * collections. + * * @since 2.8 */ trait Immutable diff --git a/src/library/scala/Integral.scala b/src/library/scala/Integral.scala index bf51a8b8f1..e5d2baed48 100644 --- a/src/library/scala/Integral.scala +++ b/src/library/scala/Integral.scala @@ -1,3 +1,14 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + + package scala /** diff --git a/src/library/scala/Mutable.scala b/src/library/scala/Mutable.scala index 992d295da3..26fa3dafca 100644 --- a/src/library/scala/Mutable.scala +++ b/src/library/scala/Mutable.scala @@ -5,6 +5,10 @@ ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ + +// $Id$ + + package scala /** diff --git a/src/library/scala/NotDefinedError.scala b/src/library/scala/NotDefinedError.scala index 4ba345d38b..b088dcc681 100644 --- a/src/library/scala/NotDefinedError.scala +++ b/src/library/scala/NotDefinedError.scala @@ -1,7 +1,7 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** ** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ diff --git a/src/library/scala/NotNull.scala b/src/library/scala/NotNull.scala index e349a35e95..189189e331 100644 --- a/src/library/scala/NotNull.scala +++ b/src/library/scala/NotNull.scala @@ -5,6 +5,10 @@ ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ + +// $Id$ + + package scala /** diff --git a/src/library/scala/Numeric.scala b/src/library/scala/Numeric.scala index 46259343fa..0468970d35 100644 --- a/src/library/scala/Numeric.scala +++ b/src/library/scala/Numeric.scala @@ -1,3 +1,14 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + + package scala /** diff --git a/src/library/scala/Ordered.scala b/src/library/scala/Ordered.scala index febb1a6e77..009502619c 100644 --- a/src/library/scala/Ordered.scala +++ b/src/library/scala/Ordered.scala @@ -1,7 +1,7 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** ** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ diff --git a/src/library/scala/Ordering.scala b/src/library/scala/Ordering.scala index 906a1dba81..3a740d1de2 100644 --- a/src/library/scala/Ordering.scala +++ b/src/library/scala/Ordering.scala @@ -1,13 +1,14 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** ** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ // $Id$ + package scala import java.util.Comparator diff --git a/src/library/scala/PartialOrdering.scala b/src/library/scala/PartialOrdering.scala index 75bc88b001..cba71410d7 100644 --- a/src/library/scala/PartialOrdering.scala +++ b/src/library/scala/PartialOrdering.scala @@ -1,33 +1,39 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** ** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ // $Id$ + package scala -/** A trait for representing partial orderings. It is important to - * distinguish between a type that has a partial order and a representation - * of partial ordering on some type. This trait is for representing the latter. - * - * A <a href="http://en.wikipedia.org/wiki/Partial_order">partial ordering</a> - * is a binary relation on a type <code>T</code> that is also an equivalence - * relation on values of type <code>T</code>. This relation is exposed as - * the <code>lteq</code> method of the <code>PartialOrdering</code> trait. - * This relation must be: - * <ul> - * <li>reflexive: <code>lteq(x, x) == true</code>, for any <code>x</code> of - * type <code>T</code>.</li> - * <li>anti-symmetric: <code>lteq(x, y) == true</code> and <code>lteq(y, x) == true</code> - * then <code>equiv(x, y)</code>, for any <code>x</code> and <code>y</code> of - * type <code>T</code>.</li> - * <li>transitive: if <code>lteq(x, y) == true</code> and <code>lteq(y, z) == true</code> - * then <code>lteq(x, z) == true</code>, for any <code>x</code>, <code>y</code>, - * and <code>z</code> of type <code>T</code>.</li> +/** <p> + * A trait for representing partial orderings. It is important to + * distinguish between a type that has a partial order and a representation + * of partial ordering on some type. This trait is for representing the + * latter. + * </p> + * <p> + * A <a href="http://en.wikipedia.org/wiki/Partial_order">partial ordering</a> + * is a binary relation on a type <code>T</code> that is also an equivalence + * relation on values of type <code>T</code>. This relation is exposed as + * the <code>lteq</code> method of the <code>PartialOrdering</code> trait. + * This relation must be: + * </p> + * <ul> + * <li>reflexive: <code>lteq(x, x) == true</code>, for any <code>x</code> of + * type <code>T</code>.</li> + * <li>anti-symmetric: <code>lteq(x, y) == true</code> and + * <code>lteq(y, x) == true</code> then <code>equiv(x, y)</code>, for any + * <code>x</code> and <code>y</code> of type <code>T</code>.</li> + * <li>transitive: if <code>lteq(x, y) == true</code> and + * <code>lteq(y, z) == true</code> then <code>lteq(x, z) == true</code>, + * for any <code>x</code>, <code>y</code>, and <code>z</code> of type + * <code>T</code>.</li> * </ul> * * @author Geoffrey Washburn @@ -73,7 +79,7 @@ trait PartialOrdering[T] extends Equiv[T] { def equiv(x: T, y: T): Boolean = lteq(x,y) && lteq(y,x) def reverse : PartialOrdering[T] = new PartialOrdering[T] { - override def reverse = outer; + override def reverse = outer def lteq(x: T, y: T) = outer.lteq(y, x) def tryCompare(x: T, y: T) = outer.tryCompare(y, x) } diff --git a/src/library/scala/SerialVersionUID.scala b/src/library/scala/SerialVersionUID.scala index 8c22479f3b..dd0eabf2e9 100644 --- a/src/library/scala/SerialVersionUID.scala +++ b/src/library/scala/SerialVersionUID.scala @@ -1,7 +1,7 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** ** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** */ @@ -13,7 +13,7 @@ package scala /** - * Annotation for specifying the static SerialVersionUID field - * of a serializable class + * Annotation for specifying the <code>static SerialVersionUID</code> field + * of a serializable class. */ class SerialVersionUID(uid: Long) extends StaticAnnotation diff --git a/src/library/scala/collection/Iterable.scala b/src/library/scala/collection/Iterable.scala index 218dcc65e2..f441486885 100644 --- a/src/library/scala/collection/Iterable.scala +++ b/src/library/scala/collection/Iterable.scala @@ -8,6 +8,7 @@ // $Id: Iterable.scala 15188 2008-05-24 15:01:02Z stepancheg $ + package scala.collection import scala.util.control.Breaks._ @@ -57,7 +58,11 @@ trait Iterable[+A] extends Traversable[A] } -/** Factory methods and utilities for instances of type Traversable */ +/** Factory methods and utilities for instances of type <code>Iterable</code>. + * + * @author Martin Odersky + * @version 2.8 + */ object Iterable extends TraversableFactory[Iterable] { implicit def builderFactory[A]: BuilderFactory[A, Iterable[A], Coll] = new VirtualBuilderFactory[A] @@ -71,5 +76,6 @@ object Iterable extends TraversableFactory[Iterable] { @deprecated("use seq.max instead") def max[A](seq: Iterable[A])(implicit ord: Ordering[A]): A = seq.max - @deprecated("use View instead") type Projection[A] = IterableView[A, Coll] + @deprecated("use View instead") + type Projection[A] = IterableView[A, Coll] } diff --git a/src/library/scala/collection/IterableProxy.scala b/src/library/scala/collection/IterableProxy.scala index 125b470ad7..5217ebea8c 100644 --- a/src/library/scala/collection/IterableProxy.scala +++ b/src/library/scala/collection/IterableProxy.scala @@ -13,9 +13,6 @@ package scala.collection import generic._ -// Methods could be printed by cat Traversibe.scala | egrep '^ (override )?def' - - /** <p> * This trait implements a proxy for iterable objects. It forwards * all calls to a different iterable object. diff --git a/src/library/scala/collection/Iterator.scala b/src/library/scala/collection/Iterator.scala index 4212d14eb3..bbb6d3d690 100644 --- a/src/library/scala/collection/Iterator.scala +++ b/src/library/scala/collection/Iterator.scala @@ -66,7 +66,9 @@ object Iterator { else empty.next() } - /** An iterator that returns values of a given function over a range of integer values starting from 0. + /** An iterator that returns values of a given function over a range of + * integer values starting from 0. + * * @param end The argument up to which values are tabulated. * @param f The function computing the results * @return An iterator with values `f(0) ... f(end-1)` @@ -79,7 +81,7 @@ object Iterator { else empty.next() } - /** An iterator returning successive values in some integer interval. + /** An iterator returning successive values in some integer interval. * * @param start the start value of the iterator * @param end the end value of the iterator (the first value NOT returned) @@ -88,7 +90,7 @@ object Iterator { def range(start: Int, end: Int): Iterator[Int] = range(start, end, 1) /** An iterator returning equally spaced values in some integer interval. - + * * @param start the start value of the iterator * @param end the end value of the iterator (the first value NOT returned) * @param step the increment value of the iterator (must be positive or negative) @@ -134,22 +136,24 @@ object Iterator { def next(): Int = { val result = i; i += step; result } } - /** - * Create an infinite iterator based on the given expression - * (which is recomputed for every element) + /** Create an infinite iterator based on the given expression + * (which is recomputed for every element) * - * @param elem the element composing the resulting iterator - * @return the iterator containing an infinite number of elem + * @param elem the element composing the resulting iterator + * @return the iterator containing an infinite number of elem */ def continually[A](elem: => A): Iterator[A] = new Iterator[A] { def hasNext = true def next = elem } - /** A wrapper class for the `flatten `method that is added to class Iterator with implicit conversion @see iteratorIteratorWrapper. + /** A wrapper class for the <code>flatten</code> method that is added to + * class <code>Iterator</code> with implicit conversion + * @see iteratorIteratorWrapper. */ class IteratorIteratorOps[A](its: Iterator[Iterator[A]]) { - /** If `its` is an iterator of iterators, `its.flatten` gives the iterator that is the concatenation of all iterators in `its`. + /** If `its` is an iterator of iterators, `its.flatten` gives the iterator + * that is the concatenation of all iterators in `its`. */ def flatten: Iterator[A] = new Iterator[A] { private var it: Iterator[A] = empty @@ -292,6 +296,7 @@ trait Iterator[+A] { self => /** Advances this iterator past the first <code>n</code> elements, * or the length of the iterator, whichever is smaller. + * * @param n the number of elements to drop * @return the new iterator */ @@ -362,8 +367,9 @@ trait Iterator[+A] { self => } /** Returns a new iterator based on the partial function <code>pf</code>, - * containing pf(x) for all the elements which are defined on pf. + * containing <code>pf(x)</code> for all the elements which are defined on pf. * The order of the elements is preserved. + * * @param pf the partial function which filters and maps the iterator. * @return the new iterator. */ @@ -443,15 +449,15 @@ trait Iterator[+A] { self => /** Return an iterator formed from this iterator and the specified iterator * <code>that</code> by associating each element of the former with * the element at the same position in the latter. - * If one of the two iterators is longer than the other, its remaining elements are ignored. - * + * If one of the two iterators is longer than the other, its remaining + * elements are ignored. */ def zip[B](that: Iterator[B]) = new Iterator[(A, B)] { def hasNext = self.hasNext && that.hasNext def next = (self.next, that.next) } - /** Return a new iterator with a length equal or longer to `len`. + /** Return a new iterator with a length equal or longer to <code>len</code>. * If the current iterator returns fewer than `len` elements * return `elem` until the required length `len` is reached. */ @@ -659,7 +665,8 @@ trait Iterator[+A] { self => def :\[B](z: B)(op: (A, B) => B): B = foldRight(z)(op) /** Combines the elements of this iterator together using the binary - * operator <code>op</code>, from left to right + * operator <code>op</code>, from left to right. + * * @param op The operator to apply * @return <code>op(... op(a<sub>0</sub>,a<sub>1</sub>), ..., a<sub>n</sub>)</code> if the iterator yields elements @@ -686,7 +693,7 @@ trait Iterator[+A] { self => else throw new UnsupportedOperationException("empty.reduceRight") } - /** Combines the elements of this iterator together using the binary + /** Combines the elements of this iterator together using the binary * operator <code>op</code>, from left to right * @param op The operator to apply * @return If the iterable is non-empty, the result of the operations as an Option, otherwise None. @@ -695,8 +702,9 @@ trait Iterator[+A] { self => if (!hasNext) None else Some(reduceLeft(op)) } - /** Combines the elements of this iterable object together using the binary + /** Combines the elements of this iterable object together using the binary * operator <code>op</code>, from right to left. + * * @param op The operator to apply * @return If the iterable is non-empty, the result of the operations as an Option, otherwise None. */ @@ -743,7 +751,7 @@ trait Iterator[+A] { self => buf } - /** A flexible iterator for transforming an Iterator[A] into an + /** A flexible iterator for transforming an <code>Iterator[A]</code> into an * Iterator[Sequence[A]], with configurable sequence size, step, and * strategy for dealing with elements which don't fit evenly. * @@ -978,7 +986,7 @@ trait Iterator[+A] { self => res.toList } - /** Traverse this iterator and return all elements in a stream. + /** Traverse this iterator and return all elements in a stream. * * @return A stream which enumerates all elements of this iterator. */ @@ -1060,7 +1068,7 @@ trait Iterator[+A] { self => override def toString = (if (hasNext) "non-empty" else "empty")+" iterator" - /** Returns a new iterator that first yields the elements of this + /** Returns a new iterator that first yields the elements of this * iterator followed by the elements provided by iterator <code>that</code>. */ @deprecated("use <code>++</code>") @@ -1107,10 +1115,12 @@ trait Iterator[+A] { self => i += 1 } } + @deprecated("use copyToArray instead") def readInto[B >: A](xs: Array[B], start: Int) { readInto(xs, start, xs.length - start) } + @deprecated("use copyToArray instead") def readInto[B >: A](xs: Array[B]) { readInto(xs, 0, xs.length) diff --git a/src/library/scala/collection/JavaConversions.scala b/src/library/scala/collection/JavaConversions.scala index a353af7313..d578e38fe6 100644 --- a/src/library/scala/collection/JavaConversions.scala +++ b/src/library/scala/collection/JavaConversions.scala @@ -8,6 +8,7 @@ // $Id$ + package scala.collection /** <p> diff --git a/src/library/scala/collection/LinearSequenceLike.scala b/src/library/scala/collection/LinearSequenceLike.scala index 80aed33584..1d6af92cb7 100644 --- a/src/library/scala/collection/LinearSequenceLike.scala +++ b/src/library/scala/collection/LinearSequenceLike.scala @@ -312,7 +312,8 @@ trait LinearSequenceLike[+A, +Repr <: LinearSequenceLike[A, Repr]] extends Seque (b.result, these) } - /** Returns true iff the other linear sequence contains the same elements as this one. + /** Returns <code>true</code> iff the other linear sequence contains the + * same elements as this one. * * @note will not terminate for two infinite-sized linear sequences. * @param that the other linear sequence @@ -320,13 +321,14 @@ trait LinearSequenceLike[+A, +Repr <: LinearSequenceLike[A, Repr]] extends Seque override def sameElements[B >: A](that: Iterable[B]): Boolean = that match { case that1: LinearSequence[_] => var these = this - var those = that + var those = that1 while (!these.isEmpty && !those.isEmpty && these.head == those.head) { these = these.tail those = those.tail } these.isEmpty && those.isEmpty - case _ => super.sameElements(that) + case _ => + super.sameElements(that) } // Overridden methods from Sequence diff --git a/src/library/scala/collection/MapProxy.scala b/src/library/scala/collection/MapProxy.scala index b89b7e7cf6..ecf3d9d13c 100644 --- a/src/library/scala/collection/MapProxy.scala +++ b/src/library/scala/collection/MapProxy.scala @@ -8,6 +8,7 @@ // $Id$ + package scala.collection import generic.MapProxyTemplate diff --git a/src/library/scala/collection/Sequence.scala b/src/library/scala/collection/Sequence.scala index 9fb39c0cae..9c4c115741 100644 --- a/src/library/scala/collection/Sequence.scala +++ b/src/library/scala/collection/Sequence.scala @@ -11,18 +11,19 @@ package scala.collection -import mutable.ListBuffer -// import immutable.{List, Nil, ::} -import generic._ -import scala.util.control.Breaks._ - -/** Class <code>Sequence[A]</code> represents sequences of elements - * of type <code>A</code>. - * It adds the following methods to class Iterable: - * `length`, `lengthCompare`, `apply`, `isDefinedAt`, `segmentLength`, `prefixLength`, - * `indexWhere`, `indexOf`, `lastIndexWhere`, `lastIndexOf`, `reverse`, `reverseIterator`, - * `startsWith`, `endsWith`, `indexOfSeq`. - * +import scala.collection.generic._ + +/** <p> + * Class <code>Sequence[A]</code> represents sequences of elements + * of type <code>A</code>.<br/> + * It adds the following methods to class <code>Iterable</code>: + * <code>length</code>, <code>lengthCompare</code>, <code>apply</code>, + * <code>isDefinedAt</code>, <code>segmentLength</code>, + * <code>prefixLength</code>, <code>indexWhere</code>, <code>indexOf</code>, + * <code>lastIndexWhere</code>, <code>lastIndexOf</code>, <code>reverse</code>, + * <code>reverseIterator</code>, <code>startsWith</code>, + * <code>endsWith</code>, <code>indexOfSeq</code>. + * </p> * * @author Martin Odersky * @author Matthias Zenger @@ -35,14 +36,20 @@ trait Sequence[+A] extends PartialFunction[Int, A] override def companion: Companion[Sequence] = Sequence } -object Sequence extends SequenceFactory[Sequence] -{ +/** Factory object for <code>Sequence</code> trait. + * + * @author Martin Odersky + * @version 2.8 + */ +object Sequence extends SequenceFactory[Sequence] { + private[collection] val hashSeed = "Sequence".hashCode implicit def builderFactory[A]: BuilderFactory[A, Sequence[A], Coll] = new VirtualBuilderFactory[A] def newBuilder[A]: Builder[A, Sequence[A]] = immutable.Sequence.newBuilder[A] - @deprecated("use View instead") type Projection[A] = SequenceView[A, Coll] + @deprecated("use View instead") + type Projection[A] = SequenceView[A, Coll] @deprecated("use Sequence(value) instead") def singleton[A](value: A) = Sequence(value) diff --git a/src/library/scala/collection/Set.scala b/src/library/scala/collection/Set.scala index a5147b992e..f7d1208dff 100644 --- a/src/library/scala/collection/Set.scala +++ b/src/library/scala/collection/Set.scala @@ -27,7 +27,11 @@ trait Set[A] extends (A => Boolean) override def companion: Companion[Set] = Set } -/* Factory object for `Set` class */ +/** Factory object for <code>Set</code> class. + * + * @author Martin Odersky + * @version 2.8 + */ object Set extends SetFactory[Set] { override def empty[A]: Set[A] = immutable.Set.empty[A] implicit def builderFactory[A]: BuilderFactory[A, Set[A], Coll] = setBuilderFactory[A] diff --git a/src/library/scala/collection/Traversable.scala b/src/library/scala/collection/Traversable.scala index 6ed1844915..bac36647c9 100644 --- a/src/library/scala/collection/Traversable.scala +++ b/src/library/scala/collection/Traversable.scala @@ -7,6 +7,8 @@ \* */ // $Id: Traversable.scala 15188 2008-05-24 15:01:02Z stepancheg $ + + package scala.collection // import immutable.{List, Stream, Nil} @@ -93,13 +95,18 @@ trait Traversable[+A] extends TraversableTemplate[A, Traversable[A]] */ } -/** Factory methods and utilities for instances of type Traversable */ +/** Factory methods and utilities for instances of type <code>Traversable</code>. + * + * @author Martin Odersky + * @version 2.8 + */ object Traversable extends TraversableFactory[Traversable] { self => /** provide break functionality separate from client code */ private[collection] val breaks: Breaks = new Breaks - implicit def builderFactory[A]: BuilderFactory[A, Traversable[A], Coll] = new VirtualBuilderFactory[A] + implicit def builderFactory[A]: BuilderFactory[A, Traversable[A], Coll] = + new VirtualBuilderFactory[A] def newBuilder[A]: Builder[A, Traversable[A]] = immutable.Traversable.newBuilder[A] } diff --git a/src/library/scala/collection/Vector.scala b/src/library/scala/collection/Vector.scala index b993125947..15cbd11638 100644 --- a/src/library/scala/collection/Vector.scala +++ b/src/library/scala/collection/Vector.scala @@ -8,14 +8,19 @@ // $Id$ + package scala.collection import generic._ import mutable.ArrayBuffer -/** Sequences that support O(1) element access and O(1) length computation. - * This class does not add any methods to Sequence but overrides several - * methods with optimized implementations. +/** <p> + * Sequences that support O(1) element access and O(1) length computation. + * </p> + * <p> + * This class does not add any methods to <code>Sequence</code> but + * overrides several methods with optimized implementations. + * </p> * * @author Sean McDirmid * @author Martin Odersky diff --git a/src/library/scala/collection/VectorLike.scala b/src/library/scala/collection/VectorLike.scala index dc1c5aed4a..1bb53b8017 100755 --- a/src/library/scala/collection/VectorLike.scala +++ b/src/library/scala/collection/VectorLike.scala @@ -8,7 +8,9 @@ // $Id: VectorTemplate.scala 18646 2009-09-04 16:56:11Z odersky $ + package scala.collection + import generic._ import mutable.ArrayBuffer diff --git a/src/library/scala/collection/generic/BitSetFactory.scala b/src/library/scala/collection/generic/BitSetFactory.scala index 035347340f..8bd7b7883b 100644 --- a/src/library/scala/collection/generic/BitSetFactory.scala +++ b/src/library/scala/collection/generic/BitSetFactory.scala @@ -5,8 +5,12 @@ ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ + // $Id$ + + package scala.collection.generic + import scala.collection._ trait BitSetFactory[Coll <: BitSet with BitSetTemplate[Coll]] { diff --git a/src/library/scala/collection/generic/Companion.scala b/src/library/scala/collection/generic/Companion.scala index fd2e9325ca..316394b786 100644 --- a/src/library/scala/collection/generic/Companion.scala +++ b/src/library/scala/collection/generic/Companion.scala @@ -10,7 +10,6 @@ package scala.collection.generic -import scala.collection._ import scala.collection._ @@ -19,14 +18,13 @@ abstract class Companion[+CC[X] <: Traversable[X]] { def newBuilder[A]: Builder[A, CC[A]] - /** The empty iterable of type CC */ + /** The empty iterable of type <code>CC</code>. */ def empty[A]: CC[A] = newBuilder[A].result - /** Creates an iterable of type CC with specified elements */ + /** Creates an iterable of type <code>CC</code> with specified elements. */ def apply[A](args: A*): CC[A] = { val b = newBuilder[A] b ++= args b.result } } - diff --git a/src/library/scala/collection/generic/KMP.scala b/src/library/scala/collection/generic/KMP.scala index 8da2cec274..97f3b215b4 100755 --- a/src/library/scala/collection/generic/KMP.scala +++ b/src/library/scala/collection/generic/KMP.scala @@ -1,6 +1,18 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id: $ + + package scala.collection.generic -/** KMP implementation, based on the undoubtedly reliable wikipedia entry +/** KMP implementation, based on the undoubtedly reliable wikipedia entry. + * * @author paulp */ object KMP { @@ -59,8 +71,8 @@ object KMP { target: Seq[B], targetOffset: Int, targetCount: Int, fromIndex: Int): Int = KMP(source.slice(sourceOffset, sourceCount) drop fromIndex, target.slice(targetOffset, targetCount)) match { - case None => -1 - case Some(x) => x + fromIndex + case None => -1 + case Some(x) => x + fromIndex } def lastIndexOf[B]( @@ -71,8 +83,8 @@ object KMP { val tgt = target.slice(targetOffset, targetCount).reverse KMP(src, tgt) match { - case None => -1 - case Some(x) => (src.length - tgt.length - x) + sourceOffset + case None => -1 + case Some(x) => (src.length - tgt.length - x) + sourceOffset } } } diff --git a/src/library/scala/collection/generic/VectorTemplate.scala b/src/library/scala/collection/generic/VectorTemplate.scala index e80a439c76..e55d172f52 100644 --- a/src/library/scala/collection/generic/VectorTemplate.scala +++ b/src/library/scala/collection/generic/VectorTemplate.scala @@ -8,6 +8,7 @@ // $Id$ + package scala.collection package generic diff --git a/src/library/scala/collection/immutable/HashMap.scala b/src/library/scala/collection/immutable/HashMap.scala index 0849536755..730c8e1435 100644 --- a/src/library/scala/collection/immutable/HashMap.scala +++ b/src/library/scala/collection/immutable/HashMap.scala @@ -15,11 +15,16 @@ import scala.collection.generic._ import scala.collection.mutable import annotation.unchecked.uncheckedVariance -/** This class implements immutable maps using a hash table. - * It is optimized for sequential accesses where the last updated table is accessed most often. - * It supports with reasonable efficiency accesses to previous versions of the table by keeping - * a change log that's regularly compacted. - * It needs to synchronize most methods, so it is less suitable for highly concurrent accesses. +/** <p> + * This class implements immutable maps using a hash table. + * </p> + * <p> + * It is optimized for sequential accesses where the last updated table is + * accessed most often. It supports with reasonable efficiency accesses to + * previous versions of the table by keeping a change log that's regularly + * compacted. It needs to synchronize most methods, so it is less suitable + * for highly concurrent accesses. + * </p> * * @note the builder of a hash map returns specialized representations EmptyMap,Map1,..., Map4 * for maps of size <= 4. @@ -27,7 +32,7 @@ import annotation.unchecked.uncheckedVariance * @author Martin Odersky * @version 2.0, 19/01/2007 */ -@serializable +@serializable @SerialVersionUID(8886909077084990906L) class HashMap[A, +B] extends Map[A,B] with ImmutableMapTemplate[A, B, HashMap[A, B]] with mutable.HashTable[A] { type Entry = collection.mutable.DefaultEntry[A, Any] diff --git a/src/library/scala/collection/immutable/HashSet.scala b/src/library/scala/collection/immutable/HashSet.scala index 9300164438..6589e83e92 100644 --- a/src/library/scala/collection/immutable/HashSet.scala +++ b/src/library/scala/collection/immutable/HashSet.scala @@ -8,16 +8,22 @@ // $Id$ + package scala.collection.immutable import scala.collection.generic._ import scala.collection.mutable -/** This class implements immutable sets using a hash table. - * It is optimized for sequential accesses where the last updated table is accessed most often. - * It supports with reasonable efficiency accesses to previous versions of the table by keeping - * a change log that's regularly compacted. - * It needs to synchronize most methods, so it is less suitable for highly concurrent accesses. +/** <p> + * This class implements immutable sets using a hash table. + * </p> + * <p> + * It is optimized for sequential accesses where the last updated table is + * accessed most often. It supports with reasonable efficiency accesses to + * previous versions of the table by keeping a change log that's regularly + * compacted. It needs to synchronize most methods, so it is less suitable + * for highly concurrent accesses. + * </p> * * @note the builder of a hash set returns specialized representations EmptySet,Set1,..., Set4 * for sets of size <= 4. @@ -25,7 +31,7 @@ import scala.collection.mutable * @author Martin Odersky * @version 2.8 */ -@serializable +@serializable @SerialVersionUID(4020728942921483037L) class HashSet[A] extends Set[A] with SetClass[A, HashSet] with SetTemplate[A, HashSet[A]] @@ -127,11 +133,11 @@ class HashSet[A] extends Set[A] } } -/** A factory object for immutable HashSets - * - * @author Martin Odersky - * @version 2.8 - */ +/** A factory object for immutable HashSets. + * + * @author Martin Odersky + * @version 2.8 + */ object HashSet extends SetFactory[HashSet] { implicit def builderFactory[A]: BuilderFactory[A, HashSet[A], Coll] = setBuilderFactory[A] override def empty[A]: HashSet[A] = new HashSet diff --git a/src/library/scala/collection/immutable/IntMap.scala b/src/library/scala/collection/immutable/IntMap.scala index 19ebbdfac4..8c22089f21 100644 --- a/src/library/scala/collection/immutable/IntMap.scala +++ b/src/library/scala/collection/immutable/IntMap.scala @@ -1,9 +1,20 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id: $ + + package scala.collection.immutable; /** * @author David MacIver */ -private[immutable] object IntMapUtils{ +private[immutable] object IntMapUtils { def zero(i : Int, mask : Int) = (i & mask) == 0; def mask(i : Int, mask : Int) = i & (complement(mask - 1) ^ mask) def hasMatch(key : Int, prefix : Int, m : Int) = mask(key, m) == prefix; @@ -38,7 +49,7 @@ private[immutable] object IntMapUtils{ import IntMapUtils._ -object IntMap{ +object IntMap { def empty[T] : IntMap[T] = IntMap.Nil; def singleton[T](key : Int, value : T) : IntMap[T] = IntMap.Tip(key, value); def apply[T](elems : (Int, T)*) : IntMap[T] = @@ -122,14 +133,14 @@ private[immutable] class IntMapEntryIterator[V](it : IntMap[V]) extends IntMapIt } private[immutable] class IntMapValueIterator[V](it : IntMap[V]) extends IntMapIterator[V, V](it){ - def valueOf(tip : IntMap.Tip[V]) = tip.value; + def valueOf(tip : IntMap.Tip[V]) = tip.value } private[immutable] class IntMapKeyIterator[V](it : IntMap[V]) extends IntMapIterator[V, Int](it){ - def valueOf(tip : IntMap.Tip[V]) = tip.key; + def valueOf(tip : IntMap.Tip[V]) = tip.key } -import IntMap._; +import IntMap._ /** * Specialised immutable map structure for integer keys, based on diff --git a/src/library/scala/collection/immutable/Iterable.scala b/src/library/scala/collection/immutable/Iterable.scala index 649d2eafc5..4a85779443 100644 --- a/src/library/scala/collection/immutable/Iterable.scala +++ b/src/library/scala/collection/immutable/Iterable.scala @@ -1,3 +1,14 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + + package scala.collection.immutable import scala.collection.generic._ @@ -17,7 +28,11 @@ trait Iterable[+A] extends Traversable[A] override def companion: Companion[Iterable] = Iterable } -/* A factory object for the trait `Iterable` */ +/** A factory object for the trait <code>Iterable</code>. + * + * @author Martin Odersky + * @version 2.8 + */ object Iterable extends TraversableFactory[Iterable] { implicit def builderFactory[A]: BuilderFactory[A, Iterable[A], Coll] = new VirtualBuilderFactory[A] def newBuilder[A]: Builder[A, Iterable[A]] = new mutable.ListBuffer diff --git a/src/library/scala/collection/immutable/LinearSequence.scala b/src/library/scala/collection/immutable/LinearSequence.scala index da4b364b74..073a3691ca 100644 --- a/src/library/scala/collection/immutable/LinearSequence.scala +++ b/src/library/scala/collection/immutable/LinearSequence.scala @@ -1,9 +1,20 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + + package scala.collection.immutable import scala.collection.generic._ import scala.collection.mutable -/** A subtrait of collection.Sequence which represents sequences +/** A subtrait of <code>collection.Sequence</code> which represents sequences * that cannot be mutated. */ trait LinearSequence[+A] extends Sequence[A] diff --git a/src/library/scala/collection/immutable/List.scala b/src/library/scala/collection/immutable/List.scala index 26c8a309a5..2642337540 100644 --- a/src/library/scala/collection/immutable/List.scala +++ b/src/library/scala/collection/immutable/List.scala @@ -743,6 +743,7 @@ object List extends SequenceFactory[List] { /** Returns the list resulting from applying the given function <code>f</code> * to corresponding elements of the argument lists. + * * @param f function to apply to each pair of elements. * @return <code>[f(a0,b0), ..., f(an,bn)]</code> if the lists are * <code>[a0, ..., ak]</code>, <code>[b0, ..., bl]</code> and @@ -837,7 +838,7 @@ object List extends SequenceFactory[List] { * @param xss the list of lists * @return the transposed list of lists */ - @deprecated("use p`xss.transpose' instead") + @deprecated("use `xss.transpose' instead") def transpose[A](xss: List[List[A]]): List[List[A]] = { val buf = new ListBuffer[List[A]] var yss = xss diff --git a/src/library/scala/collection/immutable/ListMap.scala b/src/library/scala/collection/immutable/ListMap.scala index 40ecc67381..c991318872 100644 --- a/src/library/scala/collection/immutable/ListMap.scala +++ b/src/library/scala/collection/immutable/ListMap.scala @@ -9,14 +9,15 @@ // $Id$ - package scala.collection.immutable import scala.collection.generic._ -/** The canonical factory of <a href="ListMap.html">ListMap</a>'s */ +/** The canonical factory of <a href="ListMap.html">ListMap</a>'s. + */ object ListMap extends ImmutableMapFactory[ListMap] { - implicit def builderFactory[A, B]: BuilderFactory[(A, B), ListMap[A, B], Coll] = new MapBuilderFactory[A, B] + implicit def builderFactory[A, B]: BuilderFactory[(A, B), ListMap[A, B], Coll] = + new MapBuilderFactory[A, B] def empty[A, B]: ListMap[A, B] = new ListMap } @@ -29,7 +30,7 @@ object ListMap extends ImmutableMapFactory[ListMap] { * @author Martin Oderskty * @version 2.0, 01/01/2007 */ -@serializable +@serializable @SerialVersionUID(301002838095710379L) class ListMap[A, +B] extends Map[A, B] with ImmutableMapTemplate[A, B, ListMap[A, B]] { override def empty = ListMap.empty @@ -99,7 +100,7 @@ class ListMap[A, +B] extends Map[A, B] with ImmutableMapTemplate[A, B, ListMap[A protected def value: B = throw new NoSuchElementException("empty map") protected def next: ListMap[A, B] = throw new NoSuchElementException("empty map") - @serializable + @serializable @SerialVersionUID(-6453056603889598734L) protected class Node[B1 >: B](override protected val key: A, override protected val value: B1) extends ListMap[A, B1] { /** Returns the number of mappings in this map. diff --git a/src/library/scala/collection/immutable/MapProxy.scala b/src/library/scala/collection/immutable/MapProxy.scala index 933ba3acfc..de3474a2d0 100644 --- a/src/library/scala/collection/immutable/MapProxy.scala +++ b/src/library/scala/collection/immutable/MapProxy.scala @@ -25,7 +25,6 @@ import scala.collection.generic.MapProxyTemplate * @author Matthias Zenger, Martin Odersky * @version 2.0, 31/12/2006 */ - trait MapProxy[A, +B] extends Map[A, B] with MapProxyTemplate[A, B, Map[A, B]] { override def repr = this diff --git a/src/library/scala/collection/immutable/Queue.scala b/src/library/scala/collection/immutable/Queue.scala index 0daa31af77..343c4d2779 100644 --- a/src/library/scala/collection/immutable/Queue.scala +++ b/src/library/scala/collection/immutable/Queue.scala @@ -25,6 +25,7 @@ object Queue { * @version 1.0, 08/07/2003 */ @serializable +@SerialVersionUID(-7622936493364270175L) class Queue[+A] protected( protected val in: List[A], protected val out: List[A]) extends Sequence[A] @@ -110,7 +111,7 @@ class Queue[+A] protected( def dequeue: (A, Queue[A]) = out match { case Nil if !in.isEmpty => val rev = in.reverse ; (rev.head, new Queue(Nil, rev.tail)) case x :: xs => (x, new Queue(in, xs)) - case _ => throw new NoSuchElementException("queue empty") + case _ => throw new NoSuchElementException("dequeue on empty queue") } /** Returns the first element in the queue, or throws an error if there @@ -122,7 +123,7 @@ class Queue[+A] protected( def front: A = if (!out.isEmpty) out.head else if (!in.isEmpty) in.last - else throw new NoSuchElementException("queue empty") + else throw new NoSuchElementException("front on empty queue") /** Returns a string representation of this queue. */ diff --git a/src/library/scala/collection/immutable/RedBlack.scala b/src/library/scala/collection/immutable/RedBlack.scala index ee00d36ad2..0ff253045e 100644 --- a/src/library/scala/collection/immutable/RedBlack.scala +++ b/src/library/scala/collection/immutable/RedBlack.scala @@ -7,9 +7,11 @@ \* */ // $Id$ + + package scala.collection.immutable -@serializable +@serializable @SerialVersionUID(8691885935445612921L) abstract class RedBlack[A] { def isSmaller(x: A, y: A): Boolean @@ -30,14 +32,14 @@ abstract class RedBlack[A] { def delete(k: A): Tree[B] = del(k) def foreach[U](f: (A, B) => U) @deprecated("use `foreach' instead") - def visit[T](input : T)(f : (T,A,B) => Tuple2[Boolean,T]) : Tuple2[Boolean,T]; + def visit[T](input: T)(f: (T, A, B) => (Boolean, T)): (Boolean, T) def toStream: Stream[(A,B)] def iterator: Iterator[(A, B)] @deprecated("use `iterator' instead") def elements = iterator def upd[B1 >: B](k: A, v: B1): Tree[B1] def del(k: A): Tree[B] def smallest: NonEmpty[B] - def range(from : Option[A], until : Option[A]) : Tree[B] + def range(from: Option[A], until: Option[A]): Tree[B] def first : A def last : A def count : Int @@ -85,27 +87,28 @@ abstract class RedBlack[A] { } } def smallest: NonEmpty[B] = if (left.isEmpty) this else left.smallest + def toStream: Stream[(A,B)] = left.toStream ++ Stream((key,value)) ++ right.toStream def iterator: Iterator[(A, B)] = left.iterator ++ Iterator.single(Pair(key, value)) ++ right.iterator - def foreach[U](f: (A, B) => U) { + def foreach[U](f: (A, B) => U) { left foreach f f(key, value) right foreach f } @deprecated("use `foreach' instead") - def visit[T](input : T)(f : (T,A,B) => Tuple2[Boolean,T]) : Tuple2[Boolean,T] = { + def visit[T](input: T)(f: (T,A,B) => (Boolean, T)): (Boolean, T) = { val left = this.left.visit(input)(f) if (!left._1) return left val middle = f(left._2, key, value) if (!middle._1) return middle return this.right.visit(middle._2)(f) } - override def range(from : Option[A], until : Option[A]) : Tree[B] = { + override def range(from: Option[A], until: Option[A]): Tree[B] = { if (from == None && until == None) return this if (from != None && isSmaller(key, from.get)) return right.range(from, until); if (until != None && (isSmaller(until.get,key) || !isSmaller(key,until.get))) @@ -132,12 +135,12 @@ abstract class RedBlack[A] { def iterator: Iterator[(A, Nothing)] = Iterator.empty def toStream: Stream[(A,Nothing)] = Stream.empty - def foreach[U](f: (A, Nothing) => U) {} + def foreach[U](f: (A, Nothing) => U) {} @deprecated("use `foreach' instead") - def visit[T](input : T)(f : (T,A,Nothing) => Tuple2[Boolean,T]) = Tuple2(true,input) + def visit[T](input: T)(f: (T, A, Nothing) => (Boolean, T)) = (true, input) - def range(from : Option[A], until : Option[A]) = this + def range(from: Option[A], until: Option[A]) = this def first = throw new NoSuchElementException("empty map") def last = throw new NoSuchElementException("empty map") def count = 0 diff --git a/src/library/scala/collection/immutable/Sequence.scala b/src/library/scala/collection/immutable/Sequence.scala index 7663b9c3ce..3ce7cd3b00 100644 --- a/src/library/scala/collection/immutable/Sequence.scala +++ b/src/library/scala/collection/immutable/Sequence.scala @@ -5,6 +5,10 @@ ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ + +// $Id$ + + package scala.collection.immutable import scala.collection.generic._ diff --git a/src/library/scala/collection/immutable/SetProxy.scala b/src/library/scala/collection/immutable/SetProxy.scala index 30b11f62b4..55acfe0236 100644 --- a/src/library/scala/collection/immutable/SetProxy.scala +++ b/src/library/scala/collection/immutable/SetProxy.scala @@ -6,6 +6,9 @@ ** |/ ** \* */ +// $Id$ + + package scala.collection.immutable import scala.collection.generic.SetProxyTemplate @@ -19,7 +22,6 @@ import scala.collection.generic.SetProxyTemplate * dynamically using object composition and forwarding. * </p> */ - trait SetProxy[A] extends Set[A] with SetProxyTemplate[A, Set[A]] { override def repr = this diff --git a/src/library/scala/collection/immutable/SortedMap.scala b/src/library/scala/collection/immutable/SortedMap.scala index b363c54a29..4f3bbf6c0d 100644 --- a/src/library/scala/collection/immutable/SortedMap.scala +++ b/src/library/scala/collection/immutable/SortedMap.scala @@ -9,17 +9,17 @@ // $Id$ +package scala.collection.immutable + +import scala.collection.generic._ +import annotation.unchecked.uncheckedVariance + /** A map whose keys are sorted. * * @author Sean McDirmid * @author Martin Odersky * @version 2.8 */ -package scala.collection.immutable - -import scala.collection.generic._ -import annotation.unchecked.uncheckedVariance - trait SortedMap[A, +B] extends Map[A, B] with collection.SortedMap[A, B] with ImmutableMapTemplate[A, B, SortedMap[A, B]] diff --git a/src/library/scala/collection/immutable/SortedSet.scala b/src/library/scala/collection/immutable/SortedSet.scala index 80fd411acd..d2afc58cf2 100644 --- a/src/library/scala/collection/immutable/SortedSet.scala +++ b/src/library/scala/collection/immutable/SortedSet.scala @@ -8,16 +8,17 @@ // $Id$ + +package scala.collection.immutable + +import scala.collection.generic._ + /** A sorted set. * * @author Sean McDirmid * @author Martin Odersky * @version 2.8 */ -package scala.collection.immutable - -import scala.collection.generic._ - trait SortedSet[A] extends Set[A] with collection.SortedSet[A] with SortedSetTemplate[A, SortedSet[A]] { /** Needs to be overridden in subclasses. */ override def empty: SortedSet[A] = throw new UnsupportedOperationException("SortedMap.empty") diff --git a/src/library/scala/collection/immutable/Stack.scala b/src/library/scala/collection/immutable/Stack.scala index 4684a22162..779e727623 100644 --- a/src/library/scala/collection/immutable/Stack.scala +++ b/src/library/scala/collection/immutable/Stack.scala @@ -11,42 +11,46 @@ package scala.collection.immutable - -//import Predef.NoSuchElementException +import scala.annotation.tailrec object Stack { - val Empty = new Stack[Nothing] + val Empty: Stack[Nothing] = new Stack(Nil) + def apply[A](elems: A*) = new Stack(elems.toList) } /** This class implements immutable stacks using a list-based data * structure. Instances of <code>Stack</code> represent * empty stacks; they can be either created by calling the constructor * directly, or by applying the function <code>Stack.Empty</code>. - * @note This class exists only for historical reason and as an analogue of mutable stacks + * + * @note This class exists only for historical reason and as an + * analogue of mutable stacks * Instead of an immutable stack you can just use a list. * * @author Matthias Zenger * @version 1.0, 10/07/2003 */ -@serializable -class Stack[+A] extends Sequence[A] { +@serializable @SerialVersionUID(1976480595012942526L) +class Stack[+A] protected (protected val elems: List[A]) extends Sequence[A] { + + def this() = this(Nil) /** Checks if this stack is empty. * * @return true, iff there is no element on the stack. */ - override def isEmpty: Boolean = true + override def isEmpty: Boolean = elems.isEmpty /** The number of elements in the stack */ - def length: Int = 0 + def length: Int = elems.length /** Push an element on the stack. * * @param elem the element to push on the stack. * @return the stack with the new element on top. */ - def push[B >: A](elem: B): Stack[B] = new Node(elem) + def push[B >: A](elem: B): Stack[B] = new Stack(elem :: elems) /** Push a sequence of elements onto the stack. The last element * of the sequence will be on top of the new stack. @@ -81,23 +85,45 @@ class Stack[+A] extends Sequence[A] { /** Returns the top element of the stack. An error is signaled if * there is no element on the stack. * + * @throws Predef.NoSuchElementException * @return the top element. */ - def top: A = throw new NoSuchElementException("top of empty stack") + def top: A = + if (!elems.isEmpty) elems.head + else throw new NoSuchElementException("top of empty stack") /** Removes the top element from the stack. + * Note: should return <code>(A, Stack[A])</code> as for queues (mics) * + * @throws Predef.NoSuchElementException * @return the new stack without the former top element. */ - def pop: Stack[A] = throw new NoSuchElementException("pop of empty stack") + def pop: Stack[A] = + if (!elems.isEmpty) new Stack(elems.tail) + else throw new NoSuchElementException("pop of empty stack") + + def pop2: (A, Stack[A]) = + if (!elems.isEmpty) (elems.head, new Stack(elems.tail)) + else throw new NoSuchElementException("pop of empty stack") /** Returns the n-th element of this stack. The bottom element has index * 0, elements above are indexed with increasing numbers. * + * @throws Predef.NoSuchElementException * @param n the index number. * @return the n-th element on the stack. */ - def apply(n: Int): A = if (n <= 0) top else pop.apply(n - 1) + def apply(n: Int): A = { + @tailrec + def walk(i: Int, xs: List[A]): A = + (i == 0, xs.isEmpty) match { + case (_, true) => throw new NoSuchElementException("index out of range") + case (true, _) => xs.head + case (false, _) => walk(i - 1, xs.tail) + } + + walk(n, elems) + } /** Returns an iterator over all elements on the stack. The iterator * issues elements in the reversed order they were inserted into the @@ -111,17 +137,17 @@ class Stack[+A] extends Sequence[A] { def next: A = { val r = top; cur = cur.pop; r } } - /** - * Redefines the prefix of the string representation. + /** Returns the hash code for this stack. + * + * @return the hash code of the stack. */ - override def stringPrefix: String = "Stack" - - @serializable - protected class Node[+B >: A](elem: B) extends Stack[B] { - override def isEmpty: Boolean = false - override def length: Int = Stack.this.length + 1 - override def top: B = elem - override def pop: Stack[B] = Stack.this - } + override def hashCode(): Int = //"Stack".hashCode + if (isEmpty) 0 + else pop2 match { case (x,y) => x.hashCode + y.hashCode } + + /** Returns a string representation of this stack. + */ + override def toString() = elems.mkString("Stack(", ", ", ")") + } diff --git a/src/library/scala/collection/immutable/Traversable.scala b/src/library/scala/collection/immutable/Traversable.scala index 53fc96aae0..ed79a87b7a 100644 --- a/src/library/scala/collection/immutable/Traversable.scala +++ b/src/library/scala/collection/immutable/Traversable.scala @@ -1,13 +1,25 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id: $ + + package scala.collection.immutable import scala.collection.generic._ import scala.collection.mutable -/** A subtrait of Traversable in package collection which represents traversables - * that cannot be mutated. +/** A subtrait of <code>collection.Traversable</code> which represents + * traversables that cannot be mutated. * !!! todo: revise equality + * * @author Matthias Zenger - * @author Martin Odersky + * @author Martin Odersky * @version 2.8 */ trait Traversable[+A] extends collection.Traversable[A] @@ -17,10 +29,13 @@ trait Traversable[+A] extends collection.Traversable[A] override def companion: Companion[Traversable] = Traversable } -/* A factory object for the trait `Traversable` */ +/** A factory object for the trait <code>Traversable</code>. + * + * @author Martin Odersky + * @version 2.8 + */ object Traversable extends TraversableFactory[Traversable] { - implicit def builderFactory[A]: BuilderFactory[A, Traversable[A], Coll] = new VirtualBuilderFactory[A] + implicit def builderFactory[A]: BuilderFactory[A, Traversable[A], Coll] = + new VirtualBuilderFactory[A] def newBuilder[A]: Builder[A, Traversable[A]] = new mutable.ListBuffer } - - diff --git a/src/library/scala/collection/immutable/TreeMap.scala b/src/library/scala/collection/immutable/TreeMap.scala index c146064296..90f8fe9827 100644 --- a/src/library/scala/collection/immutable/TreeMap.scala +++ b/src/library/scala/collection/immutable/TreeMap.scala @@ -8,6 +8,7 @@ // $Id$ + package scala.collection.immutable import scala.collection.generic._ diff --git a/src/library/scala/collection/immutable/TreeSet.scala b/src/library/scala/collection/immutable/TreeSet.scala index 0e5496828a..58d1bddba5 100644 --- a/src/library/scala/collection/immutable/TreeSet.scala +++ b/src/library/scala/collection/immutable/TreeSet.scala @@ -13,15 +13,17 @@ package scala.collection.immutable import scala.collection.generic._ -/** The canonical factory of <a href="TreeSet.html">TreeSet</a>'s. */ +/** The canonical factory of <a href="TreeSet.html">TreeSet</a>'s. + */ object TreeSet extends SortedSetFactory[TreeSet]{ - implicit def implicitBuilder[A](implicit ordering : Ordering[A]) : Builder[A, TreeSet[A]] = newBuilder[A](ordering) - def newBuilder[A](implicit ordering : Ordering[A]) : Builder[A, TreeSet[A]] = new AddingBuilder(empty[A](ordering)) + implicit def implicitBuilder[A](implicit ordering: Ordering[A]): Builder[A, TreeSet[A]] = newBuilder[A](ordering) + def newBuilder[A](implicit ordering: Ordering[A]): Builder[A, TreeSet[A]] = + new AddingBuilder(empty[A](ordering)) /** The empty set of this type */ - def empty[A](implicit ordering : Ordering[A]) = new TreeSet[A] + def empty[A](implicit ordering: Ordering[A]) = new TreeSet[A] } @@ -30,16 +32,16 @@ object TreeSet extends SortedSetFactory[TreeSet]{ * @author Martin Odersky * @version 2.0, 02/01/2007 */ - -@serializable -class TreeSet[A](override val size: Int, t: RedBlack[A]#Tree[Unit])(implicit val ordering : Ordering[A]) +@serializable @SerialVersionUID(-234066569443569402L) +class TreeSet[A](override val size: Int, t: RedBlack[A]#Tree[Unit]) + (implicit val ordering: Ordering[A]) extends RedBlack[A] with SortedSet[A] with SortedSetTemplate[A, TreeSet[A]] { override def stringPrefix = "TreeSet" def isSmaller(x: A, y: A) = compare(x,y) < 0 - def this()(implicit ordering : Ordering[A]) = this(0, null)(ordering) + def this()(implicit ordering: Ordering[A]) = this(0, null)(ordering) protected val tree: RedBlack[A]#Tree[Unit] = if (size == 0) Empty else t @@ -59,14 +61,14 @@ class TreeSet[A](override val size: Int, t: RedBlack[A]#Tree[Unit])(implicit val /** A new TreeSet with the entry added is returned, * assuming that elem is <em>not</em> in the TreeSet. */ - def insert (elem: A): TreeSet[A] = { + def insert(elem: A): TreeSet[A] = { assert(tree.lookup(elem).isEmpty) newSet(size + 1, tree.update(elem, ())) } def - (elem:A): TreeSet[A] = if (tree.lookup(elem).isEmpty) this - else newSet(size - 1, tree.delete(elem)) + else newSet(size - 1, tree delete elem) /** Checks if this set contains element <code>elem</code>. * diff --git a/src/library/scala/collection/immutable/Vector.scala b/src/library/scala/collection/immutable/Vector.scala index 41b4be580a..ff224507ee 100644 --- a/src/library/scala/collection/immutable/Vector.scala +++ b/src/library/scala/collection/immutable/Vector.scala @@ -5,12 +5,16 @@ ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ + +// $Id$ + + package scala.collection.immutable import scala.collection.generic._ import scala.collection.mutable.ArrayBuffer -/** A subtrait of collection.Vector which represents sequences +/** A subtrait of <code>collection.Vector</code> which represents sequences * that cannot be mutated. */ trait Vector[+A] extends Sequence[A] @@ -21,10 +25,14 @@ trait Vector[+A] extends Sequence[A] } object Vector extends SequenceFactory[Vector] { - class Impl[A](buf: ArrayBuffer[A]) extends Vector[A] { // todo: insert better vector implementation here + // todo: insert better vector implementation here + @serializable @SerialVersionUID(7129304555082767876L) + class Impl[A](buf: ArrayBuffer[A]) extends Vector[A] { def length = buf.length def apply(idx: Int) = buf.apply(idx) } - implicit def builderFactory[A]: BuilderFactory[A, Vector[A], Coll] = new VirtualBuilderFactory[A] - def newBuilder[A]: Builder[A, Vector[A]] = new ArrayBuffer[A] mapResult (buf => new Impl(buf)) + implicit def builderFactory[A]: BuilderFactory[A, Vector[A], Coll] = + new VirtualBuilderFactory[A] + def newBuilder[A]: Builder[A, Vector[A]] = + new ArrayBuffer[A] mapResult (buf => new Impl(buf)) } diff --git a/src/library/scala/collection/mutable/ArrayBuffer.scala b/src/library/scala/collection/mutable/ArrayBuffer.scala index d4986265a2..55a4870748 100644 --- a/src/library/scala/collection/mutable/ArrayBuffer.scala +++ b/src/library/scala/collection/mutable/ArrayBuffer.scala @@ -22,7 +22,7 @@ import scala.collection.generic._ * @author Martin Odersky * @version 2.8 */ -@serializable +@serializable @SerialVersionUID(1529165946227428979L) class ArrayBuffer[A](override protected val initialSize: Int) extends Buffer[A] with TraversableClass[A, ArrayBuffer] @@ -157,9 +157,14 @@ class ArrayBuffer[A](override protected val initialSize: Int) override def stringPrefix: String = "ArrayBuffer" } -/* Factory object for `ArrayBuffer` class */ +/** Factory object for <code>ArrayBuffer</code> class. + * + * @author Martin Odersky + * @version 2.8 + */ object ArrayBuffer extends SequenceFactory[ArrayBuffer] { - implicit def builderFactory[A]: BuilderFactory[A, ArrayBuffer[A], Coll] = new VirtualBuilderFactory[A] + implicit def builderFactory[A]: BuilderFactory[A, ArrayBuffer[A], Coll] = + new VirtualBuilderFactory[A] def newBuilder[A]: Builder[A, ArrayBuffer[A]] = new ArrayBuffer[A] } diff --git a/src/library/scala/collection/mutable/ArrayStack.scala b/src/library/scala/collection/mutable/ArrayStack.scala index 8ceff87d19..5401b2f2de 100644 --- a/src/library/scala/collection/mutable/ArrayStack.scala +++ b/src/library/scala/collection/mutable/ArrayStack.scala @@ -8,21 +8,22 @@ // $Id$ -package scala.collection.mutable; + +package scala.collection.mutable import scala.collection.generic._ -private object Utils{ - def growArray(x : Array[AnyRef]) = { - val y = new Array[AnyRef](x.length * 2); - Array.copy(x, 0, y, 0, x.length); - y; +private object Utils { + def growArray(x: Array[AnyRef]) = { + val y = new Array[AnyRef](x.length * 2) + Array.copy(x, 0, y, 0, x.length) + y } - def clone(x : Array[AnyRef]) = { - val y = new Array[AnyRef](x.length); - Array.copy(x, 0, y, 0, x.length); - y; + def clone(x: Array[AnyRef]) = { + val y = new Array[AnyRef](x.length) + Array.copy(x, 0, y, 0, x.length) + y } } @@ -35,10 +36,10 @@ private object Utils{ @cloneable class ArrayStack[T] private(private var table : Array[AnyRef], private var index : Int) extends collection.Sequence[T] with Cloneable[ArrayStack[T]] { - def this() = this(new Array[AnyRef](1), 0); + def this() = this(new Array[AnyRef](1), 0) /** Retrieve n'th element from stack, where top of stack has index 0 */ - def apply(n: Int) = + def apply(n: Int): T = table(index - 1 - n).asInstanceOf[T] /** The number of elements in the stack */ @@ -49,21 +50,21 @@ class ArrayStack[T] private(private var table : Array[AnyRef], * * @param x The element to push */ - def push(x : T) = { - if (index == table.length) table = Utils.growArray(table); - table(index) = x.asInstanceOf[AnyRef]; - index += 1; + def push(x: T) { + if (index == table.length) table = Utils.growArray(table) + table(index) = x.asInstanceOf[AnyRef] + index += 1 } /** * Pop the top element off the stack. */ - def pop = { - if (index == 0) error("Stack empty"); - index -= 1; - val x = table(index).asInstanceOf[T]; - table(index) = null; - x; + def pop: T = { + if (index == 0) error("Stack empty") + index -= 1 + val x = table(index).asInstanceOf[T] + table(index) = null + x } /** View the top element of the stack. */ @@ -73,19 +74,19 @@ class ArrayStack[T] private(private var table : Array[AnyRef], /** * View the top element of the stack. */ - def top = table(index - 1).asInstanceOf[T] + def top: T = table(index - 1).asInstanceOf[T] /** * Duplicate the top element of the stack. */ - def dup = push(top); + def dup = push(top) /** * Empties the stack. */ - def clear = { - index = 0; - table = new Array(1); + def clear { + index = 0 + table = new Array(1) } /** @@ -94,14 +95,14 @@ class ArrayStack[T] private(private var table : Array[AnyRef], * * @param f The function to drain to. */ - def drain(f : T => Unit) = while(!isEmpty) f(pop); + def drain(f: T => Unit) = while (!isEmpty) f(pop) /** * Pushes all the provided elements onto the stack. * * @param x The source of elements to push */ - def ++=(x : collection.Iterable[T]): this.type = { x.foreach(this +=(_)); this } + def ++=(x: collection.Iterable[T]): this.type = { x.foreach(this +=(_)); this } /** @@ -109,16 +110,14 @@ class ArrayStack[T] private(private var table : Array[AnyRef], * * @param x The source of elements to push */ - def ++=(x : Iterator[T]): this.type = { x.foreach(this +=(_)); this } + def ++=(x: Iterator[T]): this.type = { x.foreach(this +=(_)); this } /** * Alias for push. * * @param x The element to push */ - def +=(x : T): this.type = { push(x); this } - - + def +=(x: T): this.type = { push(x); this } /** * Pop the top two elements off the stack, apply f to them and push the result @@ -126,15 +125,15 @@ class ArrayStack[T] private(private var table : Array[AnyRef], * * @param f The combining function */ - def combine(f : (T, T) => T) = push(f(pop, pop)); + def combine(f: (T, T) => T) = push(f(pop, pop)); /** * Repeatedly combine the top elements of the stack until the stack contains only * one element. */ - def reduceWith(f : (T, T) => T) = while(size > 1) combine(f) + def reduceWith(f: (T, T) => T) = while(size > 1) combine(f) - override def size = index; + override def size = index /** * Evaluates the expression, preserving the contents of the stack so that @@ -143,39 +142,39 @@ class ArrayStack[T] private(private var table : Array[AnyRef], * * @param action The action to run. */ - def preserving[T](action : => T) = { - val oldIndex = index; - val oldTable = Utils.clone(table); + def preserving[T](action: => T) = { + val oldIndex = index + val oldTable = Utils.clone(table) - try{ - action; + try { + action } finally { - index = oldIndex; - table = oldTable; + index = oldIndex + table = oldTable } } - override def isEmpty = index == 0; + override def isEmpty: Boolean = index == 0 /** * Iterates over the stack in LIFO order. */ - def iterator: Iterator[T] = new Iterator[T]{ - var currentIndex = index; - def hasNext = currentIndex > 0; + def iterator: Iterator[T] = new Iterator[T] { + var currentIndex = index + def hasNext = currentIndex > 0 def next = { - currentIndex -= 1; - table(currentIndex).asInstanceOf[T]; + currentIndex -= 1 + table(currentIndex).asInstanceOf[T] } } - override def foreach[U](f : T => U){ - var currentIndex = index; - while(currentIndex > 0){ - currentIndex -= 1; - f(table(currentIndex).asInstanceOf[T]); + override def foreach[U](f: T => U) { + var currentIndex = index + while (currentIndex > 0) { + currentIndex -= 1 + f(table(currentIndex).asInstanceOf[T]) } } - override def clone = new ArrayStack[T](Utils.clone(table), index); + override def clone = new ArrayStack[T](Utils.clone(table), index) } diff --git a/src/library/scala/collection/mutable/Buffer.scala b/src/library/scala/collection/mutable/Buffer.scala index fcbe4f655f..4264bcad00 100644 --- a/src/library/scala/collection/mutable/Buffer.scala +++ b/src/library/scala/collection/mutable/Buffer.scala @@ -29,7 +29,8 @@ trait Buffer[A] extends Sequence[A] override def companion: Companion[Buffer] = Buffer } -/* Factory object for `Buffer` trait */ +/** Factory object for <code>Buffer</code> trait. + */ object Buffer extends SequenceFactory[Buffer] { implicit def builderFactory[A]: BuilderFactory[A, Buffer[A], Coll] = new VirtualBuilderFactory[A] def newBuilder[A]: Builder[A, Buffer[A]] = new ArrayBuffer diff --git a/src/library/scala/collection/mutable/BufferProxy.scala b/src/library/scala/collection/mutable/BufferProxy.scala index a69b51cfb9..1c52751308 100644 --- a/src/library/scala/collection/mutable/BufferProxy.scala +++ b/src/library/scala/collection/mutable/BufferProxy.scala @@ -1,7 +1,7 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** ** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ @@ -68,14 +68,14 @@ trait BufferProxy[A] extends Buffer[A] with Proxy { * * @param elems the elements to append. */ - override def append(elems: A*): Unit = self.++=(elems) + override def append(elems: A*) { self.++=(elems) } /** Appends a number of elements provided by an iterable object * via its <code>iterator</code> method. * * @param iter the iterable object. */ - def appendAll(iter: collection.Iterable[A]): Unit = self.appendAll(iter) + def appendAll(iter: collection.Iterable[A]) { self.appendAll(iter) } /** Prepend a single element to this buffer and return * the identity of the buffer. @@ -96,7 +96,7 @@ trait BufferProxy[A] extends Buffer[A] with Proxy { * * @param elem the element to prepend. */ - override def prepend(elems: A*): Unit = self.prependAll(elems) + override def prepend(elems: A*) { self.prependAll(elems) } /** Prepends a number of elements provided by an iterable object * via its <code>iterator</code> method. The identity of the @@ -104,7 +104,7 @@ trait BufferProxy[A] extends Buffer[A] with Proxy { * * @param iter the iterable object. */ - def prependAll(elems: collection.Iterable[A]): Unit = self.prependAll(elems) + def prependAll(elems: collection.Iterable[A]) { self.prependAll(elems) } /** Inserts new elements at the index <code>n</code>. Opposed to method * <code>update</code>, this method will not replace an element with a @@ -113,7 +113,7 @@ trait BufferProxy[A] extends Buffer[A] with Proxy { * @param n the index where a new element will be inserted. * @param elems the new elements to insert. */ - override def insert(n: Int, elems: A*): Unit = self.insertAll(n, elems) + override def insert(n: Int, elems: A*) { self.insertAll(n, elems) } /** Inserts new elements at the index <code>n</code>. Opposed to method * <code>update</code>, this method will not replace an element with a @@ -142,13 +142,13 @@ trait BufferProxy[A] extends Buffer[A] with Proxy { /** Clears the buffer contents. */ - def clear(): Unit = self.clear + def clear() { self.clear } /** Send a message to this scriptable object. * * @param cmd the message to send. */ - override def <<(cmd: Message[A]): Unit = self << cmd + override def <<(cmd: Message[A]) { self << cmd } /** Return a clone of this buffer. * diff --git a/src/library/scala/collection/mutable/CloneableCollection.scala b/src/library/scala/collection/mutable/CloneableCollection.scala index 354e71435e..40ee9f8649 100644 --- a/src/library/scala/collection/mutable/CloneableCollection.scala +++ b/src/library/scala/collection/mutable/CloneableCollection.scala @@ -11,9 +11,10 @@ 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 +/** The J2ME version of the library defined this trait with a <code>clone</code> + * method to substitute for the lack of <code>Object.clone</code> there. */ -@deprecated("use Cloneable instead") trait CloneableCollection { +@deprecated("use Cloneable instead") +trait CloneableCollection { override def clone(): AnyRef = super.clone() } diff --git a/src/library/scala/collection/mutable/DefaultMapModel.scala b/src/library/scala/collection/mutable/DefaultMapModel.scala index f76a54c739..0f18ea0986 100644 --- a/src/library/scala/collection/mutable/DefaultMapModel.scala +++ b/src/library/scala/collection/mutable/DefaultMapModel.scala @@ -1,7 +1,7 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** ** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** +** __\ \/ /__/ __ |/ /__/ __ | http://www.scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ @@ -43,4 +43,3 @@ trait DefaultMapModel[A, B] extends Map[A, B] { def iterator = entries map {e => (e.key, e.value)} } - diff --git a/src/library/scala/collection/mutable/DoubleLinkedList.scala b/src/library/scala/collection/mutable/DoubleLinkedList.scala index e66a20c0cf..6471f4ba3c 100644 --- a/src/library/scala/collection/mutable/DoubleLinkedList.scala +++ b/src/library/scala/collection/mutable/DoubleLinkedList.scala @@ -20,7 +20,7 @@ import scala.collection.generic._ * @author Martin Odersky * @version 2.8 */ -@serializable +@serializable @SerialVersionUID(419155950203746706L) class DoubleLinkedList[A](_elem: A, _next: DoubleLinkedList[A]) extends LinearSequence[A] with TraversableClass[A, DoubleLinkedList] with DoubleLinkedListTemplate[A, DoubleLinkedList[A]] { diff --git a/src/library/scala/collection/mutable/HashMap.scala b/src/library/scala/collection/mutable/HashMap.scala index a8c2e14655..f3e02cd0e8 100644 --- a/src/library/scala/collection/mutable/HashMap.scala +++ b/src/library/scala/collection/mutable/HashMap.scala @@ -13,8 +13,7 @@ package scala.collection.mutable import scala.collection.generic._ - -@serializable +@serializable @SerialVersionUID(-8682987922734091219L) class HashMap[A, B] extends Map[A, B] with MutableMapTemplate[A, B, HashMap[A, B]] with HashTable[A] { diff --git a/src/library/scala/collection/mutable/History.scala b/src/library/scala/collection/mutable/History.scala index 27d7b8c40e..1e96b7accd 100644 --- a/src/library/scala/collection/mutable/History.scala +++ b/src/library/scala/collection/mutable/History.scala @@ -21,6 +21,7 @@ package scala.collection.mutable * @version 1.0, 08/07/2003 */ @serializable +@SerialVersionUID(5219213543849892588L) class History[A, B] extends AnyRef with Subscriber[A, B] with Iterable[(B, A)] { protected val log: Queue[(B, A)] = new Queue[(B, A)] @@ -30,7 +31,7 @@ class History[A, B] extends AnyRef with Subscriber[A, B] with Iterable[(B, A)] * @param pub ... * @param event ... */ - def notify(pub: B, event: A): Unit = { + def notify(pub: B, event: A) { if (log.length >= maxHistory) log.dequeue @@ -41,5 +42,14 @@ class History[A, B] extends AnyRef with Subscriber[A, B] with Iterable[(B, A)] def iterator: Iterator[(B, A)] = log.iterator def events: Iterator[A] = log.iterator.map { case (_, e) => e } - def clear(): Unit = log.clear + def clear() { log.clear } + + /** Checks if two history objects are structurally identical. + * + * @return true, iff both history objects contain the same sequence of elements. + */ + override def equals(obj: Any): Boolean = obj match { + case that: History[_, _] => this.log equals that.log + case _ => false + } } diff --git a/src/library/scala/collection/mutable/LinkedList.scala b/src/library/scala/collection/mutable/LinkedList.scala index b02b2bc90b..25cde0e993 100644 --- a/src/library/scala/collection/mutable/LinkedList.scala +++ b/src/library/scala/collection/mutable/LinkedList.scala @@ -30,9 +30,8 @@ class LinkedList[A](_elem: A, _next: LinkedList[A]) extends LinearSequence[A] } object LinkedList extends SequenceFactory[LinkedList] { - implicit def builderFactory[A]: BuilderFactory[A, LinkedList[A], Coll] = new VirtualBuilderFactory[A] - def newBuilder[A]: Builder[A, LinkedList[A]] = (new MutableList) mapResult ((l: MutableList[A]) => l.toLinkedList) + implicit def builderFactory[A]: BuilderFactory[A, LinkedList[A], Coll] = + new VirtualBuilderFactory[A] + def newBuilder[A]: Builder[A, LinkedList[A]] = + (new MutableList) mapResult ((l: MutableList[A]) => l.toLinkedList) } - - - diff --git a/src/library/scala/collection/mutable/ListBuffer.scala b/src/library/scala/collection/mutable/ListBuffer.scala index 4b2bfcf6b0..4486d3b394 100644 --- a/src/library/scala/collection/mutable/ListBuffer.scala +++ b/src/library/scala/collection/mutable/ListBuffer.scala @@ -21,7 +21,7 @@ import scala.collection.immutable * @author Martin Odersky * @version 2.8 */ -@serializable +@serializable @SerialVersionUID(3419063961353022661L) final class ListBuffer[A] extends Buffer[A] with TraversableClass[A, ListBuffer] @@ -47,8 +47,8 @@ final class ListBuffer[A] // Implementations of abstract methods in Buffer /** Replaces element at index <code>n</code> with the new element - * <code>newelem</code>. Takes time linear in the buffer size. (except the first - * element, which is updated in constant time). + * <code>newelem</code>. Takes time linear in the buffer size. (except the + * first element, which is updated in constant time). * * @param n the index of the element to replace. * @param x the new element. @@ -164,8 +164,8 @@ final class ListBuffer[A] } } - /** Removes a given number of elements on a given index position. May take time linear in - * the buffer size. + /** Removes a given number of elements on a given index position. May take + * time linear in the buffer size. * * @param n the index which refers to the first element to remove. * @param count the number of elements to remove. @@ -174,7 +174,7 @@ final class ListBuffer[A] if (exported) copy() val n1 = n max 0 val count1 = count min (len - n1) - var old = start.head; + var old = start.head if (n1 == 0) { var c = count1 while (c > 0) { @@ -233,7 +233,7 @@ final class ListBuffer[A] def remove(n: Int): A = try { if (n < 0 || n >= len) throw new IndexOutOfBoundsException(n.toString()) if (exported) copy() - var old = start.head; + var old = start.head if (n == 0) { start = start.tail } else { @@ -251,7 +251,8 @@ final class ListBuffer[A] old } - /** Remove a single element from this buffer. May take time linear in the buffer size. + /** Remove a single element from this buffer. May take time linear in the + * buffer size. * * @param x the element to remove. */ @@ -305,6 +306,11 @@ final class ListBuffer[A] } } + override def equals(that: Any): Boolean = that match { + case that: ListBuffer[_] => this.readOnly equals that.readOnly + case _ => super.equals(that) + } + /** Returns a clone of this buffer. * * @return a <code>ListBuffer</code> with the same elements. @@ -318,9 +324,14 @@ final class ListBuffer[A] override def stringPrefix: String = "ListBuffer" } -/* Factory object for `ListBuffer` class */ +/** Factory object for <code>ListBuffer</code> class. + * + * @author Martin Odersky + * @version 2.8 + */ object ListBuffer extends SequenceFactory[ListBuffer] { - implicit def builderFactory[A]: BuilderFactory[A, ListBuffer[A], Coll] = new VirtualBuilderFactory[A] - def newBuilder[A]: Builder[A, ListBuffer[A]] = new AddingBuilder(new ListBuffer[A]) + implicit def builderFactory[A]: BuilderFactory[A, ListBuffer[A], Coll] = + new VirtualBuilderFactory[A] + def newBuilder[A]: Builder[A, ListBuffer[A]] = + new AddingBuilder(new ListBuffer[A]) } - diff --git a/src/library/scala/collection/mutable/MutableList.scala b/src/library/scala/collection/mutable/MutableList.scala index c1de157628..28b6ccbd5a 100644 --- a/src/library/scala/collection/mutable/MutableList.scala +++ b/src/library/scala/collection/mutable/MutableList.scala @@ -74,7 +74,7 @@ class MutableList[A] extends LinearSequence[A] */ def get(n: Int): Option[A] = first0.get(n) - protected def prependElem(elem: A): Unit = { + protected def prependElem(elem: A) { first0 = new LinkedList[A](elem, first0) if (len == 0) last0 = first0 @@ -90,7 +90,8 @@ class MutableList[A] extends LinearSequence[A] len = len + 1 } - @deprecated("use clear instead") def reset() { clear() } + @deprecated("use clear instead") + def reset() { clear() } /** Returns an iterator over all elements of this list. */ diff --git a/src/library/scala/collection/mutable/Publisher.scala b/src/library/scala/collection/mutable/Publisher.scala index a0d5b0c668..60b1e185dc 100644 --- a/src/library/scala/collection/mutable/Publisher.scala +++ b/src/library/scala/collection/mutable/Publisher.scala @@ -1,7 +1,7 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** ** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ @@ -31,16 +31,30 @@ trait Publisher[A, This <: Publisher[A, This]] { private val filters = new HashMap[SubThis, Set[Filter]] with MultiMap[SubThis, Filter] private val suspended = new HashSet[SubThis] - def subscribe(sub: SubThis): Unit = subscribe(sub, event => true) - def subscribe(sub: SubThis, filter: Filter): Unit = filters(sub) += filter - def suspendSubscription(sub: SubThis): Unit = suspended += sub - def activateSubscription(sub: SubThis): Unit = suspended -= sub - def removeSubscription(sub: SubThis): Unit = filters -= sub + def subscribe(sub: SubThis) { subscribe(sub, event => true) } + def subscribe(sub: SubThis, filter: Filter) { filters(sub) += filter } + def suspendSubscription(sub: SubThis) { suspended += sub } + def activateSubscription(sub: SubThis) { suspended -= sub } + def removeSubscription(sub: SubThis) { filters -= sub } def removeSubscriptions() { filters.clear } - protected def publish(event: A): Unit = + protected def publish(event: A) { filters.keysIterator.foreach(sub => if (filters.entryExists(sub, p => p(event))) sub.notify(this, event) ) -}
\ No newline at end of file + } + + /** Checks if two publishers are structurally identical. + * + * @return true, iff both publishers contain the same sequence of elements. + */ + override def equals(obj: Any): Boolean = obj match { + case that: Publisher[_, _] => + (this.filters equals that.filters) && + (this.suspended equals that.suspended) + case _ => + false + } + +} diff --git a/src/library/scala/collection/mutable/Sequence.scala b/src/library/scala/collection/mutable/Sequence.scala index 6ce3afae33..2a263b0a4d 100644 --- a/src/library/scala/collection/mutable/Sequence.scala +++ b/src/library/scala/collection/mutable/Sequence.scala @@ -5,13 +5,17 @@ ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ + +// $Id$ + + package scala.collection.mutable import scala.collection.generic._ -/** A subtrait of collection.Sequence which represents sequences +/** A subtrait of <code>collection.Sequence</code> which represents sequences * that can be mutated. - * The class adds an `update` method to collection.Sequence. + * The class adds an <code>update</code> method to <code>collection.Sequence</code>. */ trait Sequence[A] extends Iterable[A] with collection.Sequence[A] @@ -23,6 +27,11 @@ trait Sequence[A] extends Iterable[A] def update(idx: Int, elem: A) } +/** A factory object for the trait <code>Sequence</code>. + * + * @author Martin Odersky + * @version 2.8 + */ object Sequence extends SequenceFactory[Sequence] { implicit def builderFactory[A]: BuilderFactory[A, Sequence[A], Coll] = new VirtualBuilderFactory[A] def newBuilder[A]: Builder[A, Sequence[A]] = new ArrayBuffer diff --git a/src/library/scala/collection/mutable/Subscriber.scala b/src/library/scala/collection/mutable/Subscriber.scala index 751fe12498..47f7519bd7 100644 --- a/src/library/scala/collection/mutable/Subscriber.scala +++ b/src/library/scala/collection/mutable/Subscriber.scala @@ -1,7 +1,7 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** ** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ diff --git a/src/library/scala/collection/mutable/Traversable.scala b/src/library/scala/collection/mutable/Traversable.scala index 025100fb91..efe06852b3 100644 --- a/src/library/scala/collection/mutable/Traversable.scala +++ b/src/library/scala/collection/mutable/Traversable.scala @@ -5,14 +5,18 @@ ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ + +// $Id$ + + package scala.collection.mutable import scala.collection.generic._ -/** A subtrait of collection.Traversable which represents traversables - * that can be mutated. +/** A subtrait of <code>collection.Traversable</code> which represents + * traversables that can be mutated. * - * @author Martin Odersky + * @author Martin Odersky * @version 2.8 */ trait Traversable[A] extends collection.Traversable[A] @@ -22,9 +26,14 @@ trait Traversable[A] extends collection.Traversable[A] override def companion: Companion[Traversable] = Traversable } -/* A factory object for the trait `Traversable` */ +/** A factory object for the trait <code>Traversable</code>. + * + * @author Martin Odersky + * @version 2.8 + */ object Traversable extends TraversableFactory[Traversable] { - implicit def builderFactory[A]: BuilderFactory[A, Traversable[A], Coll] = new VirtualBuilderFactory[A] + implicit def builderFactory[A]: BuilderFactory[A, Traversable[A], Coll] = + new VirtualBuilderFactory[A] def newBuilder[A]: Builder[A, Traversable[A]] = new ArrayBuffer } diff --git a/src/library/scala/collection/mutable/Undoable.scala b/src/library/scala/collection/mutable/Undoable.scala index 121b144359..850dcc0e6c 100644 --- a/src/library/scala/collection/mutable/Undoable.scala +++ b/src/library/scala/collection/mutable/Undoable.scala @@ -1,7 +1,7 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** ** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ @@ -22,4 +22,4 @@ trait Undoable { /** Undo the last operation. */ def undo(): Unit -}
\ No newline at end of file +} diff --git a/src/library/scala/collection/mutable/Vector.scala b/src/library/scala/collection/mutable/Vector.scala index 97e144810c..2b6e497731 100644 --- a/src/library/scala/collection/mutable/Vector.scala +++ b/src/library/scala/collection/mutable/Vector.scala @@ -6,14 +6,14 @@ ** |/ ** \* */ -// $Id: $ +// $Id$ package scala.collection.mutable import scala.collection.generic._ -/** A subtrait of collection.Vector which represents sequences +/** A subtrait of <code>collection.Vector</code> which represents sequences * that can be mutated. */ trait Vector[A] extends Sequence[A] diff --git a/src/library/scala/collection/script/Message.scala b/src/library/scala/collection/script/Message.scala index 6c370a7e66..d12cb418a5 100644 --- a/src/library/scala/collection/script/Message.scala +++ b/src/library/scala/collection/script/Message.scala @@ -1,7 +1,7 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** ** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ diff --git a/src/library/scala/collection/script/Scriptable.scala b/src/library/scala/collection/script/Scriptable.scala index d77a0a09c1..86a804502d 100644 --- a/src/library/scala/collection/script/Scriptable.scala +++ b/src/library/scala/collection/script/Scriptable.scala @@ -1,7 +1,7 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** ** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://www.scala-lang.org/ ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ diff --git a/src/library/scala/concurrent/AsyncInvokable.scala b/src/library/scala/concurrent/AsyncInvokable.scala index ae84042689..be831bfdf5 100644 --- a/src/library/scala/concurrent/AsyncInvokable.scala +++ b/src/library/scala/concurrent/AsyncInvokable.scala @@ -1,3 +1,14 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + + package scala.concurrent /** The <code>AsyncInvokable</code> trait... diff --git a/src/library/scala/concurrent/Channel.scala b/src/library/scala/concurrent/Channel.scala index 47c99248b0..1218b48763 100644 --- a/src/library/scala/concurrent/Channel.scala +++ b/src/library/scala/concurrent/Channel.scala @@ -1,7 +1,7 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** ** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ @@ -16,28 +16,28 @@ package scala.concurrent * @author Martin Odersky * @version 1.0, 10/03/2003 */ -class Channel[a] { - class LinkedList[a] { - var elem: a = _ - var next: LinkedList[a] = null +class Channel[A] { + class LinkedList[A] { + var elem: A = _ + var next: LinkedList[A] = null } - private var written = new LinkedList[a] // FIFO buffer, realized through + private var written = new LinkedList[A] // FIFO buffer, realized through private var lastWritten = written // aliasing of a linked list private var nreaders = 0 /** * @param x ... */ - def write(x: a) = synchronized { + def write(x: A) = synchronized { lastWritten.elem = x - lastWritten.next = new LinkedList[a] + lastWritten.next = new LinkedList[A] lastWritten = lastWritten.next if (nreaders > 0) notify() } - def read: a = synchronized { + def read: A = synchronized { while (null == written.next) { - nreaders = nreaders + 1; wait(); nreaders = nreaders - 1 + nreaders += 1; wait(); nreaders -= 1 } val x = written.elem written = written.next diff --git a/src/library/scala/concurrent/DelayedLazyVal.scala b/src/library/scala/concurrent/DelayedLazyVal.scala index 63477b4b3c..a5d8219a02 100644 --- a/src/library/scala/concurrent/DelayedLazyVal.scala +++ b/src/library/scala/concurrent/DelayedLazyVal.scala @@ -1,7 +1,7 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** ** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ diff --git a/src/library/scala/concurrent/JavaConversions.scala b/src/library/scala/concurrent/JavaConversions.scala index 7810cee669..e91b777b9a 100644 --- a/src/library/scala/concurrent/JavaConversions.scala +++ b/src/library/scala/concurrent/JavaConversions.scala @@ -1,3 +1,14 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + + package scala.concurrent import java.util.concurrent.{ExecutorService, Executor} diff --git a/src/library/scala/concurrent/Lock.scala b/src/library/scala/concurrent/Lock.scala index 56d97f54b6..63c736ab5e 100644 --- a/src/library/scala/concurrent/Lock.scala +++ b/src/library/scala/concurrent/Lock.scala @@ -1,7 +1,7 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** ** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ diff --git a/src/library/scala/concurrent/ManagedBlocker.scala b/src/library/scala/concurrent/ManagedBlocker.scala index c77f97285e..3715e8a159 100644 --- a/src/library/scala/concurrent/ManagedBlocker.scala +++ b/src/library/scala/concurrent/ManagedBlocker.scala @@ -1,3 +1,14 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + + package scala.concurrent /** The <code>ManagedBlocker</code> trait... diff --git a/src/library/scala/concurrent/SyncChannel.scala b/src/library/scala/concurrent/SyncChannel.scala index e28ff477a3..ba03680e61 100644 --- a/src/library/scala/concurrent/SyncChannel.scala +++ b/src/library/scala/concurrent/SyncChannel.scala @@ -1,7 +1,7 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** ** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ diff --git a/src/library/scala/concurrent/TIMEOUT.scala b/src/library/scala/concurrent/TIMEOUT.scala index df9edcbbe5..74c16792ae 100644 --- a/src/library/scala/concurrent/TIMEOUT.scala +++ b/src/library/scala/concurrent/TIMEOUT.scala @@ -1,7 +1,7 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** ** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ diff --git a/src/library/scala/concurrent/TaskRunner.scala b/src/library/scala/concurrent/TaskRunner.scala index e9b7c6916b..58ccc7a386 100644 --- a/src/library/scala/concurrent/TaskRunner.scala +++ b/src/library/scala/concurrent/TaskRunner.scala @@ -1,3 +1,14 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + + package scala.concurrent /** The <code>TaskRunner</code> trait... diff --git a/src/library/scala/concurrent/TaskRunners.scala b/src/library/scala/concurrent/TaskRunners.scala index cc5c1a5131..aa8afa0fd1 100644 --- a/src/library/scala/concurrent/TaskRunners.scala +++ b/src/library/scala/concurrent/TaskRunners.scala @@ -1,3 +1,14 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + + package scala.concurrent import java.util.concurrent.{ThreadPoolExecutor, LinkedBlockingQueue, TimeUnit} diff --git a/src/library/scala/concurrent/ThreadPoolRunner.scala b/src/library/scala/concurrent/ThreadPoolRunner.scala index e532d2bfff..9dd89afc02 100644 --- a/src/library/scala/concurrent/ThreadPoolRunner.scala +++ b/src/library/scala/concurrent/ThreadPoolRunner.scala @@ -1,3 +1,14 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + + package scala.concurrent import java.util.concurrent.{ExecutorService, Callable, TimeUnit} @@ -31,8 +42,9 @@ trait ThreadPoolRunner extends FutureTaskRunner { toRichFuture(executor.submit[S](task)) } - def execute[S](task: Task[S]): Unit = + def execute[S](task: Task[S]) { executor execute task + } def managedBlock(blocker: ManagedBlocker) { blocker.block() diff --git a/src/library/scala/concurrent/ThreadRunner.scala b/src/library/scala/concurrent/ThreadRunner.scala index 16269fa65f..f6661fdc83 100644 --- a/src/library/scala/concurrent/ThreadRunner.scala +++ b/src/library/scala/concurrent/ThreadRunner.scala @@ -1,3 +1,14 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + + package scala.concurrent import java.lang.Thread diff --git a/src/library/scala/package.scala b/src/library/scala/package.scala index 7bec5ae8ac..c894e1e9ad 100644 --- a/src/library/scala/package.scala +++ b/src/library/scala/package.scala @@ -1,3 +1,14 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + + package object scala { type Iterable[+A] = scala.collection.Iterable[A] val Iterable = scala.collection.Iterable diff --git a/src/library/scala/reflect/Manifest.scala b/src/library/scala/reflect/Manifest.scala index 91d5f4ffc0..bf1ff5cfaf 100644 --- a/src/library/scala/reflect/Manifest.scala +++ b/src/library/scala/reflect/Manifest.scala @@ -136,29 +136,32 @@ object Manifest { override lazy val toString = value.toString + ".type" } - /** Manifest for the class type `clazz[args]', where `clazz' is - * a top-level or static class. - * @note This no-prefix, no-arguments case is separate because we - * it's called from ScalaRunTime.boxArray itself. If we - * pass varargs as arrays into this, we get an infinitely recursive call - * to boxArray. (Besides, having a separate case is more efficient) - */ + /** Manifest for the class type <code>clazz[args]</code>, where <code>clazz</code> + * is a top-level or static class. + * @note This no-prefix, no-arguments case is separate because we + * it's called from ScalaRunTime.boxArray itself. If we + * pass varargs as arrays into this, we get an infinitely recursive call + * to boxArray. (Besides, having a separate case is more efficient) + */ def classType[T](clazz: Predef.Class[_]): Manifest[T] = new ClassTypeManifest[T](None, clazz, Nil) - /** Manifest for the class type `clazz', where `clazz' is - * a top-level or static class and args are its type arguments. */ + /** Manifest for the class type <code>clazz</code>, where <code>clazz</code> + * is a top-level or static class and <code>args</code> are its type arguments. + */ def classType[T](clazz: Predef.Class[T], arg1: Manifest[_], args: Manifest[_]*): Manifest[T] = new ClassTypeManifest[T](None, clazz, arg1 :: args.toList) - /** Manifest for the class type `clazz[args]', where `clazz' is - * a class with non-package prefix type `prefix` and type arguments `args`. - */ + /** Manifest for the class type <code>clazz[args]</code>, where <code>clazz</code> + * is a class with non-package prefix type <code>prefix</code> and type + * arguments <code>args</code>. + */ def classType[T](prefix: Manifest[_], clazz: Predef.Class[_], args: Manifest[_]*): Manifest[T] = new ClassTypeManifest[T](Some(prefix), clazz, args.toList) - /** Manifest for the class type `clazz[args]', where `clazz' is - * a top-level or static class. */ + /** Manifest for the class type <code>clazz[args]</code>, where `clazz' is + * a top-level or static class. + */ @serializable private class ClassTypeManifest[T](prefix: Option[Manifest[_]], val erasure: Predef.Class[_], @@ -169,9 +172,11 @@ object Manifest { argString } - /** Manifest for the abstract type `prefix # name'. `upperBound' is not - * strictly necessary as it could be obtained by reflection. It was - * added so that erasure can be calculated without reflection. */ + /** Manifest for the abstract type <code>prefix # name</code>. + * <code>upperBound</code> is not strictly necessary as it could be obtained + * by reflection. It was added so that erasure can be calculated without + * reflection. + */ def abstractType[T](prefix: Manifest[_], name: String, upperBound: Manifest[_], args: Manifest[_]*): Manifest[T] = new (Manifest[T] @serializable) { def erasure = upperBound.erasure diff --git a/src/library/scala/serializable.scala b/src/library/scala/serializable.scala index d45c6f402f..2fbec64ef5 100644 --- a/src/library/scala/serializable.scala +++ b/src/library/scala/serializable.scala @@ -1,7 +1,7 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** ** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ diff --git a/src/library/scala/specialized.scala b/src/library/scala/specialized.scala index 8701d16e6b..e082c2cdfa 100644 --- a/src/library/scala/specialized.scala +++ b/src/library/scala/specialized.scala @@ -1,3 +1,14 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + + package scala /** Annotate type parameters on which code should be automatically diff --git a/test/files/run/sequenceComparisons.scala b/test/files/run/sequenceComparisons.scala index 340a4fa55f..cc1cf3610c 100644 --- a/test/files/run/sequenceComparisons.scala +++ b/test/files/run/sequenceComparisons.scala @@ -113,9 +113,9 @@ object Test { } } - def main(args: Array[String]): Unit = { + def main(args: Array[String]) { runSeqs() assert(failures.isEmpty, failures mkString "\n") } -}
\ No newline at end of file +} diff --git a/test/pending/jvm/serialization.check b/test/pending/jvm/serialization.check index 144e31603f..397578bcba 100644 --- a/test/pending/jvm/serialization.check +++ b/test/pending/jvm/serialization.check @@ -1,10 +1,15 @@ +x0 = List(1, 2, 3) +y0 = List(1, 2, 3) +x0 eq y0: false, y0 eq x0: false +x0 equals y0: true, y0 equals x0: true + x1 = List() y1 = List() -x1 eq y1: true - y1 eq x1: true +x1 eq y1: true, y1 eq x1: true x2 = None y2 = None -x2 eq y2: true - y2 eq x2: true +x2 eq y2: true, y2 eq x2: true x3 = Array[1,2,3] y3 = Array[1,2,3] @@ -14,73 +19,120 @@ x4 = <na> y4 = <na> x4(2): 4 - y4(2): 4 +x5 = 'hello +y5 = 'hello +x5 eq y5: true, y5 eq x5: true +x5 equals y5: true, y5 equals x5: true + +x6 = (BannerLimit,12345) +y6 = (BannerLimit,12345) +x6 eq y6: false, y6 eq x6: false +x6 equals y6: true, y6 equals x6: true + +x7 = RoundingMode +y7 = RoundingMode +x7 eq y7: true, y7 eq x7: true +x7 equals y7: true, y7 equals x7: true + +x8 = WeekDay +y8 = WeekDay +x8 eq y8: true, y8 eq x8: true +x8 equals y8: true, y8 equals x8: true + +x9 = UP +y9 = UP +x9 eq y9: true, y9 eq x9: true +x9 equals y9: true, y9 equals x9: true + +x10 = WeekDay(0) +y10 = WeekDay(0) +x10 eq y10: true, y10 eq x10: true +x10 equals y10: true, y10 equals x10: true + +x9 eq x10: false, x10 eq x9: false +x9 equals x10: false, x10 equals x9: false +x9 eq y10: false, y10 eq x9: false +x9 equals y10: false, y10 equals x9: false + x = List((buffers,20), (layers,2), (title,3)) y = List((buffers,20), (layers,2), (title,3)) -x equals y: true - y equals x: true +x equals y: true, y equals x: true + +x = Map(2 -> C, 1 -> B, 0 -> A) +y = Map(2 -> C, 1 -> B, 0 -> A) +x equals y: true, y equals x: true x = Map(buffers -> 20, layers -> 2, title -> 3) y = Map(buffers -> 20, layers -> 2, title -> 3) -x equals y: true - y equals x: true +x equals y: true, y equals x: true x = Set(2, 3) y = Set(2, 3) -x equals y: true - y equals x: true +x equals y: true, y equals x: true x = Set(5, 3) y = Set(5, 3) -x equals y: true - y equals x: true +x equals y: true, y equals x: true -x = Queue(a,b,c) -y = Queue(a,b,c) -x equals y: true - y equals x: true +x = Queue(a, b, c) +y = Queue(a, b, c) +x equals y: true, y equals x: true -x = Stack(c, b, a) -y = Stack(c, b, a) -x equals y: true - y equals x: true +x = Stack(a, b, c) +y = Stack(a, b, c) +x equals y: true, y equals x: true x = Map(42 -> FortyTwo) y = Map(42 -> FortyTwo) -x equals y: true - y equals x: true +x equals y: true, y equals x: true -x = Set(0, 2) -y = Set(0, 2) -x equals y: true - y equals x: true +x = TreeSet(0, 2) +y = TreeSet(0, 2) +x equals y: true, y equals x: true + +x = Vector(1, 2, 3) +y = Vector(1, 2, 3) +x equals y: true, y equals x: true x = ArrayBuffer(one, two) y = ArrayBuffer(one, two) -x equals y: true - y equals x: true +x equals y: true, y equals x: true x = Map(title -> 3, buffers -> 20, layers -> 2) y = Map(title -> 3, buffers -> 20, layers -> 2) -x equals y: true - y equals x: true +x equals y: true, y equals x: true x = Set(0, 8, 9) y = Set(0, 8, 9) -x equals y: true - y equals x: true +x equals y: true, y equals x: true x = Set(layers, buffers, title) y = Set(layers, buffers, title) -x equals y: true - y equals x: true +x equals y: true, y equals x: true x = LinkedList(2, 3) y = LinkedList(2, 3) -x equals y: true - y equals x: true +x equals y: true, y equals x: true x = Queue(20, 2, 3) y = Queue(20, 2, 3) -x equals y: true - y equals x: true +x equals y: true, y equals x: true -x = Stack(20, 2, 3) -y = Stack(20, 2, 3) -x equals y: true - y equals x: true +x = Stack(3, 2, 20) +y = Stack(3, 2, 20) +x equals y: true, y equals x: true x = ListBuffer(white, black) y = ListBuffer(white, black) -x equals y: true - y equals x: true +x equals y: true, y equals x: true + +x = History((Feed,hello)) +y = History((Feed,hello)) +x equals y: true, y equals x: true x = <html><title>title</title><body></body></html> y = <html><title>title</title><body></body></html> -x equals y: true - y equals x: true +x equals y: true, y equals x: true x = <html> <body> @@ -122,25 +174,25 @@ y = <html> </table> </body> </html> -x equals y: true - y equals x: true +x equals y: true, y equals x: true x = Tim y = Tim -x equals y: true - y equals x: true +x equals y: true, y equals x: true x = Bob y = Bob -x equals y: true - y equals x: true +x equals y: true, y equals x: true x = John y = John -x equals y: true - y equals x: true +x equals y: true, y equals x: true x = Bill y = Bill -x equals y: true - y equals x: true +x equals y: true, y equals x: true x = Paul y = Paul -x equals y: true - y equals x: true +x equals y: true, y equals x: true diff --git a/test/pending/jvm/serialization.scala b/test/pending/jvm/serialization.scala index 2c46ee0b7b..d2c2cc5e7d 100644 --- a/test/pending/jvm/serialization.scala +++ b/test/pending/jvm/serialization.scala @@ -5,15 +5,6 @@ import java.lang.System -object EqualityTest { - def check[A, B](x: A, y: B) { - println("x = " + x) - println("y = " + y) - println("x equals y: " + (x equals y) + " - y equals x: " + (y equals x)) - println() - } -} - object Serialize { @throws(classOf[java.io.IOException]) def write[A](o: A): Array[Byte] = { @@ -30,48 +21,115 @@ object Serialize { new java.io.ObjectInputStream(new java.io.ByteArrayInputStream(buffer)) in.readObject().asInstanceOf[A] } + def check[A, B](x: A, y: B) { + println("x = " + x) + println("y = " + y) + println("x equals y: " + (x equals y) + ", y equals x: " + (y equals x)) + println() + } } +import Serialize._ //############################################################################ // Test classes in package "scala" -@serializable object Test1_scala { private def arrayToString[A](arr: Array[A]): String = arr.mkString("Array[",",","]") - private def arrayEquals[A, B](a1: Array[A], a2: Array[B]) = - (a1.length == a2.length) && - (Iterator.range(0, a1.length) forall { i => a1(i) == a2(i) }) + private def arrayEquals[A, B](a1: Array[A], a2: Array[B]): Boolean = + (a1.length == a2.length) && + (Iterator.range(0, a1.length) forall { i => a1(i) == a2(i) }) + + @serializable + object WeekDay extends Enumeration { + type WeekDay = Value + val Monday, Tuesday, Wednesday, Thusday, Friday, Saturday, Sunday = Value + } + import WeekDay._, BigDecimal._, RoundingMode._ + val x0 = List(1, 2, 3) val x1 = Nil val x2 = None val x3 = Array(1, 2, 3) val x4 = { x: Int => 2 * x } + val x5 = 'hello + val x6 = ("BannerLimit", 12345) + val x7 = BigDecimal.RoundingMode + val x8 = WeekDay + val x9 = UP // named element + val x10 = Monday // unamed element try { - val y1: List[Nothing] = Serialize.read(Serialize.write(x1)) - val y2: Option[Nothing] = Serialize.read(Serialize.write(x2)) - val y3: Array[Int] = Serialize.read(Serialize.write(x3)) - val y4: Function[Int, Int] = Serialize.read(Serialize.write(x4)) - + val y0: List[Int] = read(write(x0)) + val y1: List[Nothing] = read(write(x1)) + val y2: Option[Nothing] = read(write(x2)) + val y3: Array[Int] = read(write(x3)) + val y4: Function[Int, Int] = read(write(x4)) + val y5: Symbol = read(write(x5)) + val y6: (String, Int) = read(write(x6)) + val y7: RoundingMode.type = read(write(x7)) + val y8: WeekDay.type = read(write(x8)) + val y9: RoundingMode = read(write(x9)) + val y10: WeekDay = read(write(x10)) + + println("x0 = " + x0) + println("y0 = " + y0) + println("x0 eq y0: " + (x0 eq y0) + ", y0 eq x0: " + (y0 eq x0)) + println("x0 equals y0: " + (x0 equals y0) + ", y0 equals x0: " + (y0 equals x0)) + println() println("x1 = " + x1) println("y1 = " + y1) - println("x1 eq y1: " + (x1 eq y1) + " - y1 eq x1: " + (y1 eq x1)) - println + println("x1 eq y1: " + (x1 eq y1) + ", y1 eq x1: " + (y1 eq x1)) + println() println("x2 = " + x2) println("y2 = " + y2) - println("x2 eq y2: " + (x2 eq y2) + " - y2 eq x2: " + (y2 eq x2)) - println + println("x2 eq y2: " + (x2 eq y2) + ", y2 eq x2: " + (y2 eq x2)) + println() println("x3 = " + arrayToString(x3)) println("y3 = " + arrayToString(y3)) println("arrayEquals(x3, y3): " + arrayEquals(x3, y3)) - println + println() println("x4 = <na>") println("y4 = <na>") println("x4(2): " + x4(2) + " - y4(2): " + y4(2)) - println + println() + println("x5 = " + x5) + println("y5 = " + y5) + println("x5 eq y5: " + (x5 eq y5) + ", y5 eq x5: " + (y5 eq x5)) + println("x5 equals y5: " + (x5 equals y5) + ", y5 equals x5: " + (y5 equals x5)) + println() + println("x6 = " + x6) + println("y6 = " + y6) + println("x6 eq y6: " + (x6 eq y6) + ", y6 eq x6: " + (y6 eq x6)) + println("x6 equals y6: " + (x6 equals y6) + ", y6 equals x6: " + (y6 equals x6)) + println() + println("x7 = " + x7) + println("y7 = " + y7) + println("x7 eq y7: " + (x7 eq y7) + ", y7 eq x7: " + (y7 eq x7)) + println("x7 equals y7: " + (x7 equals y7) + ", y7 equals x7: " + (y7 equals x7)) + println() + println("x8 = " + x8) + println("y8 = " + y8) + println("x8 eq y8: " + (x8 eq y8) + ", y8 eq x8: " + (y8 eq x8)) + println("x8 equals y8: " + (x8 equals y8) + ", y8 equals x8: " + (y8 equals x8)) + println() + println("x9 = " + x9) + println("y9 = " + y9) + println("x9 eq y9: " + (x9 eq y9) + ", y9 eq x9: " + (y9 eq x9)) + println("x9 equals y9: " + (x9 equals y9) + ", y9 equals x9: " + (y9 equals x9)) + println() + println("x10 = " + x10) + println("y10 = " + y10) + println("x10 eq y10: " + (x10 eq y10) + ", y10 eq x10: " + (y10 eq x10)) + println("x10 equals y10: " + (x10 equals y10) + ", y10 equals x10: " + (y10 equals x10)) + println() + println("x9 eq x10: " + (x9 eq x10) + ", x10 eq x9: " + (x10 eq x9)) + println("x9 equals x10: " + (x9 equals x10) + ", x10 equals x9: " + (x10 equals x9)) + println("x9 eq y10: " + (x9 eq y10) + ", y10 eq x9: " + (y10 eq x9)) + println("x9 equals y10: " + (x9 equals y10) + ", y10 equals x9: " + (y10 equals x9)) + println() } catch { case e: Exception => @@ -86,18 +144,17 @@ object Test1_scala { @serializable object Test2_immutable { import scala.collection.immutable.{ - BitSet, ListMap, ListSet, Queue, Stack, TreeSet, TreeMap} + BitSet, HashMap, ListMap, ListSet, Queue, Stack, TreeSet, TreeMap, Vector} val x1 = List( - Pair("buffers", 20), - Pair("layers", 2), - Pair("title", 3) + ("buffers", 20), + ("layers", 2), + ("title", 3) ) - val x2 = new ListMap[String, Int] - .incl(Pair("buffers", 20)) - .incl(Pair("layers", 2)) - .incl(Pair("title", 3)) + val m1 = new HashMap[Int, String] + (0 -> "A", 1 -> "B", 2 -> "C") + + val x2 = new ListMap[String, Int] + ("buffers" -> 20, "layers" -> 2, "title" -> 3) val x3 = { val bs = new collection.mutable.BitSet() @@ -105,34 +162,40 @@ object Test2_immutable { bs.toImmutable } - val x4 = new ListSet[Int]().incl(3).incl(5) + val x4 = new ListSet[Int]() + 3 + 5 + + val x5 = Queue("a", "b", "c") - val x5 = new Queue("a", "b", "c") + val x6 = Stack("a", "b", "c") - val x6 = new Stack().push("a", "b", "c") + val x7 = new TreeMap[Int, String] + (42 -> "FortyTwo") - val x7 = new TreeMap[Int, String] + 42 -> "FortyTwo" + val x8 = new TreeSet[Int]() + 2 + 0 - val x8 = new TreeSet[Int]().incl(2).incl(0) + val x9 = Vector(1, 2, 3) try { - val y1: List[Pair[String, Int]] = Serialize.read(Serialize.write(x1)) - val y2: ListMap[String, Int] = Serialize.read(Serialize.write(x2)) - val y3: BitSet = Serialize.read(Serialize.write(x3)) - val y4: ListSet[Int] = Serialize.read(Serialize.write(x4)) - val y5: Queue[String] = Serialize.read(Serialize.write(x5)) - val y6: Stack[String] = Serialize.read(Serialize.write(x6)) - val y7: TreeMap[Int, String] = Serialize.read(Serialize.write(x7)) - val y8: TreeSet[Int] = Serialize.read(Serialize.write(x8)) - - EqualityTest.check(x1, y1) - EqualityTest.check(x2, y2) - EqualityTest.check(x3, y3) - EqualityTest.check(x4, y4) - EqualityTest.check(x5, y5) - EqualityTest.check(x6, y6) - EqualityTest.check(x7, y7) - EqualityTest.check(x8, y8) + val y1: List[Pair[String, Int]] = read(write(x1)) + val n1: HashMap[Int, String] = read(write(m1)) + val y2: ListMap[String, Int] = read(write(x2)) + val y3: BitSet = read(write(x3)) + val y4: ListSet[Int] = read(write(x4)) + val y5: Queue[String] = read(write(x5)) + val y6: Stack[String] = read(write(x6)) + val y7: TreeMap[Int, String] = read(write(x7)) + val y8: TreeSet[Int] = read(write(x8)) + val y9: Vector[Int] = read(write(x9)) + + check(x1, y1) + check(m1, n1) + check(x2, y2) + check(x3, y3) + check(x4, y4) + check(x5, y5) + check(x6, y6) + check(x7, y7) + check(x8, y8) + check(x9, y9) } catch { case e: Exception => @@ -163,43 +226,47 @@ object Test3_mutable { val x3 = new HashSet[String] x3 ++= Test2_immutable.x1.map(p => p._1) - @serializable - class Feed extends Publisher[String, Feed] - - val x8 = new History[String, Feed] - val x4 = new LinkedList[Int](2, null) x4.append(new LinkedList(3, null)) - val x7 = new ListBuffer[String] - x7 ++= List("white", "black") - val x5 = new Queue[Int] x5 ++= Test2_immutable.x1.map(p => p._2) val x6 = new Stack[Int] - x6 ++= x5 + x6 pushAll x5 + + val x7 = new ListBuffer[String] + x7 ++= List("white", "black") + + @serializable + class Feed extends Publisher[String, Feed] { + override def toString() = "Feed" + } + val feed = new Feed + + val x8 = new History[String, Feed] + x8.notify(feed, "hello") try { - val y0: ArrayBuffer[String] = Serialize.read(Serialize.write(x0)) - val y1: HashMap[String, Int] = Serialize.read(Serialize.write(x1)) - val y2: BitSet = Serialize.read(Serialize.write(x2)) - val y3: HashSet[String] = Serialize.read(Serialize.write(x3)) - val y4: LinkedList[Int] = Serialize.read(Serialize.write(x4)) - val y5: Queue[Int] = Serialize.read(Serialize.write(x5)) - val y6: Stack[Int] = Serialize.read(Serialize.write(x6)) - val y7: ListBuffer[String] = Serialize.read(Serialize.write(x7)) - val y8: History[String, Feed] = Serialize.read(Serialize.write(x8)) - - EqualityTest.check(x0, y0) - EqualityTest.check(x1, y1) - EqualityTest.check(x2, y2) - EqualityTest.check(x3, y3) - EqualityTest.check(x4, y4) - EqualityTest.check(x5, y5) - EqualityTest.check(x6, y6) - EqualityTest.check(x7, y7) - //EqualityTest.check(x8, y8) //todo + val y0: ArrayBuffer[String] = read(write(x0)) + val y1: HashMap[String, Int] = read(write(x1)) + val y2: BitSet = read(write(x2)) + val y3: HashSet[String] = read(write(x3)) + val y4: LinkedList[Int] = read(write(x4)) + val y5: Queue[Int] = read(write(x5)) + val y6: Stack[Int] = read(write(x6)) + val y7: ListBuffer[String] = read(write(x7)) + val y8: History[String, Feed] = read(write(x8)) + + check(x0, y0) + check(x1, y1) + check(x2, y2) + check(x3, y3) + check(x4, y4) + check(x5, y5) + check(x6, y6) + check(x7, y7) + check(x8, y8) } catch { case e: Exception => @@ -246,11 +313,11 @@ object Test4_xml { </html>; try { - val y1: scala.xml.Elem = Serialize.read(Serialize.write(x1)) - val y2: scala.xml.Elem = Serialize.read(Serialize.write(x2)) + val y1: scala.xml.Elem = read(write(x1)) + val y2: scala.xml.Elem = read(write(x2)) - EqualityTest.check(x1, y1) - EqualityTest.check(x2, y2) + check(x1, y1) + check(x2, y2) } catch { case e: Exception => @@ -283,11 +350,11 @@ object Test5 { val x2 = bob try { - val y1: Person = Serialize.read(Serialize.write(x1)) - val y2: Employee = Serialize.read(Serialize.write(x2)) + val y1: Person = read(write(x1)) + val y2: Employee = read(write(x2)) - EqualityTest.check(x1, y1) - EqualityTest.check(x2, y2) + check(x1, y1) + check(x2, y2) } catch { case e: Exception => @@ -313,13 +380,13 @@ object Test6 { val x3 = paul try { - val y1: Person = Serialize.read(Serialize.write(x1)) - val y2: Employee = Serialize.read(Serialize.write(x2)) - val y3: Person = Serialize.read(Serialize.write(x3)) + val y1: Person = read(write(x1)) + val y2: Employee = read(write(x2)) + val y3: Person = read(write(x3)) - EqualityTest.check(x1, y1) - EqualityTest.check(x2, y2) - EqualityTest.check(x3, y3) + check(x1, y1) + check(x2, y2) + check(x3, y3) } catch { case e: Exception => |