summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
Diffstat (limited to 'src/library')
-rw-r--r--src/library/rootdoc.txt4
-rw-r--r--src/library/scala/Array.scala2
-rw-r--r--src/library/scala/DelayedInit.scala32
-rw-r--r--src/library/scala/Dynamic.scala23
-rw-r--r--src/library/scala/Function0.scala2
-rw-r--r--src/library/scala/Option.scala2
-rw-r--r--src/library/scala/Predef.scala84
-rw-r--r--src/library/scala/Tuple2.scala105
-rw-r--r--src/library/scala/Tuple3.scala120
-rw-r--r--src/library/scala/collection/BitSet.scala2
-rw-r--r--src/library/scala/collection/BitSetLike.scala2
-rw-r--r--src/library/scala/collection/GenIterableLike.scala5
-rw-r--r--src/library/scala/collection/GenMapLike.scala2
-rw-r--r--src/library/scala/collection/GenTraversableLike.scala45
-rw-r--r--src/library/scala/collection/GenTraversableOnce.scala2
-rw-r--r--src/library/scala/collection/IndexedSeq.scala2
-rw-r--r--src/library/scala/collection/IndexedSeqLike.scala2
-rw-r--r--src/library/scala/collection/Iterable.scala2
-rw-r--r--src/library/scala/collection/Iterator.scala27
-rw-r--r--src/library/scala/collection/LinearSeq.scala2
-rw-r--r--src/library/scala/collection/Map.scala4
-rw-r--r--src/library/scala/collection/MapLike.scala4
-rw-r--r--src/library/scala/collection/Seq.scala2
-rw-r--r--src/library/scala/collection/SeqLike.scala14
-rw-r--r--src/library/scala/collection/Set.scala2
-rw-r--r--src/library/scala/collection/TraversableLike.scala2
-rw-r--r--src/library/scala/collection/TraversableOnce.scala38
-rw-r--r--src/library/scala/collection/TraversableViewLike.scala18
-rw-r--r--src/library/scala/collection/concurrent/Map.scala2
-rw-r--r--src/library/scala/collection/generic/ArrayTagTraversableFactory.scala2
-rw-r--r--src/library/scala/collection/generic/BitSetFactory.scala2
-rw-r--r--src/library/scala/collection/generic/Clearable.scala26
-rw-r--r--src/library/scala/collection/generic/GenMapFactory.scala2
-rw-r--r--src/library/scala/collection/generic/GenSetFactory.scala2
-rw-r--r--src/library/scala/collection/generic/GenTraversableFactory.scala2
-rw-r--r--src/library/scala/collection/generic/GenericCompanion.scala2
-rw-r--r--src/library/scala/collection/generic/GenericParCompanion.scala2
-rw-r--r--src/library/scala/collection/generic/Growable.scala6
-rw-r--r--src/library/scala/collection/generic/ImmutableSortedMapFactory.scala2
-rw-r--r--src/library/scala/collection/generic/ImmutableSortedSetFactory.scala4
-rw-r--r--src/library/scala/collection/generic/MutableSortedSetFactory.scala4
-rw-r--r--src/library/scala/collection/generic/ParFactory.scala2
-rw-r--r--src/library/scala/collection/generic/ParMapFactory.scala2
-rw-r--r--src/library/scala/collection/generic/Shrinkable.scala2
-rw-r--r--src/library/scala/collection/immutable/BitSet.scala4
-rw-r--r--src/library/scala/collection/immutable/GenSeq.scala.disabled2
-rw-r--r--src/library/scala/collection/immutable/GenSet.scala.disabled2
-rw-r--r--src/library/scala/collection/immutable/HashMap.scala4
-rw-r--r--src/library/scala/collection/immutable/HashSet.scala6
-rw-r--r--src/library/scala/collection/immutable/IndexedSeq.scala2
-rw-r--r--src/library/scala/collection/immutable/IntMap.scala4
-rw-r--r--src/library/scala/collection/immutable/Iterable.scala4
-rw-r--r--src/library/scala/collection/immutable/LinearSeq.scala2
-rw-r--r--src/library/scala/collection/immutable/List.scala4
-rw-r--r--src/library/scala/collection/immutable/LongMap.scala4
-rw-r--r--src/library/scala/collection/immutable/Map.scala2
-rw-r--r--src/library/scala/collection/immutable/NumericRange.scala2
-rw-r--r--src/library/scala/collection/immutable/PagedSeq.scala2
-rw-r--r--src/library/scala/collection/immutable/Queue.scala4
-rw-r--r--src/library/scala/collection/immutable/Seq.scala4
-rw-r--r--src/library/scala/collection/immutable/Set.scala4
-rw-r--r--src/library/scala/collection/immutable/SortedSet.scala4
-rw-r--r--src/library/scala/collection/immutable/Stack.scala4
-rw-r--r--src/library/scala/collection/immutable/Stream.scala8
-rw-r--r--src/library/scala/collection/immutable/StringLike.scala2
-rw-r--r--src/library/scala/collection/immutable/StringOps.scala2
-rw-r--r--src/library/scala/collection/immutable/Traversable.scala2
-rw-r--r--src/library/scala/collection/immutable/TreeSet.scala4
-rw-r--r--src/library/scala/collection/immutable/Vector.scala2
-rw-r--r--src/library/scala/collection/immutable/WrappedString.scala2
-rw-r--r--src/library/scala/collection/mutable/ArrayBuffer.scala4
-rw-r--r--src/library/scala/collection/mutable/ArrayLike.scala2
-rw-r--r--src/library/scala/collection/mutable/ArrayOps.scala2
-rw-r--r--src/library/scala/collection/mutable/ArraySeq.scala4
-rw-r--r--src/library/scala/collection/mutable/ArrayStack.scala4
-rw-r--r--src/library/scala/collection/mutable/BitSet.scala4
-rw-r--r--src/library/scala/collection/mutable/Buffer.scala4
-rw-r--r--src/library/scala/collection/mutable/BufferProxy.scala2
-rw-r--r--src/library/scala/collection/mutable/Builder.scala2
-rw-r--r--src/library/scala/collection/mutable/ConcurrentMap.scala2
-rw-r--r--src/library/scala/collection/mutable/DoubleLinkedList.scala4
-rw-r--r--src/library/scala/collection/mutable/DoubleLinkedListLike.scala2
-rw-r--r--src/library/scala/collection/mutable/GenSeq.scala.disabled2
-rw-r--r--src/library/scala/collection/mutable/GenSet.scala.disabled2
-rw-r--r--src/library/scala/collection/mutable/GrowingBuilder.scala2
-rw-r--r--src/library/scala/collection/mutable/HashMap.scala4
-rw-r--r--src/library/scala/collection/mutable/HashSet.scala4
-rw-r--r--src/library/scala/collection/mutable/HashTable.scala2
-rw-r--r--src/library/scala/collection/mutable/IndexedSeq.scala2
-rw-r--r--src/library/scala/collection/mutable/IndexedSeqLike.scala2
-rw-r--r--src/library/scala/collection/mutable/Iterable.scala2
-rw-r--r--src/library/scala/collection/mutable/LinearSeq.scala4
-rw-r--r--src/library/scala/collection/mutable/LinkedHashMap.scala12
-rw-r--r--src/library/scala/collection/mutable/LinkedHashSet.scala4
-rw-r--r--src/library/scala/collection/mutable/LinkedList.scala4
-rw-r--r--src/library/scala/collection/mutable/LinkedListLike.scala2
-rw-r--r--src/library/scala/collection/mutable/ListBuffer.scala4
-rw-r--r--src/library/scala/collection/mutable/ListMap.scala4
-rw-r--r--src/library/scala/collection/mutable/Map.scala2
-rw-r--r--src/library/scala/collection/mutable/MultiMap.scala2
-rw-r--r--src/library/scala/collection/mutable/OpenHashMap.scala4
-rw-r--r--src/library/scala/collection/mutable/Queue.scala2
-rw-r--r--src/library/scala/collection/mutable/Seq.scala4
-rw-r--r--src/library/scala/collection/mutable/Set.scala4
-rw-r--r--src/library/scala/collection/mutable/SortedSet.scala4
-rw-r--r--src/library/scala/collection/mutable/Stack.scala4
-rw-r--r--src/library/scala/collection/mutable/SynchronizedBuffer.scala2
-rw-r--r--src/library/scala/collection/mutable/SynchronizedMap.scala2
-rw-r--r--src/library/scala/collection/mutable/SynchronizedPriorityQueue.scala2
-rw-r--r--src/library/scala/collection/mutable/SynchronizedQueue.scala2
-rw-r--r--src/library/scala/collection/mutable/SynchronizedSet.scala2
-rw-r--r--src/library/scala/collection/mutable/SynchronizedStack.scala2
-rw-r--r--src/library/scala/collection/mutable/Traversable.scala2
-rw-r--r--src/library/scala/collection/mutable/TreeSet.scala2
-rw-r--r--src/library/scala/collection/mutable/UnrolledBuffer.scala2
-rw-r--r--src/library/scala/collection/mutable/WeakHashMap.scala4
-rw-r--r--src/library/scala/collection/mutable/WrappedArray.scala2
-rw-r--r--src/library/scala/collection/parallel/ParIterable.scala2
-rw-r--r--src/library/scala/collection/parallel/ParIterableLike.scala22
-rw-r--r--src/library/scala/collection/parallel/immutable/ParHashMap.scala4
-rw-r--r--src/library/scala/collection/parallel/immutable/ParHashSet.scala4
-rw-r--r--src/library/scala/collection/parallel/immutable/ParNumericRange.scala.disabled2
-rw-r--r--src/library/scala/collection/parallel/immutable/ParRange.scala2
-rw-r--r--src/library/scala/collection/parallel/immutable/ParSeq.scala4
-rw-r--r--src/library/scala/collection/parallel/immutable/ParSet.scala4
-rw-r--r--src/library/scala/collection/parallel/immutable/ParVector.scala4
-rw-r--r--src/library/scala/collection/parallel/mutable/ParArray.scala4
-rw-r--r--src/library/scala/collection/parallel/mutable/ParFlatHashTable.scala2
-rw-r--r--src/library/scala/collection/parallel/mutable/ParHashMap.scala4
-rw-r--r--src/library/scala/collection/parallel/mutable/ParHashSet.scala4
-rw-r--r--src/library/scala/collection/parallel/mutable/ParSeq.scala4
-rw-r--r--src/library/scala/collection/parallel/mutable/ParSet.scala4
-rw-r--r--src/library/scala/concurrent/ConcurrentPackageObject.scala9
-rw-r--r--src/library/scala/concurrent/ExecutionContext.scala11
-rw-r--r--src/library/scala/concurrent/Future.scala98
-rw-r--r--src/library/scala/concurrent/Promise.scala32
-rw-r--r--src/library/scala/concurrent/impl/AbstractPromise.java23
-rw-r--r--src/library/scala/concurrent/impl/ExecutionContextImpl.scala20
-rw-r--r--src/library/scala/concurrent/impl/Future.scala55
-rw-r--r--src/library/scala/concurrent/impl/Promise.scala119
-rw-r--r--src/library/scala/concurrent/package.scala10
-rw-r--r--src/library/scala/concurrent/util/Duration.scala70
-rw-r--r--src/library/scala/concurrent/util/Unsafe.java (renamed from src/library/scala/concurrent/impl/Unsafe.java)17
-rw-r--r--src/library/scala/math/package.scala17
-rw-r--r--src/library/scala/reflect/DummyMirror.scala1
-rw-r--r--src/library/scala/reflect/api/RequiredFile.scala7
-rw-r--r--src/library/scala/reflect/api/StandardNames.scala1
-rw-r--r--src/library/scala/reflect/api/Trees.scala65
-rwxr-xr-xsrc/library/scala/reflect/api/Types.scala14
-rw-r--r--src/library/scala/runtime/ScalaRunTime.scala27
-rw-r--r--src/library/scala/runtime/SeqCharSequence.scala44
-rw-r--r--src/library/scala/runtime/Tuple2Zipped.scala130
-rw-r--r--src/library/scala/runtime/Tuple3Zipped.scala141
-rw-r--r--src/library/scala/util/matching/Regex.scala39
-rw-r--r--src/library/scala/util/parsing/combinator/Parsers.scala25
155 files changed, 1073 insertions, 815 deletions
diff --git a/src/library/rootdoc.txt b/src/library/rootdoc.txt
index 6145429f1e..da27a0084b 100644
--- a/src/library/rootdoc.txt
+++ b/src/library/rootdoc.txt
@@ -22,6 +22,6 @@ Many other packages exist. See the complete list on the left.
Identifiers in the scala package and the [[scala.Predef]] object are always in scope by default.
-Some of these identifiers are type aliases provided as shortcuts to commonly used classes. For example, List is an alias for scala.collection.immutable.[[scala.collection.immutable.List]].
+Some of these identifiers are type aliases provided as shortcuts to commonly used classes. For example, `List` is an alias for scala.collection.immutable.[[scala.collection.immutable.List]].
-Other aliases refer to classes providing by the underlying platform. For example, on the JVM, String is an alias for java.lang.String.
+Other aliases refer to classes provided by the underlying platform. For example, on the JVM, `String` is an alias for `java.lang.String`.
diff --git a/src/library/scala/Array.scala b/src/library/scala/Array.scala
index fd61cfd0a1..36e95b303d 100644
--- a/src/library/scala/Array.scala
+++ b/src/library/scala/Array.scala
@@ -468,7 +468,7 @@ object Array extends FallbackArrayBuilding {
* @see [[http://www.scala-lang.org/docu/files/collections-api/collections_38.html#anchor "The Scala 2.8 Collections' API"]]
* section on `Array` by Martin Odersky for more information.
* @define coll array
- * @define Coll Array
+ * @define Coll `Array`
* @define orderDependent
* @define orderDependentFold
* @define mayNotTerminateInf
diff --git a/src/library/scala/DelayedInit.scala b/src/library/scala/DelayedInit.scala
index e898bca720..52a38ca6f7 100644
--- a/src/library/scala/DelayedInit.scala
+++ b/src/library/scala/DelayedInit.scala
@@ -8,15 +8,41 @@
package scala
-/** Classes and traits inheriting the `DelayedInit` marker trait
- * will have their initialization code rewritten as follows:
+/** Classes and objects (but note, not traits) inheriting the `DelayedInit`
+ * marker trait will have their initialization code rewritten as follows:
* `code` becomes `delayedInit(code)`.
*
* Initialization code comprises all statements and all value definitions
* that are executed during initialization.
*
+ * Example:
+ * {{{
+ * trait Helper extends DelayedInit {
+ * def delayedInit(body: => Unit) = {
+ * println("dummy text, printed before initialization of C")
+ * body // evaluates the initialization code of C
+ * }
+ * }
+ *
+ * class C extends Helper {
+ * println("this is the initialization code of C")
+ * }
+ *
+ * object Test extends App {
+ * val c = new C
+ * }
+ * }}}
+ *
+ * Should result in the following being printed:
+ * {{{
+ * dummy text, printed before initialization of C
+ * this is the initialization code of C
+ * }}}
+ *
+ * @see "Delayed Initialization" subsection of the Scala Language Specification (section 5.1)
+ *
* @author Martin Odersky
*/
trait DelayedInit {
def delayedInit(x: => Unit): Unit
-}
+} \ No newline at end of file
diff --git a/src/library/scala/Dynamic.scala b/src/library/scala/Dynamic.scala
index dcf7599742..faf834d310 100644
--- a/src/library/scala/Dynamic.scala
+++ b/src/library/scala/Dynamic.scala
@@ -9,12 +9,25 @@
package scala
/** A marker trait that enables dynamic invocations. Instances `x` of this
- * trait allow calls `x.meth(args)` for arbitrary method names `meth` and
- * argument lists `args`. If a call is not natively supported by `x`, it
- * is rewritten to `x.applyDynamic("meth")(args)`.
+ * trait allow method invocations `x.meth(args)` for arbitrary method
+ * names `meth` and argument lists `args` as well as field accesses
+ * `x.field` for arbitrary field names `field`.
*
- * As of scala 2.9, `scalac` must receive the `-Xexperimental` option for
- * `Dynamic` to receive this treatment.
+ * If a call is not natively supported by `x` (i.e. if type checking
+ * fails), it is rewritten according to the following rules:
+ *
+ * {{{
+ * foo.method("blah") ~~> foo.applyDynamic("method")("blah")
+ * foo.method(x = "blah") ~~> foo.applyDynamicNamed("method")(("x", "blah"))
+ * foo.method(x = 1, 2) ~~> foo.applyDynamicNamed("method")(("x", 1), ("", 2))
+ * foo.field ~~> foo.selectDynamic("field")
+ * foo.varia = 10 ~~> foo.updateDynamic("varia")(10)
+ * foo.arr(10) = 13 ~~> foo.selectDynamic("arr").update(10, 13)
+ * foo.arr(10) ~~> foo.applyDynamics("arr")(10)
+ * }}}
+ *
+ * As of Scala 2.10, defining direct or indirect subclasses of this trait
+ * is only possible if the language feature `dynamics` is enabled.
*/
trait Dynamic
diff --git a/src/library/scala/Function0.scala b/src/library/scala/Function0.scala
index e1e9ddb3fb..3690a0e65b 100644
--- a/src/library/scala/Function0.scala
+++ b/src/library/scala/Function0.scala
@@ -6,7 +6,7 @@
** |/ **
\* */
// GENERATED CODE: DO NOT EDIT.
-// genprod generated these sources at: Sat Apr 28 12:59:55 PDT 2012
+// genprod generated these sources at: Mon Apr 30 07:46:11 PDT 2012
package scala
diff --git a/src/library/scala/Option.scala b/src/library/scala/Option.scala
index a58297d7d4..44c8fba45f 100644
--- a/src/library/scala/Option.scala
+++ b/src/library/scala/Option.scala
@@ -83,7 +83,7 @@ object Option {
* @define p `p`
* @define f `f`
* @define coll option
- * @define Coll Option
+ * @define Coll `Option`
* @define orderDependent
* @define orderDependentFold
* @define mayNotTerminateInf
diff --git a/src/library/scala/Predef.scala b/src/library/scala/Predef.scala
index b84fcc4126..500ee87c46 100644
--- a/src/library/scala/Predef.scala
+++ b/src/library/scala/Predef.scala
@@ -307,42 +307,36 @@ object Predef extends LowPriorityImplicits {
// views --------------------------------------------------------------
- implicit def exceptionWrapper(exc: Throwable) = new runtime.RichException(exc)
-
- implicit def zipped2ToTraversable[El1, El2](zz: Tuple2[_, _]#Zipped[_, El1, _, El2]): Traversable[(El1, El2)] =
- new collection.AbstractTraversable[(El1, El2)] {
- def foreach[U](f: ((El1, El2)) => U): Unit = zz foreach Function.untupled(f)
- }
-
- implicit def zipped3ToTraversable[El1, El2, El3](zz: Tuple3[_, _, _]#Zipped[_, El1, _, El2, _, El3]): Traversable[(El1, El2, El3)] =
- new collection.AbstractTraversable[(El1, El2, El3)] {
- def foreach[U](f: ((El1, El2, El3)) => U): Unit = zz foreach Function.untupled(f)
- }
-
- implicit def genericArrayOps[T](xs: Array[T]): ArrayOps[T] = xs match {
- case x: Array[AnyRef] => refArrayOps[AnyRef](x).asInstanceOf[ArrayOps[T]]
- case x: Array[Int] => intArrayOps(x).asInstanceOf[ArrayOps[T]]
- case x: Array[Double] => doubleArrayOps(x).asInstanceOf[ArrayOps[T]]
- case x: Array[Long] => longArrayOps(x).asInstanceOf[ArrayOps[T]]
- case x: Array[Float] => floatArrayOps(x).asInstanceOf[ArrayOps[T]]
- case x: Array[Char] => charArrayOps(x).asInstanceOf[ArrayOps[T]]
- case x: Array[Byte] => byteArrayOps(x).asInstanceOf[ArrayOps[T]]
- case x: Array[Short] => shortArrayOps(x).asInstanceOf[ArrayOps[T]]
- case x: Array[Boolean] => booleanArrayOps(x).asInstanceOf[ArrayOps[T]]
- case x: Array[Unit] => unitArrayOps(x).asInstanceOf[ArrayOps[T]]
+ implicit def exceptionWrapper(exc: Throwable) = new runtime.RichException(exc)
+ implicit def tuple2ToZippedOps[T1, T2](x: (T1, T2)) = new runtime.Tuple2Zipped.Ops(x)
+ implicit def tuple3ToZippedOps[T1, T2, T3](x: (T1, T2, T3)) = new runtime.Tuple3Zipped.Ops(x)
+ implicit def seqToCharSequence(xs: collection.IndexedSeq[Char]): CharSequence = new runtime.SeqCharSequence(xs)
+ implicit def arrayToCharSequence(xs: Array[Char]): CharSequence = new runtime.ArrayCharSequence(xs, 0, xs.length)
+
+ implicit def genericArrayOps[T](xs: Array[T]): ArrayOps[T] = (xs match {
+ case x: Array[AnyRef] => refArrayOps[AnyRef](x)
+ case x: Array[Boolean] => booleanArrayOps(x)
+ case x: Array[Byte] => byteArrayOps(x)
+ case x: Array[Char] => charArrayOps(x)
+ case x: Array[Double] => doubleArrayOps(x)
+ case x: Array[Float] => floatArrayOps(x)
+ case x: Array[Int] => intArrayOps(x)
+ case x: Array[Long] => longArrayOps(x)
+ case x: Array[Short] => shortArrayOps(x)
+ case x: Array[Unit] => unitArrayOps(x)
case null => null
- }
+ }).asInstanceOf[ArrayOps[T]]
- implicit def refArrayOps[T <: AnyRef](xs: Array[T]): ArrayOps[T] = new ArrayOps.ofRef[T](xs)
- implicit def intArrayOps(xs: Array[Int]): ArrayOps[Int] = new ArrayOps.ofInt(xs)
- implicit def doubleArrayOps(xs: Array[Double]): ArrayOps[Double] = new ArrayOps.ofDouble(xs)
- implicit def longArrayOps(xs: Array[Long]): ArrayOps[Long] = new ArrayOps.ofLong(xs)
- implicit def floatArrayOps(xs: Array[Float]): ArrayOps[Float] = new ArrayOps.ofFloat(xs)
- implicit def charArrayOps(xs: Array[Char]): ArrayOps[Char] = new ArrayOps.ofChar(xs)
- implicit def byteArrayOps(xs: Array[Byte]): ArrayOps[Byte] = new ArrayOps.ofByte(xs)
- implicit def shortArrayOps(xs: Array[Short]): ArrayOps[Short] = new ArrayOps.ofShort(xs)
implicit def booleanArrayOps(xs: Array[Boolean]): ArrayOps[Boolean] = new ArrayOps.ofBoolean(xs)
- implicit def unitArrayOps(xs: Array[Unit]): ArrayOps[Unit] = new ArrayOps.ofUnit(xs)
+ implicit def byteArrayOps(xs: Array[Byte]): ArrayOps[Byte] = new ArrayOps.ofByte(xs)
+ implicit def charArrayOps(xs: Array[Char]): ArrayOps[Char] = new ArrayOps.ofChar(xs)
+ implicit def doubleArrayOps(xs: Array[Double]): ArrayOps[Double] = new ArrayOps.ofDouble(xs)
+ implicit def floatArrayOps(xs: Array[Float]): ArrayOps[Float] = new ArrayOps.ofFloat(xs)
+ implicit def intArrayOps(xs: Array[Int]): ArrayOps[Int] = new ArrayOps.ofInt(xs)
+ implicit def longArrayOps(xs: Array[Long]): ArrayOps[Long] = new ArrayOps.ofLong(xs)
+ implicit def refArrayOps[T <: AnyRef](xs: Array[T]): ArrayOps[T] = new ArrayOps.ofRef[T](xs)
+ implicit def shortArrayOps(xs: Array[Short]): ArrayOps[Short] = new ArrayOps.ofShort(xs)
+ implicit def unitArrayOps(xs: Array[Unit]): ArrayOps[Unit] = new ArrayOps.ofUnit(xs)
// Primitive Widenings --------------------------------------------------------------
@@ -406,29 +400,17 @@ object Predef extends LowPriorityImplicits {
// Strings and CharSequences --------------------------------------------------------------
- implicit def any2stringadd(x: Any) = new runtime.StringAdd(x)
@inline implicit def any2stringfmt(x: Any) = new runtime.StringFormat(x)
@inline implicit def augmentString(x: String): StringOps = new StringOps(x)
+ implicit def any2stringadd(x: Any) = new runtime.StringAdd(x)
implicit def unaugmentString(x: StringOps): String = x.repr
- implicit def stringCanBuildFrom: CanBuildFrom[String, Char, String] =
- new CanBuildFrom[String, Char, String] {
- def apply(from: String) = apply()
- def apply() = mutable.StringBuilder.newBuilder
- }
-
- implicit def seqToCharSequence(xs: collection.IndexedSeq[Char]): CharSequence = new CharSequence {
- def length: Int = xs.length
- def charAt(index: Int): Char = xs(index)
- def subSequence(start: Int, end: Int): CharSequence = seqToCharSequence(xs.slice(start, end))
- override def toString: String = xs.mkString("")
- }
+ @deprecated("Use StringCanBuildFrom", "2.10.0")
+ def stringCanBuildFrom: CanBuildFrom[String, Char, String] = StringCanBuildFrom
- implicit def arrayToCharSequence(xs: Array[Char]): CharSequence = new CharSequence {
- def length: Int = xs.length
- def charAt(index: Int): Char = xs(index)
- def subSequence(start: Int, end: Int): CharSequence = arrayToCharSequence(xs.slice(start, end))
- override def toString: String = xs.mkString("")
+ implicit val StringCanBuildFrom: CanBuildFrom[String, Char, String] = new CanBuildFrom[String, Char, String] {
+ def apply(from: String) = apply()
+ def apply() = mutable.StringBuilder.newBuilder
}
// Type Constraints --------------------------------------------------------------
diff --git a/src/library/scala/Tuple2.scala b/src/library/scala/Tuple2.scala
index 58638f440f..5e77127080 100644
--- a/src/library/scala/Tuple2.scala
+++ b/src/library/scala/Tuple2.scala
@@ -9,9 +9,6 @@
package scala
-import scala.collection.{ TraversableLike => TLike, IterableLike => ILike }
-import scala.collection.generic.{ CanBuildFrom => CBF }
-
/** A tuple of 2 elements; the canonical representation of a [[scala.Product2]].
*
@@ -30,106 +27,4 @@ case class Tuple2[@specialized(Int, Long, Double, Char, Boolean, AnyRef) +T1, @s
*/
def swap: Tuple2[T2,T1] = Tuple2(_2, _1)
- @deprecated("Use `zipped` instead.", "2.9.0")
- @annotation.unspecialized
- def zip[Repr1, El1, El2, To](implicit w1: T1 => TLike[El1, Repr1],
- w2: T2 => Iterable[El2],
- cbf1: CBF[Repr1, (El1, El2), To]): To = {
- zipped map ((x, y) => ((x, y)))
- }
-
- /** Wraps a tuple in a `Zipped`, which supports 2-ary generalisations of `map`, `flatMap`, `filter`, etc.
- * Note that there must be an implicit value to convert this tuple's types into a [[scala.collection.TraversableLike]]
- * or [[scala.collection.IterableLike]].
- * {{{
- * scala> val tuple = (List(1,2,3),List('a','b','c'))
- * tuple: (List[Int], List[Char]) = (List(1, 2, 3),List(a, b, c))
- *
- * scala> tuple.zipped map { (x,y) => x + ":" + y }
- * res6: List[java.lang.String] = List(1:a, 2:b, 3:c)
- * }}}
- *
- * @see Zipped
- * Note: will not terminate for infinite-sized collections.
- */
- def zipped[Repr1, El1, Repr2, El2](implicit w1: T1 => TLike[El1, Repr1], w2: T2 => ILike[El2, Repr2]): Zipped[Repr1, El1, Repr2, El2]
- = new Zipped[Repr1, El1, Repr2, El2](_1, _2)
-
- class Zipped[+Repr1, +El1, +Repr2, +El2](coll1: TLike[El1, Repr1], coll2: ILike[El2, Repr2]) { // coll2: ILike for filter
- def map[B, To](f: (El1, El2) => B)(implicit cbf: CBF[Repr1, B, To]): To = {
- val b = cbf(coll1.repr)
- b.sizeHint(coll1)
- val elems2 = coll2.iterator
-
- for (el1 <- coll1) {
- if (elems2.hasNext)
- b += f(el1, elems2.next)
- else
- return b.result
- }
-
- b.result
- }
-
- def flatMap[B, To](f: (El1, El2) => TraversableOnce[B])(implicit cbf: CBF[Repr1, B, To]): To = {
- val b = cbf(coll1.repr)
- val elems2 = coll2.iterator
-
- for (el1 <- coll1) {
- if (elems2.hasNext)
- b ++= f(el1, elems2.next)
- else
- return b.result
- }
-
- b.result
- }
-
- def filter[To1, To2](f: (El1, El2) => Boolean)(implicit cbf1: CBF[Repr1, El1, To1], cbf2: CBF[Repr2, El2, To2]): (To1, To2) = {
- val b1 = cbf1(coll1.repr)
- val b2 = cbf2(coll2.repr)
- val elems2 = coll2.iterator
-
- for (el1 <- coll1) {
- if (elems2.hasNext) {
- val el2 = elems2.next
- if (f(el1, el2)) {
- b1 += el1
- b2 += el2
- }
- }
- else return (b1.result, b2.result)
- }
-
- (b1.result, b2.result)
- }
-
- def exists(f: (El1, El2) => Boolean): Boolean = {
- val elems2 = coll2.iterator
-
- for (el1 <- coll1) {
- if (elems2.hasNext) {
- if (f(el1, elems2.next))
- return true
- }
- else return false
- }
- false
- }
-
- def forall(f: (El1, El2) => Boolean): Boolean =
- !exists((x, y) => !f(x, y))
-
- def foreach[U](f: (El1, El2) => U): Unit = {
- val elems2 = coll2.iterator
-
- for (el1 <- coll1) {
- if (elems2.hasNext)
- f(el1, elems2.next)
- else
- return
- }
- }
- }
-
}
diff --git a/src/library/scala/Tuple3.scala b/src/library/scala/Tuple3.scala
index 0d5399308b..5ed13602e3 100644
--- a/src/library/scala/Tuple3.scala
+++ b/src/library/scala/Tuple3.scala
@@ -9,9 +9,6 @@
package scala
-import scala.collection.{ TraversableLike => TLike, IterableLike => ILike }
-import scala.collection.generic.{ CanBuildFrom => CBF }
-
/** A tuple of 3 elements; the canonical representation of a [[scala.Product3]].
*
@@ -25,121 +22,4 @@ case class Tuple3[+T1, +T2, +T3](_1: T1, _2: T2, _3: T3)
{
override def toString() = "(" + _1 + "," + _2 + "," + _3 + ")"
-
- @deprecated("Use `zipped` instead.", "2.9.0")
- def zip[Repr1, El1, El2, El3, To](implicit w1: T1 => TLike[El1, Repr1],
- w2: T2 => Iterable[El2],
- w3: T3 => Iterable[El3],
- cbf1: CBF[Repr1, (El1, El2, El3), To]): To = {
- zipped map ((x, y, z) => ((x, y, z)))
- }
-
- /** Wraps a tuple in a `Zipped`, which supports 3-ary generalisations of `map`, `flatMap`, `filter`, etc.
- * Note that there must be an implicit value to convert this tuple's types into a [[scala.collection.TraversableLike]]
- * or [[scala.collection.IterableLike]].
- * {{{
- * scala> val tuple = (List(1,2,3),List('a','b','c'),List("x","y","z"))
- * tuple: (List[Int], List[Char], List[java.lang.String]) = (List(1, 2, 3),List(a, b, c),List(x, y, z))
- *
- * scala> tuple.zipped map { (x,y,z) => x + ":" + y + ":" + z}
- * res8: List[java.lang.String] = List(1:a:x, 2:b:y, 3:c:z)
- * }}}
- *
- * @see Zipped
- * Note: will not terminate for infinite-sized collections.
- */
- def zipped[Repr1, El1, Repr2, El2, Repr3, El3](implicit w1: T1 => TLike[El1, Repr1],
- w2: T2 => ILike[El2, Repr2],
- w3: T3 => ILike[El3, Repr3]): Zipped[Repr1, El1, Repr2, El2, Repr3, El3]
- = new Zipped[Repr1, El1, Repr2, El2, Repr3, El3](_1, _2, _3)
-
- class Zipped[+Repr1, +El1, +Repr2, +El2, +Repr3, +El3](coll1: TLike[El1, Repr1],
- coll2: ILike[El2, Repr2],
- coll3: ILike[El3, Repr3]) {
- def map[B, To](f: (El1, El2, El3) => B)(implicit cbf: CBF[Repr1, B, To]): To = {
- val b = cbf(coll1.repr)
- val elems2 = coll2.iterator
- val elems3 = coll3.iterator
-
- for (el1 <- coll1) {
- if (elems2.hasNext && elems3.hasNext)
- b += f(el1, elems2.next, elems3.next)
- else
- return b.result
- }
- b.result
- }
-
- def flatMap[B, To](f: (El1, El2, El3) => TraversableOnce[B])(implicit cbf: CBF[Repr1, B, To]): To = {
- val b = cbf(coll1.repr)
- val elems2 = coll2.iterator
- val elems3 = coll3.iterator
-
- for (el1 <- coll1) {
- if (elems2.hasNext && elems3.hasNext)
- b ++= f(el1, elems2.next, elems3.next)
- else
- return b.result
- }
- b.result
- }
-
- def filter[To1, To2, To3](f: (El1, El2, El3) => Boolean)(
- implicit cbf1: CBF[Repr1, El1, To1],
- cbf2: CBF[Repr2, El2, To2],
- cbf3: CBF[Repr3, El3, To3]): (To1, To2, To3) = {
- val b1 = cbf1(coll1.repr)
- val b2 = cbf2(coll2.repr)
- val b3 = cbf3(coll3.repr)
- val elems2 = coll2.iterator
- val elems3 = coll3.iterator
- def result = (b1.result, b2.result, b3.result)
-
- for (el1 <- coll1) {
- if (elems2.hasNext && elems3.hasNext) {
- val el2 = elems2.next
- val el3 = elems3.next
-
- if (f(el1, el2, el3)) {
- b1 += el1
- b2 += el2
- b3 += el3
- }
- }
- else return result
- }
-
- result
- }
-
- def exists(f: (El1, El2, El3) => Boolean): Boolean = {
- val elems2 = coll2.iterator
- val elems3 = coll3.iterator
-
- for (el1 <- coll1) {
- if (elems2.hasNext && elems3.hasNext) {
- if (f(el1, elems2.next, elems3.next))
- return true
- }
- else return false
- }
- false
- }
-
- def forall(f: (El1, El2, El3) => Boolean): Boolean =
- !exists((x, y, z) => !f(x, y, z))
-
- def foreach[U](f: (El1, El2, El3) => U): Unit = {
- val elems2 = coll2.iterator
- val elems3 = coll3.iterator
-
- for (el1 <- coll1) {
- if (elems2.hasNext && elems3.hasNext)
- f(el1, elems2.next, elems3.next)
- else
- return
- }
- }
- }
-
}
diff --git a/src/library/scala/collection/BitSet.scala b/src/library/scala/collection/BitSet.scala
index 59b53faf7e..90e837b219 100644
--- a/src/library/scala/collection/BitSet.scala
+++ b/src/library/scala/collection/BitSet.scala
@@ -22,7 +22,7 @@ trait BitSet extends SortedSet[Int]
/** $factoryInfo
* @define coll bitset
- * @define Coll BitSet
+ * @define Coll `BitSet`
*/
object BitSet extends BitSetFactory[BitSet] {
val empty: BitSet = immutable.BitSet.empty
diff --git a/src/library/scala/collection/BitSetLike.scala b/src/library/scala/collection/BitSetLike.scala
index e4f9fd436a..c0aaa9f28e 100644
--- a/src/library/scala/collection/BitSetLike.scala
+++ b/src/library/scala/collection/BitSetLike.scala
@@ -30,7 +30,7 @@ import mutable.StringBuilder
* @version 2.8
* @since 2.8
* @define coll bitset
- * @define Coll BitSet
+ * @define Coll `BitSet`
*/
trait BitSetLike[+This <: BitSetLike[This] with SortedSet[Int]] extends SortedSetLike[Int, This] { self =>
diff --git a/src/library/scala/collection/GenIterableLike.scala b/src/library/scala/collection/GenIterableLike.scala
index 8fa5981969..290a3b26b5 100644
--- a/src/library/scala/collection/GenIterableLike.scala
+++ b/src/library/scala/collection/GenIterableLike.scala
@@ -16,7 +16,7 @@ import generic.{ CanBuildFrom => CBF, _ }
* This trait contains abstract methods and methods that can be implemented
* directly in terms of other methods.
*
- * @define Coll GenIterable
+ * @define Coll `GenIterable`
* @define coll general iterable collection
*
* @author Martin Odersky
@@ -141,7 +141,4 @@ trait GenIterableLike[+A, +Repr] extends Any with GenTraversableLike[A, Repr] {
*/
def zipAll[B, A1 >: A, That](that: GenIterable[B], thisElem: A1, thatElem: B)(implicit bf: CBF[Repr, (A1, B), That]): That
- def isEmpty = iterator.isEmpty
-
- def head = iterator.next
}
diff --git a/src/library/scala/collection/GenMapLike.scala b/src/library/scala/collection/GenMapLike.scala
index 114169c849..d611eaea43 100644
--- a/src/library/scala/collection/GenMapLike.scala
+++ b/src/library/scala/collection/GenMapLike.scala
@@ -11,7 +11,7 @@ package scala.collection
/** A trait for all maps upon which operations may be
* implemented in parallel.
*
- * @define Coll GenMap
+ * @define Coll `GenMap`
* @define coll general map
* @author Martin Odersky
* @author Aleksandar Prokopec
diff --git a/src/library/scala/collection/GenTraversableLike.scala b/src/library/scala/collection/GenTraversableLike.scala
index 4500a849b1..df652f99d9 100644
--- a/src/library/scala/collection/GenTraversableLike.scala
+++ b/src/library/scala/collection/GenTraversableLike.scala
@@ -43,7 +43,7 @@ import annotation.migration
* @define traversableInfo
* This is a base trait of all kinds of Scala collections.
*
- * @define Coll GenTraversable
+ * @define Coll `GenTraversable`
* @define coll general collection
* @define collectExample
* @tparam A the collection element type.
@@ -59,12 +59,24 @@ trait GenTraversableLike[+A, +Repr] extends Any with GenTraversableOnce[A] with
def size: Int
+ /** Selects the first element of this $coll.
+ * $orderDependent
+ * @return the first element of this $coll.
+ * @throws `NoSuchElementException` if the $coll is empty.
+ */
def head: A
-
+
+ /** Optionally selects the first element.
+ * $orderDependent
+ * @return the first element of this $coll if it is nonempty,
+ * `None` if it is empty.
+ */
+ def headOption: Option[A]
+
/** Tests whether this $coll can be repeatedly traversed.
* @return `true`
*/
- final def isTraversableAgain = true
+ def isTraversableAgain: Boolean
/** Selects all elements except the first.
* $orderDependent
@@ -72,11 +84,30 @@ trait GenTraversableLike[+A, +Repr] extends Any with GenTraversableOnce[A] with
* except the first one.
* @throws `UnsupportedOperationException` if the $coll is empty.
*/
- def tail: Repr = {
- if (isEmpty) throw new UnsupportedOperationException("empty.tail")
- drop(1)
- }
+ def tail: Repr
+ /** Selects the last element.
+ * $orderDependent
+ * @return The last element of this $coll.
+ * @throws NoSuchElementException If the $coll is empty.
+ */
+ def last: A
+
+ /** Optionally selects the last element.
+ * $orderDependent
+ * @return the last element of this $coll$ if it is nonempty,
+ * `None` if it is empty.
+ */
+ def lastOption: Option[A]
+
+ /** Selects all elements except the last.
+ * $orderDependent
+ * @return a $coll consisting of all elements of this $coll
+ * except the last one.
+ * @throws `UnsupportedOperationException` if the $coll is empty.
+ */
+ def init: Repr
+
/** Computes a prefix scan of the elements of the collection.
*
* Note: The neutral element `z` may be applied more than once.
diff --git a/src/library/scala/collection/GenTraversableOnce.scala b/src/library/scala/collection/GenTraversableOnce.scala
index fd8595ccb8..f4e3848d98 100644
--- a/src/library/scala/collection/GenTraversableOnce.scala
+++ b/src/library/scala/collection/GenTraversableOnce.scala
@@ -14,7 +14,7 @@ package scala.collection
* Methods in this trait are either abstract or can be implemented in terms
* of other methods.
*
- * @define Coll GenTraversableOnce
+ * @define Coll `GenTraversableOnce`
* @define coll collection or iterator
* @define possiblyparinfo
* This trait may possibly have operations implemented in parallel.
diff --git a/src/library/scala/collection/IndexedSeq.scala b/src/library/scala/collection/IndexedSeq.scala
index 4a3586a375..56dd0bffff 100644
--- a/src/library/scala/collection/IndexedSeq.scala
+++ b/src/library/scala/collection/IndexedSeq.scala
@@ -26,7 +26,7 @@ trait IndexedSeq[+A] extends Seq[A]
/** $factoryInfo
* The current default implementation of a $Coll is a `Vector`.
* @define coll indexed sequence
- * @define Coll IndexedSeq
+ * @define Coll `IndexedSeq`
*/
object IndexedSeq extends SeqFactory[IndexedSeq] {
implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, IndexedSeq[A]] = ReusableCBF.asInstanceOf[GenericCanBuildFrom[A]]
diff --git a/src/library/scala/collection/IndexedSeqLike.scala b/src/library/scala/collection/IndexedSeqLike.scala
index d1f7d1cb36..11f481e425 100644
--- a/src/library/scala/collection/IndexedSeqLike.scala
+++ b/src/library/scala/collection/IndexedSeqLike.scala
@@ -26,7 +26,7 @@ import scala.annotation.tailrec
* access and length computation. They are defined in terms of abstract methods
* `apply` for indexing and `length`.
*
- * Indexed sequences do not add any new methods wrt `Seq`, but promise
+ * Indexed sequences do not add any new methods to `Seq`, but promise
* efficient implementations of random access patterns.
*
* @tparam A the element type of the $coll
diff --git a/src/library/scala/collection/Iterable.scala b/src/library/scala/collection/Iterable.scala
index b1752a5c67..f543c6f80f 100644
--- a/src/library/scala/collection/Iterable.scala
+++ b/src/library/scala/collection/Iterable.scala
@@ -40,7 +40,7 @@ trait Iterable[+A] extends Traversable[A]
/** $factoryInfo
* The current default implementation of a $Coll is a `Vector`.
* @define coll iterable collection
- * @define Coll Iterable
+ * @define Coll `Iterable`
*/
object Iterable extends TraversableFactory[Iterable] {
diff --git a/src/library/scala/collection/Iterator.scala b/src/library/scala/collection/Iterator.scala
index 65de60c8fe..e9a7906527 100644
--- a/src/library/scala/collection/Iterator.scala
+++ b/src/library/scala/collection/Iterator.scala
@@ -21,6 +21,15 @@ import immutable.Stream
*/
object Iterator {
+ /** With the advent of `TraversableOnce` and `Iterator`, it can be useful to have a builder which
+ * operates on `Iterator`s so they can be treated uniformly along with the collections.
+ * See `scala.util.Random.shuffle` for an example.
+ */
+ implicit def IteratorCanBuildFrom[A] = new TraversableOnce.BufferedCanBuildFrom[A, Iterator] {
+ def bufferToColl[B](coll: ArrayBuffer[B]) = coll.iterator
+ def traversableToColl[B](t: GenTraversable[B]) = t.toIterator
+ }
+
/** The iterator which produces no values. */
val empty: Iterator[Nothing] = new AbstractIterator[Nothing] {
def hasNext: Boolean = false
@@ -382,6 +391,24 @@ trait Iterator[+A] extends TraversableOnce[A] {
def next() = if (hasNext) { hdDefined = false; hd } else empty.next()
}
+
+ /** Tests whether every element of this iterator relates to the
+ * corresponding element of another collection by satisfying a test predicate.
+ *
+ * @param that the other collection
+ * @param p the test predicate, which relates elements from both collections
+ * @tparam B the type of the elements of `that`
+ * @return `true` if both collections have the same length and
+ * `p(x, y)` is `true` for all corresponding elements `x` of this iterator
+ * and `y` of `that`, otherwise `false`
+ */
+ def corresponds[B](that: GenTraversableOnce[B])(p: (A, B) => Boolean): Boolean = {
+ val that0 = that.toIterator
+ while (hasNext && that0.hasNext)
+ if (!p(next, that0.next)) return false
+
+ hasNext == that0.hasNext
+ }
/** Creates an iterator over all the elements of this iterator that
* satisfy the predicate `p`. The order of the elements
diff --git a/src/library/scala/collection/LinearSeq.scala b/src/library/scala/collection/LinearSeq.scala
index be143cf96b..21ed91f7f3 100644
--- a/src/library/scala/collection/LinearSeq.scala
+++ b/src/library/scala/collection/LinearSeq.scala
@@ -26,7 +26,7 @@ trait LinearSeq[+A] extends Seq[A]
/** $factoryInfo
* The current default implementation of a $Coll is a `Vector`.
* @define coll linear sequence
- * @define Coll LinearSeq
+ * @define Coll `LinearSeq`
*/
object LinearSeq extends SeqFactory[LinearSeq] {
implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, LinearSeq[A]] = ReusableCBF.asInstanceOf[GenericCanBuildFrom[A]]
diff --git a/src/library/scala/collection/Map.scala b/src/library/scala/collection/Map.scala
index 0c07d5bb74..42a56a9c5a 100644
--- a/src/library/scala/collection/Map.scala
+++ b/src/library/scala/collection/Map.scala
@@ -33,7 +33,7 @@ trait Map[A, +B] extends Iterable[(A, B)] with GenMap[A, B] with MapLike[A, B, M
}
/** $factoryInfo
- * @define Coll Map
+ * @define Coll `Map`
* @define coll map
*/
object Map extends MapFactory[Map] {
@@ -45,7 +45,7 @@ object Map extends MapFactory[Map] {
/** An abstract shell used by { mutable, immutable }.Map but not by collection.Map
* because of variance issues.
*/
- abstract class WithDefault[A, +B](underlying: Map[A, B], d: A => B) extends AbstractMap[A, B] with Map[A, B] {
+ abstract class WithDefault[A, +B](underlying: Map[A, B], d: A => B) extends AbstractMap[A, B] with Map[A, B] with Serializable {
override def size = underlying.size
def get(key: A) = underlying.get(key) // removed in 2.9: orElse Some(default(key))
def iterator = underlying.iterator
diff --git a/src/library/scala/collection/MapLike.scala b/src/library/scala/collection/MapLike.scala
index 034c1a0c0c..b2b687e75a 100644
--- a/src/library/scala/collection/MapLike.scala
+++ b/src/library/scala/collection/MapLike.scala
@@ -165,7 +165,7 @@ self =>
/** The implementation class of the set returned by `keySet`.
*/
- protected class DefaultKeySet extends AbstractSet[A] with Set[A] {
+ protected class DefaultKeySet extends AbstractSet[A] with Set[A] with Serializable {
def contains(key : A) = self.contains(key)
def iterator = keysIterator
def + (elem: A): Set[A] = (Set[A]() ++ this + elem).asInstanceOf[Set[A]] // !!! concrete overrides abstract problem
@@ -200,7 +200,7 @@ self =>
/** The implementation class of the iterable returned by `values`.
*/
- protected class DefaultValuesIterable extends AbstractIterable[B] with Iterable[B] {
+ protected class DefaultValuesIterable extends AbstractIterable[B] with Iterable[B] with Serializable {
def iterator = valuesIterator
override def size = self.size
override def foreach[C](f: B => C) = self.valuesIterator foreach f
diff --git a/src/library/scala/collection/Seq.scala b/src/library/scala/collection/Seq.scala
index fd03a49af4..34705ee058 100644
--- a/src/library/scala/collection/Seq.scala
+++ b/src/library/scala/collection/Seq.scala
@@ -27,7 +27,7 @@ trait Seq[+A] extends PartialFunction[Int, A]
/** $factoryInfo
* The current default implementation of a $Coll is a `List`.
* @define coll sequence
- * @define Coll Seq
+ * @define Coll `Seq`
*/
object Seq extends SeqFactory[Seq] {
/** $genericCanBuildFromInfo */
diff --git a/src/library/scala/collection/SeqLike.scala b/src/library/scala/collection/SeqLike.scala
index a9535adc23..044bd624ae 100644
--- a/src/library/scala/collection/SeqLike.scala
+++ b/src/library/scala/collection/SeqLike.scala
@@ -45,7 +45,7 @@ import scala.math.Ordering
* @version 1.0, 16/07/2003
* @since 2.8
*
- * @define Coll Seq
+ * @define Coll `Seq`
* @define coll sequence
* @define thatinfo the class of the returned collection. Where possible, `That` is
* the same class as the current collection class `Repr`, but this
@@ -380,8 +380,8 @@ trait SeqLike[+A, +Repr] extends Any with IterableLike[A, Repr] with GenSeqLike[
* $mayNotTerminateInf
*
* @param elem the element to test.
- * @return `true` if this $coll has an element that is
- * is equal (wrt `==`) to `elem`, `false` otherwise.
+ * @return `true` if this $coll has an element that is equal (as
+ * determined by `==`) to `elem`, `false` otherwise.
*/
def contains(elem: Any): Boolean = exists (_ == elem)
@@ -553,8 +553,8 @@ trait SeqLike[+A, +Repr] extends Any with IterableLike[A, Repr] with GenSeqLike[
/** Sorts this $coll according to a comparison function.
* $willNotTerminateInf
*
- * The sort is stable. That is, elements that are equal wrt `lt` appear in the
- * same order in the sorted sequence as in the original.
+ * The sort is stable. That is, elements that are equal (as determined by
+ * `lt`) appear in the same order in the sorted sequence as in the original.
*
* @param lt the comparison function which tests whether
* its first argument precedes its second argument in
@@ -592,8 +592,8 @@ trait SeqLike[+A, +Repr] extends Any with IterableLike[A, Repr] with GenSeqLike[
/** Sorts this $coll according to an Ordering.
*
- * The sort is stable. That is, elements that are equal wrt `lt` appear in the
- * same order in the sorted sequence as in the original.
+ * The sort is stable. That is, elements that are equal (as determined by
+ * `lt`) appear in the same order in the sorted sequence as in the original.
*
* @see scala.math.Ordering
*
diff --git a/src/library/scala/collection/Set.scala b/src/library/scala/collection/Set.scala
index 4c67aad603..7424c9cb9a 100644
--- a/src/library/scala/collection/Set.scala
+++ b/src/library/scala/collection/Set.scala
@@ -35,7 +35,7 @@ trait Set[A] extends (A => Boolean)
* The current default implementation of a $Coll is one of `EmptySet`, `Set1`, `Set2`, `Set3`, `Set4` in
* class `immutable.Set` for sets of sizes up to 4, and a `immutable.HashSet` for sets of larger sizes.
* @define coll set
- * @define Coll Set
+ * @define Coll `Set`
*/
object Set extends SetFactory[Set] {
def newBuilder[A] = immutable.Set.newBuilder[A]
diff --git a/src/library/scala/collection/TraversableLike.scala b/src/library/scala/collection/TraversableLike.scala
index 3ca4bfeee9..3716a318d9 100644
--- a/src/library/scala/collection/TraversableLike.scala
+++ b/src/library/scala/collection/TraversableLike.scala
@@ -84,6 +84,8 @@ trait TraversableLike[+A, +Repr] extends Any
*/
def repr: Repr = this.asInstanceOf[Repr]
+ final def isTraversableAgain: Boolean = true
+
/** The underlying collection seen as an instance of `$Coll`.
* By default this is implemented as the current collection object itself,
* but this can be overridden.
diff --git a/src/library/scala/collection/TraversableOnce.scala b/src/library/scala/collection/TraversableOnce.scala
index 5b5cee7f1b..639610a30c 100644
--- a/src/library/scala/collection/TraversableOnce.scala
+++ b/src/library/scala/collection/TraversableOnce.scala
@@ -8,7 +8,7 @@
package scala.collection
-import mutable.{ Buffer, ListBuffer, ArrayBuffer }
+import mutable.{ Buffer, Builder, ListBuffer, ArrayBuffer }
import annotation.unchecked.{ uncheckedVariance => uV }
import language.{implicitConversions, higherKinds}
@@ -357,7 +357,6 @@ trait TraversableOnce[+A] extends Any with GenTraversableOnce[A] {
}
-
object TraversableOnce {
@deprecated("use OnceCanBuildFrom instead")
def traversableOnceCanBuildFrom[T] = new OnceCanBuildFrom[T]
@@ -367,26 +366,43 @@ object TraversableOnce {
implicit def alternateImplicit[A](trav: TraversableOnce[A]) = new ForceImplicitAmbiguity
implicit def flattenTraversableOnce[A, CC[_]](travs: TraversableOnce[CC[A]])(implicit ev: CC[A] => TraversableOnce[A]) =
new FlattenOps[A](travs map ev)
-
- /** With the advent of TraversableOnce, it can be useful to have a builder which
- * operates on Iterators so they can be treated uniformly along with the collections.
- * See scala.util.Random.shuffle for an example.
- */
- implicit class OnceCanBuildFrom[A] extends generic.CanBuildFrom[TraversableOnce[A], A, TraversableOnce[A]] {
- def newIterator = new ArrayBuffer[A] mapResult (_.iterator)
+
+ /* Functionality reused in Iterator.CanBuildFrom */
+ private[collection] abstract class BufferedCanBuildFrom[A, Coll[X] <: TraversableOnce[X]] extends generic.CanBuildFrom[Coll[_], A, Coll[A]] {
+ def bufferToColl[B](buff: ArrayBuffer[B]): Coll[B]
+ def traversableToColl[B](t: GenTraversable[B]): Coll[B]
+
+ def newIterator: Builder[A, Coll[A]] = new ArrayBuffer[A] mapResult bufferToColl
/** Creates a new builder on request of a collection.
* @param from the collection requesting the builder to be created.
* @return the result of invoking the `genericBuilder` method on `from`.
*/
- def apply(from: TraversableOnce[A]) = newIterator
+ def apply(from: Coll[_]): Builder[A, Coll[A]] = from match {
+ case xs: generic.GenericTraversableTemplate[_, _] => xs.genericBuilder.asInstanceOf[Builder[A, Traversable[A]]] mapResult {
+ case res => traversableToColl(res.asInstanceOf[GenTraversable[A]])
+ }
+ case _ => newIterator
+ }
/** Creates a new builder from scratch
* @return the result of invoking the `newBuilder` method of this factory.
*/
def apply() = newIterator
}
-
+
+ /** With the advent of `TraversableOnce`, it can be useful to have a builder which
+ * operates on `Iterator`s so they can be treated uniformly along with the collections.
+ * See `scala.util.Random.shuffle` or `scala.concurrent.Future.sequence` for an example.
+ */
+ class OnceCanBuildFrom[A] extends BufferedCanBuildFrom[A, TraversableOnce] {
+ def bufferToColl[B](buff: ArrayBuffer[B]) = buff.iterator
+ def traversableToColl[B](t: GenTraversable[B]) = t.seq
+ }
+
+ /** Evidence for building collections from `TraversableOnce` collections */
+ implicit def OnceCanBuildFrom[A] = new OnceCanBuildFrom[A]
+
class FlattenOps[A](travs: TraversableOnce[TraversableOnce[A]]) {
def flatten: Iterator[A] = new AbstractIterator[A] {
val its = travs.toIterator
diff --git a/src/library/scala/collection/TraversableViewLike.scala b/src/library/scala/collection/TraversableViewLike.scala
index ad5e3d3240..5ca038fd2e 100644
--- a/src/library/scala/collection/TraversableViewLike.scala
+++ b/src/library/scala/collection/TraversableViewLike.scala
@@ -28,8 +28,16 @@ trait ViewMkString[+A] {
override def mkString(start: String, sep: String, end: String): String = {
thisSeq.addString(new StringBuilder(), start, sep, end).toString
}
- override def addString(b: StringBuilder, start: String, sep: String, end: String): StringBuilder =
- b append start append "..." append end
+ override def addString(b: StringBuilder, start: String, sep: String, end: String): StringBuilder = {
+ var first = true
+ b append start
+ for (x <- self) {
+ if (first) first = false else b append sep
+ b append x
+ }
+ b append end
+ b
+ }
}
/** A template trait for non-strict views of traversable collections.
@@ -41,17 +49,17 @@ trait ViewMkString[+A] {
* that takes a `View` as its `From` type parameter must yield the same view (or a generic
* superclass of it) as its result parameter. If that assumption is broken, cast errors might result.
*
- * @define viewInfo
+ * @define viewInfo
* A view is a lazy version of some collection. Collection transformers such as
* `map` or `filter` or `++` do not traverse any elements when applied on a view.
* Instead they create a new view which simply records that fact that the operation
* needs to be applied. The collection elements are accessed, and the view operations are applied,
* when a non-view result is needed, or when the `force` method is called on a view.
- * @define traversableViewInfo
+ * @define traversableViewInfo
* $viewInfo
*
* All views for traversable collections are defined by creating a new `foreach` method.
-
+ *
* @author Martin Odersky
* @version 2.8
* @since 2.8
diff --git a/src/library/scala/collection/concurrent/Map.scala b/src/library/scala/collection/concurrent/Map.scala
index 83445738d9..a724be42cc 100644
--- a/src/library/scala/collection/concurrent/Map.scala
+++ b/src/library/scala/collection/concurrent/Map.scala
@@ -19,7 +19,7 @@ package scala.collection.concurrent
* @tparam A the key type of the map
* @tparam B the value type of the map
*
- * @define Coll ConcurrentMap
+ * @define Coll `ConcurrentMap`
* @define coll concurrent map
* @define concurrentmapinfo
* This is a base trait for all Scala concurrent map implementations. It
diff --git a/src/library/scala/collection/generic/ArrayTagTraversableFactory.scala b/src/library/scala/collection/generic/ArrayTagTraversableFactory.scala
index d9ab17559e..ddae0a4d64 100644
--- a/src/library/scala/collection/generic/ArrayTagTraversableFactory.scala
+++ b/src/library/scala/collection/generic/ArrayTagTraversableFactory.scala
@@ -15,7 +15,7 @@ import language.higherKinds
* subclasses thereof.
*
* @define coll collection
- * @define Coll Traversable
+ * @define Coll `Traversable`
* @define genericCanBuildFromInfo
* The standard `CanBuildFrom` instance for $Coll objects.
* @author Aleksandar Prokopec
diff --git a/src/library/scala/collection/generic/BitSetFactory.scala b/src/library/scala/collection/generic/BitSetFactory.scala
index 796b12b0ac..da80b3964b 100644
--- a/src/library/scala/collection/generic/BitSetFactory.scala
+++ b/src/library/scala/collection/generic/BitSetFactory.scala
@@ -15,7 +15,7 @@ import scala.collection._
import mutable.Builder
/** @define coll collection
- * @define Coll Traversable
+ * @define Coll `Traversable`
* @define factoryInfo
* This object provides a set of operations to create `$Coll` values.
* @author Martin Odersky
diff --git a/src/library/scala/collection/generic/Clearable.scala b/src/library/scala/collection/generic/Clearable.scala
new file mode 100644
index 0000000000..6c8d9558b0
--- /dev/null
+++ b/src/library/scala/collection/generic/Clearable.scala
@@ -0,0 +1,26 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+package scala.collection
+package generic
+
+/** This trait forms part of collections that can be cleared
+ * with a clear() call.
+ *
+ * @author Paul Phillips
+ * @version 2.10
+ * @since 2.10
+ * @define coll clearable collection
+ * @define Coll `Clearable`
+ */
+trait Clearable {
+ /** Clears the $coll's contents. After this operation, the
+ * $coll is empty.
+ */
+ def clear(): Unit
+}
diff --git a/src/library/scala/collection/generic/GenMapFactory.scala b/src/library/scala/collection/generic/GenMapFactory.scala
index b3faf0497b..31fe4e100d 100644
--- a/src/library/scala/collection/generic/GenMapFactory.scala
+++ b/src/library/scala/collection/generic/GenMapFactory.scala
@@ -15,7 +15,7 @@ import language.higherKinds
/** A template for companion objects of `Map` and subclasses thereof.
*
* @define coll map
- * @define Coll Map
+ * @define Coll `Map`
* @define factoryInfo
* This object provides a set of operations needed to create `$Coll` values.
* @author Martin Odersky
diff --git a/src/library/scala/collection/generic/GenSetFactory.scala b/src/library/scala/collection/generic/GenSetFactory.scala
index caae8afa1c..4f812b337c 100644
--- a/src/library/scala/collection/generic/GenSetFactory.scala
+++ b/src/library/scala/collection/generic/GenSetFactory.scala
@@ -17,7 +17,7 @@ import language.higherKinds
/** A template for companion objects of `Set` and subclasses thereof.
*
* @define coll set
- * @define Coll Set
+ * @define Coll `Set`
* @define factoryInfo
* This object provides a set of operations needed to create `$Coll` values.
* @author Martin Odersky
diff --git a/src/library/scala/collection/generic/GenTraversableFactory.scala b/src/library/scala/collection/generic/GenTraversableFactory.scala
index f233a40d35..94def7ab5d 100644
--- a/src/library/scala/collection/generic/GenTraversableFactory.scala
+++ b/src/library/scala/collection/generic/GenTraversableFactory.scala
@@ -19,7 +19,7 @@ import language.higherKinds
* @since 2.8
*
* @define coll collection
- * @define Coll Traversable
+ * @define Coll `Traversable`
* @define factoryInfo
* This object provides a set of operations to create `$Coll` values.
* @author Martin Odersky
diff --git a/src/library/scala/collection/generic/GenericCompanion.scala b/src/library/scala/collection/generic/GenericCompanion.scala
index cf01cf5f08..badceac713 100644
--- a/src/library/scala/collection/generic/GenericCompanion.scala
+++ b/src/library/scala/collection/generic/GenericCompanion.scala
@@ -20,7 +20,7 @@ import language.higherKinds
* @author Martin Odersky
* @since 2.8
* @define coll collection
- * @define Coll CC
+ * @define Coll `CC`
*/
abstract class GenericCompanion[+CC[X] <: GenTraversable[X]] {
/** The underlying collection type with unknown element type */
diff --git a/src/library/scala/collection/generic/GenericParCompanion.scala b/src/library/scala/collection/generic/GenericParCompanion.scala
index 93c166b7ba..484da5c6d9 100644
--- a/src/library/scala/collection/generic/GenericParCompanion.scala
+++ b/src/library/scala/collection/generic/GenericParCompanion.scala
@@ -16,7 +16,7 @@ import language.higherKinds
/** A template class for companion objects of parallel collection classes.
* They should be mixed in together with `GenericCompanion` type.
*
- * @define Coll ParIterable
+ * @define Coll `ParIterable`
* @tparam CC the type constructor representing the collection class
* @since 2.8
*/
diff --git a/src/library/scala/collection/generic/Growable.scala b/src/library/scala/collection/generic/Growable.scala
index f0a70c2b88..d6a263af2f 100644
--- a/src/library/scala/collection/generic/Growable.scala
+++ b/src/library/scala/collection/generic/Growable.scala
@@ -18,11 +18,11 @@ package generic
* @version 2.8
* @since 2.8
* @define coll growable collection
- * @define Coll Growable
+ * @define Coll `Growable`
* @define add add
* @define Add add
*/
-trait Growable[-A] {
+trait Growable[-A] extends Clearable {
/** ${Add}s a single element to this $coll.
*
@@ -50,5 +50,5 @@ trait Growable[-A] {
/** Clears the $coll's contents. After this operation, the
* $coll is empty.
*/
- def clear()
+ def clear(): Unit
}
diff --git a/src/library/scala/collection/generic/ImmutableSortedMapFactory.scala b/src/library/scala/collection/generic/ImmutableSortedMapFactory.scala
index 93aae0e355..f415a52b4d 100644
--- a/src/library/scala/collection/generic/ImmutableSortedMapFactory.scala
+++ b/src/library/scala/collection/generic/ImmutableSortedMapFactory.scala
@@ -16,7 +16,7 @@ import language.higherKinds
/** A template for companion objects of `SortedMap` and subclasses thereof.
*
* @since 2.8
- * @define Coll SortedMap
+ * @define Coll `SortedMap`
* @define coll sorted map
* @define factoryInfo
* This object provides a set of operations needed to create sorted maps of type `$Coll`.
diff --git a/src/library/scala/collection/generic/ImmutableSortedSetFactory.scala b/src/library/scala/collection/generic/ImmutableSortedSetFactory.scala
index 67fb72270c..1317bb4796 100644
--- a/src/library/scala/collection/generic/ImmutableSortedSetFactory.scala
+++ b/src/library/scala/collection/generic/ImmutableSortedSetFactory.scala
@@ -16,8 +16,8 @@ import language.higherKinds
/** A template for companion objects of `SortedSet` and subclasses thereof.
*
* @since 2.8
- * @define Coll immutable.SortedSet
- * @define coll immutable sorted
+ * @define Coll `immutable.SortedSet`
+ * @define coll immutable sorted set
* @define factoryInfo
* This object provides a set of operations needed to create sorted sets of type `$Coll`.
* @author Martin Odersky
diff --git a/src/library/scala/collection/generic/MutableSortedSetFactory.scala b/src/library/scala/collection/generic/MutableSortedSetFactory.scala
index b0dd23ee1a..0e90ed999c 100644
--- a/src/library/scala/collection/generic/MutableSortedSetFactory.scala
+++ b/src/library/scala/collection/generic/MutableSortedSetFactory.scala
@@ -13,8 +13,8 @@ import scala.collection.mutable.{ Builder, GrowingBuilder }
import language.higherKinds
/**
- * @define Coll mutable.SortedSet
- * @define coll mutable sorted
+ * @define Coll `mutable.SortedSet`
+ * @define coll mutable sorted set
*
* @author Lucien Pereira
*
diff --git a/src/library/scala/collection/generic/ParFactory.scala b/src/library/scala/collection/generic/ParFactory.scala
index 0829ba6616..41dca8fbe9 100644
--- a/src/library/scala/collection/generic/ParFactory.scala
+++ b/src/library/scala/collection/generic/ParFactory.scala
@@ -17,7 +17,7 @@ import language.higherKinds
* operations to create `$Coll` objects.
*
* @define coll parallel collection
- * @define Coll ParIterable
+ * @define Coll `ParIterable`
* @since 2.8
*/
abstract class ParFactory[CC[X] <: ParIterable[X] with GenericParTemplate[X, CC]]
diff --git a/src/library/scala/collection/generic/ParMapFactory.scala b/src/library/scala/collection/generic/ParMapFactory.scala
index c05ab73431..5aedf67924 100644
--- a/src/library/scala/collection/generic/ParMapFactory.scala
+++ b/src/library/scala/collection/generic/ParMapFactory.scala
@@ -19,7 +19,7 @@ import language.higherKinds
* to create `$Coll` objects.
*
* @define coll parallel map
- * @define Coll ParMap
+ * @define Coll `ParMap`
* @author Aleksandar Prokopec
* @since 2.8
*/
diff --git a/src/library/scala/collection/generic/Shrinkable.scala b/src/library/scala/collection/generic/Shrinkable.scala
index 88c7ce3a3d..0c9dafefb1 100644
--- a/src/library/scala/collection/generic/Shrinkable.scala
+++ b/src/library/scala/collection/generic/Shrinkable.scala
@@ -17,7 +17,7 @@ package generic
* @version 2.8
* @since 2.8
* @define coll shrinkable collection
- * @define Coll Shrinkable
+ * @define Coll `Shrinkable`
*/
trait Shrinkable[-A] {
diff --git a/src/library/scala/collection/immutable/BitSet.scala b/src/library/scala/collection/immutable/BitSet.scala
index 870d5534dc..1b676e2d2f 100644
--- a/src/library/scala/collection/immutable/BitSet.scala
+++ b/src/library/scala/collection/immutable/BitSet.scala
@@ -20,7 +20,7 @@ import mutable.{ Builder, SetBuilder }
* @see [[http://docs.scala-lang.org/overviews/collections/concrete-immutable-collection-classes.html#immutable_bitsets "Scala's Collection Library overview"]]
* section on `Immutable BitSets` for more information.
*
- * @define Coll immutable.BitSet
+ * @define Coll `immutable.BitSet`
* @define coll immutable bitset
*/
@SerialVersionUID(1611436763290191562L)
@@ -63,7 +63,7 @@ abstract class BitSet extends scala.collection.AbstractSet[Int]
}
/** $factoryInfo
- * @define Coll immutable.BitSet
+ * @define Coll `immutable.BitSet`
* @define coll immutable bitset
*/
object BitSet extends BitSetFactory[BitSet] {
diff --git a/src/library/scala/collection/immutable/GenSeq.scala.disabled b/src/library/scala/collection/immutable/GenSeq.scala.disabled
index 5b59418b9f..b8bc420ec3 100644
--- a/src/library/scala/collection/immutable/GenSeq.scala.disabled
+++ b/src/library/scala/collection/immutable/GenSeq.scala.disabled
@@ -25,7 +25,7 @@ import mutable.Builder
*
* The class adds an `update` method to `collection.Seq`.
*
- * @define Coll mutable.Seq
+ * @define Coll `mutable.Seq`
* @define coll mutable sequence
*/
trait GenSeq[+A] extends GenIterable[A]
diff --git a/src/library/scala/collection/immutable/GenSet.scala.disabled b/src/library/scala/collection/immutable/GenSet.scala.disabled
index dc921b5245..828219580e 100644
--- a/src/library/scala/collection/immutable/GenSet.scala.disabled
+++ b/src/library/scala/collection/immutable/GenSet.scala.disabled
@@ -24,7 +24,7 @@ import mutable.Builder
*
* @since 1.0
* @author Matthias Zenger
- * @define Coll mutable.Set
+ * @define Coll `mutable.Set`
* @define coll mutable set
*/
trait GenSet[A] extends GenIterable[A]
diff --git a/src/library/scala/collection/immutable/HashMap.scala b/src/library/scala/collection/immutable/HashMap.scala
index 6b11371bec..13a0febfee 100644
--- a/src/library/scala/collection/immutable/HashMap.scala
+++ b/src/library/scala/collection/immutable/HashMap.scala
@@ -27,7 +27,7 @@ import parallel.immutable.ParHashMap
* @since 2.3
* @see [[http://docs.scala-lang.org/overviews/collections/concrete-immutable-collection-classes.html#hash_tries "Scala's Collection Library overview"]]
* section on `Hash Tries` for more information.
- * @define Coll immutable.HashMap
+ * @define Coll `immutable.HashMap`
* @define coll immutable hash map
* @define mayNotTerminateInf
* @define willNotTerminateInf
@@ -96,7 +96,7 @@ class HashMap[A, +B] extends AbstractMap[A, B]
}
/** $factoryInfo
- * @define Coll immutable.HashMap
+ * @define Coll `immutable.HashMap`
* @define coll immutable hash map
*
* @author Tiark Rompf
diff --git a/src/library/scala/collection/immutable/HashSet.scala b/src/library/scala/collection/immutable/HashSet.scala
index 79d2fb71cc..b956a4d838 100644
--- a/src/library/scala/collection/immutable/HashSet.scala
+++ b/src/library/scala/collection/immutable/HashSet.scala
@@ -26,7 +26,7 @@ import collection.parallel.immutable.ParHashSet
* @author Tiark Rompf
* @version 2.8
* @since 2.3
- * @define Coll immutable.HashSet
+ * @define Coll `immutable.HashSet`
* @define coll immutable hash set
*/
@SerialVersionUID(2L)
@@ -85,12 +85,12 @@ class HashSet[A] extends AbstractSet[A]
}
/** $factoryInfo
- * @define Coll immutable.HashSet
+ * @define Coll `immutable.HashSet`
* @define coll immutable hash set
*
* @author Tiark Rompf
* @since 2.3
- * @define Coll immutable.HashSet
+ * @define Coll `immutable.HashSet`
* @define coll immutable hash set
* @define mayNotTerminateInf
* @define willNotTerminateInf
diff --git a/src/library/scala/collection/immutable/IndexedSeq.scala b/src/library/scala/collection/immutable/IndexedSeq.scala
index e3939001d8..b37edc4254 100644
--- a/src/library/scala/collection/immutable/IndexedSeq.scala
+++ b/src/library/scala/collection/immutable/IndexedSeq.scala
@@ -29,7 +29,7 @@ trait IndexedSeq[+A] extends Seq[A]
/** $factoryInfo
* The current default implementation of a $Coll is a `Vector`.
* @define coll indexed sequence
- * @define Coll IndexedSeq
+ * @define Coll `IndexedSeq`
*/
object IndexedSeq extends SeqFactory[IndexedSeq] {
class Impl[A](buf: ArrayBuffer[A]) extends AbstractSeq[A] with IndexedSeq[A] with Serializable {
diff --git a/src/library/scala/collection/immutable/IntMap.scala b/src/library/scala/collection/immutable/IntMap.scala
index 3c9c0c2f24..039a57041c 100644
--- a/src/library/scala/collection/immutable/IntMap.scala
+++ b/src/library/scala/collection/immutable/IntMap.scala
@@ -36,7 +36,7 @@ import IntMapUtils._
/** A companion object for integer maps.
*
- * @define Coll IntMap
+ * @define Coll `IntMap`
* @define mapCanBuildFromInfo
* The standard `CanBuildFrom` instance for `$Coll` objects.
* The created value is an instance of class `MapCanBuildFrom`.
@@ -150,7 +150,7 @@ import IntMap._
* @tparam T type of the values associated with integer keys.
*
* @since 2.7
- * @define Coll immutable.IntMap
+ * @define Coll `immutable.IntMap`
* @define coll immutable integer map
* @define mayNotTerminateInf
* @define willNotTerminateInf
diff --git a/src/library/scala/collection/immutable/Iterable.scala b/src/library/scala/collection/immutable/Iterable.scala
index d5fca2bdff..a1390ba189 100644
--- a/src/library/scala/collection/immutable/Iterable.scala
+++ b/src/library/scala/collection/immutable/Iterable.scala
@@ -18,7 +18,7 @@ import parallel.immutable.ParIterable
/** A base trait for iterable collections that are guaranteed immutable.
* $iterableInfo
*
- * @define Coll immutable.Iterable
+ * @define Coll `immutable.Iterable`
* @define coll immutable iterable collection
*/
trait Iterable[+A] extends Traversable[A]
@@ -34,7 +34,7 @@ trait Iterable[+A] extends Traversable[A]
}
/** $factoryInfo
- * @define Coll immutable.Iterable
+ * @define Coll `immutable.Iterable`
* @define coll immutable iterable collection
*/
object Iterable extends TraversableFactory[Iterable] {
diff --git a/src/library/scala/collection/immutable/LinearSeq.scala b/src/library/scala/collection/immutable/LinearSeq.scala
index 536894c287..2d6986740a 100644
--- a/src/library/scala/collection/immutable/LinearSeq.scala
+++ b/src/library/scala/collection/immutable/LinearSeq.scala
@@ -29,7 +29,7 @@ trait LinearSeq[+A] extends Seq[A]
/** $factoryInfo
* The current default implementation of a $Coll is a `List`.
* @define coll immutable linear sequence
- * @define Coll immutable.LinearSeq
+ * @define Coll `immutable.LinearSeq`
*/
object LinearSeq extends SeqFactory[LinearSeq] {
implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, LinearSeq[A]] = ReusableCBF.asInstanceOf[GenericCanBuildFrom[A]]
diff --git a/src/library/scala/collection/immutable/List.scala b/src/library/scala/collection/immutable/List.scala
index 1b75c10113..b4c22c3b6c 100644
--- a/src/library/scala/collection/immutable/List.scala
+++ b/src/library/scala/collection/immutable/List.scala
@@ -141,7 +141,7 @@ sealed abstract class List[+A] extends AbstractSeq[A]
/** Builds a new list by applying a function to all elements of this list.
* Like `xs map f`, but returns `xs` unchanged if function
- * `f` maps all elements to themselves (wrt eq).
+ * `f` maps all elements to themselves (as determined by `eq`).
*
* @param f the function to apply to each element.
* @tparam B the element type of the returned collection.
@@ -382,7 +382,7 @@ final case class ::[B](private var hd: B, private[scala] var tl: List[B]) extend
/** $factoryInfo
* @define coll list
- * @define Coll List
+ * @define Coll `List`
*/
object List extends SeqFactory[List] {
diff --git a/src/library/scala/collection/immutable/LongMap.scala b/src/library/scala/collection/immutable/LongMap.scala
index 11b5d1e311..8a316f37de 100644
--- a/src/library/scala/collection/immutable/LongMap.scala
+++ b/src/library/scala/collection/immutable/LongMap.scala
@@ -36,7 +36,7 @@ import LongMapUtils._
/** A companion object for long maps.
*
- * @define Coll LongMap
+ * @define Coll `LongMap`
* @define mapCanBuildFromInfo
* The standard `CanBuildFrom` instance for `$Coll` objects.
* The created value is an instance of class `MapCanBuildFrom`.
@@ -147,7 +147,7 @@ import LongMap._;
* @tparam T type of the values associated with the long keys.
*
* @since 2.7
- * @define Coll immutable.LongMap
+ * @define Coll `immutable.LongMap`
* @define coll immutable long integer map
* @define mayNotTerminateInf
* @define willNotTerminateInf
diff --git a/src/library/scala/collection/immutable/Map.scala b/src/library/scala/collection/immutable/Map.scala
index bbefd983fd..e73da01ac4 100644
--- a/src/library/scala/collection/immutable/Map.scala
+++ b/src/library/scala/collection/immutable/Map.scala
@@ -66,7 +66,7 @@ trait Map[A, +B] extends Iterable[(A, B)]
}
/** $factoryInfo
- * @define Coll immutable.Map
+ * @define Coll `immutable.Map`
* @define coll immutable map
*/
object Map extends ImmutableMapFactory[Map] {
diff --git a/src/library/scala/collection/immutable/NumericRange.scala b/src/library/scala/collection/immutable/NumericRange.scala
index 0966fa035f..4c82d99c03 100644
--- a/src/library/scala/collection/immutable/NumericRange.scala
+++ b/src/library/scala/collection/immutable/NumericRange.scala
@@ -34,7 +34,7 @@ import generic._
*
* @author Paul Phillips
* @version 2.8
- * @define Coll NumericRange
+ * @define Coll `NumericRange`
* @define coll numeric range
* @define mayNotTerminateInf
* @define willNotTerminateInf
diff --git a/src/library/scala/collection/immutable/PagedSeq.scala b/src/library/scala/collection/immutable/PagedSeq.scala
index 68c75ee586..94953ce38b 100644
--- a/src/library/scala/collection/immutable/PagedSeq.scala
+++ b/src/library/scala/collection/immutable/PagedSeq.scala
@@ -119,7 +119,7 @@ import PagedSeq._
*
* @author Martin Odersky
* @since 2.7
- * @define Coll PagedSeq
+ * @define Coll `PagedSeq`
* @define coll paged sequence
* @define mayNotTerminateInf
* @define willNotTerminateInf
diff --git a/src/library/scala/collection/immutable/Queue.scala b/src/library/scala/collection/immutable/Queue.scala
index da04446281..e980dda847 100644
--- a/src/library/scala/collection/immutable/Queue.scala
+++ b/src/library/scala/collection/immutable/Queue.scala
@@ -30,7 +30,7 @@ import annotation.tailrec
* @see [[http://docs.scala-lang.org/overviews/collections/concrete-immutable-collection-classes.html#immutable_queues "Scala's Collection Library overview"]]
* section on `Immutable Queues` for more information.
*
- * @define Coll immutable.Queue
+ * @define Coll `immutable.Queue`
* @define coll immutable queue
* @define mayNotTerminateInf
* @define willNotTerminateInf
@@ -131,7 +131,7 @@ class Queue[+A] protected(protected val in: List[A], protected val out: List[A])
}
/** $factoryInfo
- * @define Coll immutable.Queue
+ * @define Coll `immutable.Queue`
* @define coll immutable queue
*/
object Queue extends SeqFactory[Queue] {
diff --git a/src/library/scala/collection/immutable/Seq.scala b/src/library/scala/collection/immutable/Seq.scala
index 882ca12612..1104eb1b4f 100644
--- a/src/library/scala/collection/immutable/Seq.scala
+++ b/src/library/scala/collection/immutable/Seq.scala
@@ -19,7 +19,7 @@ import parallel.immutable.ParSeq
* that are guaranteed immutable.
*
* $seqInfo
- * @define Coll immutable.Seq
+ * @define Coll `immutable.Seq`
* @define coll immutable sequence
*/
trait Seq[+A] extends Iterable[A]
@@ -36,7 +36,7 @@ trait Seq[+A] extends Iterable[A]
}
/** $factoryInfo
- * @define Coll immutable.Seq
+ * @define Coll `immutable.Seq`
* @define coll immutable sequence
*/
object Seq extends SeqFactory[Seq] {
diff --git a/src/library/scala/collection/immutable/Set.scala b/src/library/scala/collection/immutable/Set.scala
index cd972d6c30..f783f2d562 100644
--- a/src/library/scala/collection/immutable/Set.scala
+++ b/src/library/scala/collection/immutable/Set.scala
@@ -21,7 +21,7 @@ import parallel.immutable.ParSet
* @since 1.0
* @author Matthias Zenger
* @author Martin Odersky
- * @define Coll immutable.Set
+ * @define Coll `immutable.Set`
* @define coll immutable set
*/
trait Set[A] extends Iterable[A]
@@ -38,7 +38,7 @@ trait Set[A] extends Iterable[A]
}
/** $factoryInfo
- * @define Coll immutable.Set
+ * @define Coll `immutable.Set`
* @define coll immutable set
*/
object Set extends ImmutableSetFactory[Set] {
diff --git a/src/library/scala/collection/immutable/SortedSet.scala b/src/library/scala/collection/immutable/SortedSet.scala
index e1637ce78b..62fa4e0335 100644
--- a/src/library/scala/collection/immutable/SortedSet.scala
+++ b/src/library/scala/collection/immutable/SortedSet.scala
@@ -21,7 +21,7 @@ import mutable.Builder
* @author Martin Odersky
* @version 2.8
* @since 2.4
- * @define Coll immutable.SortedSet
+ * @define Coll `immutable.SortedSet`
* @define coll immutable sorted set
*/
trait SortedSet[A] extends Set[A] with scala.collection.SortedSet[A] with SortedSetLike[A, SortedSet[A]] {
@@ -30,7 +30,7 @@ trait SortedSet[A] extends Set[A] with scala.collection.SortedSet[A] with Sorted
}
/** $factoryInfo
- * @define Coll immutable.SortedSet
+ * @define Coll `immutable.SortedSet`
* @define coll immutable sorted set
*/
object SortedSet extends ImmutableSortedSetFactory[SortedSet] {
diff --git a/src/library/scala/collection/immutable/Stack.scala b/src/library/scala/collection/immutable/Stack.scala
index 50fc2795c0..c63c1ce232 100644
--- a/src/library/scala/collection/immutable/Stack.scala
+++ b/src/library/scala/collection/immutable/Stack.scala
@@ -13,7 +13,7 @@ import generic._
import mutable.{ ArrayBuffer, Builder }
/** $factoryInfo
- * @define Coll immutable.Stack
+ * @define Coll `immutable.Stack`
* @define coll immutable stack
*/
object Stack extends SeqFactory[Stack] {
@@ -37,7 +37,7 @@ object Stack extends SeqFactory[Stack] {
* @see [[http://docs.scala-lang.org/overviews/collections/concrete-immutable-collection-classes.html#immutable_stacks "Scala's Collection Library overview"]]
* section on `Immutable stacks` for more information.
*
- * @define Coll immutable.Stack
+ * @define Coll `immutable.Stack`
* @define coll immutable stack
* @define orderDependent
* @define orderDependentFold
diff --git a/src/library/scala/collection/immutable/Stream.scala b/src/library/scala/collection/immutable/Stream.scala
index 2df4ed70c7..f3e7214c5f 100644
--- a/src/library/scala/collection/immutable/Stream.scala
+++ b/src/library/scala/collection/immutable/Stream.scala
@@ -177,7 +177,7 @@ import language.implicitConversions
* section on `Streams` for more information.
* @define naturalsEx def naturalsFrom(i: Int): Stream[Int] = i #:: naturalsFrom(i + 1)
- * @define Coll Stream
+ * @define Coll `Stream`
* @define coll stream
* @define orderDependent
* @define orderDependentFold
@@ -805,9 +805,9 @@ self =>
these
}
- /** Builds a new stream from this stream in which any duplicates (wrt to ==)
- * have been removed. Among duplicate elements, only the first one is
- * retained in the resulting `Stream`.
+ /** Builds a new stream from this stream in which any duplicates (as
+ * determined by `==`) have been removed. Among duplicate elements, only the
+ * first one is retained in the resulting `Stream`.
*
* @return A new `Stream` representing the result of applying distinctness to
* the original `Stream`.
diff --git a/src/library/scala/collection/immutable/StringLike.scala b/src/library/scala/collection/immutable/StringLike.scala
index 52032a1cde..d1605bf637 100644
--- a/src/library/scala/collection/immutable/StringLike.scala
+++ b/src/library/scala/collection/immutable/StringLike.scala
@@ -33,7 +33,7 @@ import StringLike._
* @tparam Repr The type of the actual collection inheriting `StringLike`.
*
* @since 2.8
- * @define Coll String
+ * @define Coll `String`
* @define coll string
* @define orderDependent
* @define orderDependentFold
diff --git a/src/library/scala/collection/immutable/StringOps.scala b/src/library/scala/collection/immutable/StringOps.scala
index 97609b4c4d..633821ecea 100644
--- a/src/library/scala/collection/immutable/StringOps.scala
+++ b/src/library/scala/collection/immutable/StringOps.scala
@@ -25,7 +25,7 @@ import mutable.StringBuilder
* @param repr the actual representation of this string operations object.
*
* @since 2.8
- * @define Coll StringOps
+ * @define Coll `StringOps`
* @define coll string
*/
final class StringOps(override val repr: String) extends AnyVal with StringLike[String] {
diff --git a/src/library/scala/collection/immutable/Traversable.scala b/src/library/scala/collection/immutable/Traversable.scala
index 7830b38d69..59d3b4e029 100644
--- a/src/library/scala/collection/immutable/Traversable.scala
+++ b/src/library/scala/collection/immutable/Traversable.scala
@@ -30,7 +30,7 @@ trait Traversable[+A] extends scala.collection.Traversable[A]
/** $factoryInfo
* The current default implementation of a $Coll is a `Vector`.
* @define coll immutable traversable collection
- * @define Coll immutable.Traversable
+ * @define Coll `immutable.Traversable`
*/
object Traversable extends TraversableFactory[Traversable] {
implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Traversable[A]] = ReusableCBF.asInstanceOf[GenericCanBuildFrom[A]]
diff --git a/src/library/scala/collection/immutable/TreeSet.scala b/src/library/scala/collection/immutable/TreeSet.scala
index 1b3d72ceb7..882e828c5b 100644
--- a/src/library/scala/collection/immutable/TreeSet.scala
+++ b/src/library/scala/collection/immutable/TreeSet.scala
@@ -16,7 +16,7 @@ import immutable.{RedBlackTree => RB}
import mutable.{ Builder, SetBuilder }
/** $factoryInfo
- * @define Coll immutable.TreeSet
+ * @define Coll `immutable.TreeSet`
* @define coll immutable tree set
*/
object TreeSet extends ImmutableSortedSetFactory[TreeSet] {
@@ -40,7 +40,7 @@ object TreeSet extends ImmutableSortedSetFactory[TreeSet] {
* @see [[http://docs.scala-lang.org/overviews/collections/concrete-immutable-collection-classes.html#redblack_trees "Scala's Collection Library overview"]]
* section on `Red-Black Trees` for more information.
*
- * @define Coll immutable.TreeSet
+ * @define Coll `immutable.TreeSet`
* @define coll immutable tree set
* @define orderDependent
* @define orderDependentFold
diff --git a/src/library/scala/collection/immutable/Vector.scala b/src/library/scala/collection/immutable/Vector.scala
index 55c31feec2..1395a8f52d 100644
--- a/src/library/scala/collection/immutable/Vector.scala
+++ b/src/library/scala/collection/immutable/Vector.scala
@@ -40,7 +40,7 @@ object Vector extends SeqFactory[Vector] {
*
* @tparam A the element type
*
- * @define Coll Vector
+ * @define Coll `Vector`
* @define coll vector
* @define thatinfo the class of the returned collection. In the standard library configuration,
* `That` is always `Vector[B]` because an implicit of type `CanBuildFrom[Vector, B, That]`
diff --git a/src/library/scala/collection/immutable/WrappedString.scala b/src/library/scala/collection/immutable/WrappedString.scala
index de8aeea7e1..aa7e5b3c4a 100644
--- a/src/library/scala/collection/immutable/WrappedString.scala
+++ b/src/library/scala/collection/immutable/WrappedString.scala
@@ -25,7 +25,7 @@ import mutable.{Builder, StringBuilder}
* @param self a string contained within this wrapped string
*
* @since 2.8
- * @define Coll WrappedString
+ * @define Coll `WrappedString`
* @define coll wrapped string
*/
class WrappedString(val self: String) extends AbstractSeq[Char] with IndexedSeq[Char] with StringLike[WrappedString] {
diff --git a/src/library/scala/collection/mutable/ArrayBuffer.scala b/src/library/scala/collection/mutable/ArrayBuffer.scala
index bfdc08536c..3034fc2bce 100644
--- a/src/library/scala/collection/mutable/ArrayBuffer.scala
+++ b/src/library/scala/collection/mutable/ArrayBuffer.scala
@@ -29,7 +29,7 @@ import parallel.mutable.ParArray
*
* @tparam A the type of this arraybuffer's elements.
*
- * @define Coll ArrayBuffer
+ * @define Coll `ArrayBuffer`
* @define coll arraybuffer
* @define thatinfo the class of the returned collection. In the standard library configuration,
* `That` is always `ArrayBuffer[B]` because an implicit of type `CanBuildFrom[ArrayBuffer, B, ArrayBuffer[B]]`
@@ -187,7 +187,7 @@ class ArrayBuffer[A](override protected val initialSize: Int)
*
* $factoryInfo
* @define coll array buffer
- * @define Coll ArrayBuffer
+ * @define Coll `ArrayBuffer`
*/
object ArrayBuffer extends SeqFactory[ArrayBuffer] {
/** $genericCanBuildFromInfo */
diff --git a/src/library/scala/collection/mutable/ArrayLike.scala b/src/library/scala/collection/mutable/ArrayLike.scala
index 23d36252d2..04601845c4 100644
--- a/src/library/scala/collection/mutable/ArrayLike.scala
+++ b/src/library/scala/collection/mutable/ArrayLike.scala
@@ -18,7 +18,7 @@ import generic._
* @tparam A type of the elements contained in the array like object.
* @tparam Repr the type of the actual collection containing the elements.
*
- * @define Coll ArrayLike
+ * @define Coll `ArrayLike`
* @version 2.8
* @since 2.8
*/
diff --git a/src/library/scala/collection/mutable/ArrayOps.scala b/src/library/scala/collection/mutable/ArrayOps.scala
index 5f0e1e1071..57e81fdb9c 100644
--- a/src/library/scala/collection/mutable/ArrayOps.scala
+++ b/src/library/scala/collection/mutable/ArrayOps.scala
@@ -30,7 +30,7 @@ import parallel.mutable.ParArray
*
* @tparam T type of the elements contained in this array.
*
- * @define Coll ArrayOps
+ * @define Coll `ArrayOps`
* @define orderDependent
* @define orderDependentFold
* @define mayNotTerminateInf
diff --git a/src/library/scala/collection/mutable/ArraySeq.scala b/src/library/scala/collection/mutable/ArraySeq.scala
index cb86c416fe..d0eaee348b 100644
--- a/src/library/scala/collection/mutable/ArraySeq.scala
+++ b/src/library/scala/collection/mutable/ArraySeq.scala
@@ -27,7 +27,7 @@ import parallel.mutable.ParArray
* @tparam A type of the elements contained in this array sequence.
* @param length the length of the underlying array.
*
- * @define Coll ArraySeq
+ * @define Coll `ArraySeq`
* @define coll array sequence
* @define thatinfo the class of the returned collection. In the standard library configuration,
* `That` is always `ArraySeq[B]` because an implicit of type `CanBuildFrom[ArraySeq, B, ArraySeq[B]]`
@@ -93,7 +93,7 @@ extends AbstractSeq[A]
/** $factoryInfo
* @define coll array sequence
- * @define Coll ArraySeq
+ * @define Coll `ArraySeq`
*/
object ArraySeq extends SeqFactory[ArraySeq] {
/** $genericCanBuildFromInfo */
diff --git a/src/library/scala/collection/mutable/ArrayStack.scala b/src/library/scala/collection/mutable/ArrayStack.scala
index b3a0534826..04a318d0c3 100644
--- a/src/library/scala/collection/mutable/ArrayStack.scala
+++ b/src/library/scala/collection/mutable/ArrayStack.scala
@@ -15,7 +15,7 @@ import generic._
*
* $factoryInfo
* @define coll array stack
- * @define Coll ArrayStack
+ * @define Coll `ArrayStack`
*/
object ArrayStack extends SeqFactory[ArrayStack] {
implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, ArrayStack[A]] = ReusableCBF.asInstanceOf[GenericCanBuildFrom[A]]
@@ -51,7 +51,7 @@ object ArrayStack extends SeqFactory[ArrayStack] {
*
* @tparam T type of the elements contained in this array stack.
*
- * @define Coll ArrayStack
+ * @define Coll `ArrayStack`
* @define coll array stack
* @define orderDependent
* @define orderDependentFold
diff --git a/src/library/scala/collection/mutable/BitSet.scala b/src/library/scala/collection/mutable/BitSet.scala
index 6b9673dae6..58b45aa2a2 100644
--- a/src/library/scala/collection/mutable/BitSet.scala
+++ b/src/library/scala/collection/mutable/BitSet.scala
@@ -21,7 +21,7 @@ import BitSetLike.{LogWL, updateArray}
* @see [[http://docs.scala-lang.org/overviews/collections/concrete-mutable-collection-classes.html#mutable_bitsets "Scala's Collection Library overview"]]
* section on `Mutable Bitsets` for more information.
*
- * @define Coll BitSet
+ * @define Coll `BitSet`
* @define coll bitset
* @define thatinfo the class of the returned collection. In the standard library configuration,
* `That` is always `BitSet[B]` because an implicit of type `CanBuildFrom[BitSet, B, BitSet]`
@@ -114,7 +114,7 @@ class BitSet(protected var elems: Array[Long]) extends AbstractSet[Int]
/** $factoryInfo
* @define coll bitset
- * @define Coll BitSet
+ * @define Coll `BitSet`
*/
object BitSet extends BitSetFactory[BitSet] {
def empty: BitSet = new BitSet
diff --git a/src/library/scala/collection/mutable/Buffer.scala b/src/library/scala/collection/mutable/Buffer.scala
index 7326d5ec5b..dd225cfab9 100644
--- a/src/library/scala/collection/mutable/Buffer.scala
+++ b/src/library/scala/collection/mutable/Buffer.scala
@@ -25,7 +25,7 @@ import generic._
*
* @tparam A type of the elements contained in this buffer.
*
- * @define Coll Buffer
+ * @define Coll `Buffer`
* @define coll buffer
*/
@cloneable
@@ -37,7 +37,7 @@ trait Buffer[A] extends Seq[A]
/** $factoryInfo
* @define coll buffer
- * @define Coll Buffer
+ * @define Coll `Buffer`
*/
object Buffer extends SeqFactory[Buffer] {
implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Buffer[A]] = ReusableCBF.asInstanceOf[GenericCanBuildFrom[A]]
diff --git a/src/library/scala/collection/mutable/BufferProxy.scala b/src/library/scala/collection/mutable/BufferProxy.scala
index 6a6bdd0077..aa1b20d240 100644
--- a/src/library/scala/collection/mutable/BufferProxy.scala
+++ b/src/library/scala/collection/mutable/BufferProxy.scala
@@ -25,7 +25,7 @@ import script._
*
* @tparam A type of the elements the buffer proxy contains.
*
- * @define Coll BufferProxy
+ * @define Coll `BufferProxy`
* @define coll buffer proxy
*/
trait BufferProxy[A] extends Buffer[A] with Proxy {
diff --git a/src/library/scala/collection/mutable/Builder.scala b/src/library/scala/collection/mutable/Builder.scala
index 44cc1c8582..bbf4f5889d 100644
--- a/src/library/scala/collection/mutable/Builder.scala
+++ b/src/library/scala/collection/mutable/Builder.scala
@@ -100,6 +100,8 @@ trait Builder[-Elem, +To] extends Growable[Elem] {
def +=(x: Elem): this.type = { self += x; this }
def clear() = self.clear()
override def ++=(xs: TraversableOnce[Elem]): this.type = { self ++= xs; this }
+ override def sizeHint(size: Int) = self.sizeHint(size)
+ override def sizeHintBounded(size: Int, boundColl: TraversableLike[_, _]) = self.sizeHintBounded(size, boundColl)
def result: NewTo = f(self.result)
}
}
diff --git a/src/library/scala/collection/mutable/ConcurrentMap.scala b/src/library/scala/collection/mutable/ConcurrentMap.scala
index f2b44d6737..ad6b609862 100644
--- a/src/library/scala/collection/mutable/ConcurrentMap.scala
+++ b/src/library/scala/collection/mutable/ConcurrentMap.scala
@@ -20,7 +20,7 @@ package mutable
* @tparam A the key type of the map
* @tparam B the value type of the map
*
- * @define Coll ConcurrentMap
+ * @define Coll `ConcurrentMap`
* @define coll concurrent map
* @define concurrentmapinfo
* This is a base trait for all Scala concurrent map implementations. It
diff --git a/src/library/scala/collection/mutable/DoubleLinkedList.scala b/src/library/scala/collection/mutable/DoubleLinkedList.scala
index 49378a4f4e..cba4e9725e 100644
--- a/src/library/scala/collection/mutable/DoubleLinkedList.scala
+++ b/src/library/scala/collection/mutable/DoubleLinkedList.scala
@@ -26,7 +26,7 @@ import generic._
*
* @tparam A the type of the elements contained in this double linked list.
*
- * @define Coll DoubleLinkedList
+ * @define Coll `DoubleLinkedList`
* @define coll double linked list
* @define thatinfo the class of the returned collection. In the standard library configuration,
* `That` is always `DoubleLinkedList[B]` because an implicit of type `CanBuildFrom[DoubleLinkedList, B, DoubleLinkedList[B]]`
@@ -67,7 +67,7 @@ class DoubleLinkedList[A]() extends AbstractSeq[A]
/** $factoryInfo
* @define coll double linked list
- * @define Coll DoubleLinkedList
+ * @define Coll `DoubleLinkedList`
*/
object DoubleLinkedList extends SeqFactory[DoubleLinkedList] {
/** $genericCanBuildFromInfo */
diff --git a/src/library/scala/collection/mutable/DoubleLinkedListLike.scala b/src/library/scala/collection/mutable/DoubleLinkedListLike.scala
index dfb70beeda..ebccacf976 100644
--- a/src/library/scala/collection/mutable/DoubleLinkedListLike.scala
+++ b/src/library/scala/collection/mutable/DoubleLinkedListLike.scala
@@ -52,7 +52,7 @@ import annotation.migration
* @tparam A type of the elements contained in the double linked list
* @tparam This the type of the actual linked list holding the elements
*
- * @define Coll DoubleLinkedList
+ * @define Coll `DoubleLinkedList`
* @define coll double linked list
*/
trait DoubleLinkedListLike[A, This <: Seq[A] with DoubleLinkedListLike[A, This]] extends SeqLike[A, This] with LinkedListLike[A, This] { self =>
diff --git a/src/library/scala/collection/mutable/GenSeq.scala.disabled b/src/library/scala/collection/mutable/GenSeq.scala.disabled
index 85e4065183..53ec5acc34 100644
--- a/src/library/scala/collection/mutable/GenSeq.scala.disabled
+++ b/src/library/scala/collection/mutable/GenSeq.scala.disabled
@@ -24,7 +24,7 @@ import generic._
*
* The class adds an `update` method to `collection.Seq`.
*
- * @define Coll mutable.Seq
+ * @define Coll `mutable.Seq`
* @define coll mutable sequence
*/
trait GenSeq[A] extends GenIterable[A]
diff --git a/src/library/scala/collection/mutable/GenSet.scala.disabled b/src/library/scala/collection/mutable/GenSet.scala.disabled
index ac11e634e8..9080abaf38 100644
--- a/src/library/scala/collection/mutable/GenSet.scala.disabled
+++ b/src/library/scala/collection/mutable/GenSet.scala.disabled
@@ -24,7 +24,7 @@ import generic._
*
* @since 1.0
* @author Matthias Zenger
- * @define Coll mutable.Set
+ * @define Coll `mutable.Set`
* @define coll mutable set
*/
trait GenSet[A] extends GenIterable[A]
diff --git a/src/library/scala/collection/mutable/GrowingBuilder.scala b/src/library/scala/collection/mutable/GrowingBuilder.scala
index 0b7385194e..df63177b87 100644
--- a/src/library/scala/collection/mutable/GrowingBuilder.scala
+++ b/src/library/scala/collection/mutable/GrowingBuilder.scala
@@ -18,7 +18,7 @@ import generic._
* @version 2.8
* @since 2.8
*
- * @define Coll GrowingBuilder
+ * @define Coll `GrowingBuilder`
* @define coll growing builder
*/
class GrowingBuilder[Elem, To <: Growable[Elem]](empty: To) extends Builder[Elem, To] {
diff --git a/src/library/scala/collection/mutable/HashMap.scala b/src/library/scala/collection/mutable/HashMap.scala
index 65a10f4ba9..bf640cdb90 100644
--- a/src/library/scala/collection/mutable/HashMap.scala
+++ b/src/library/scala/collection/mutable/HashMap.scala
@@ -21,7 +21,7 @@ import scala.collection.parallel.mutable.ParHashMap
* @tparam A the type of the keys contained in this hash map.
* @tparam B the type of the values assigned to keys in this hash map.
*
- * @define Coll mutable.HashMap
+ * @define Coll `mutable.HashMap`
* @define coll mutable hash map
* @define thatinfo the class of the returned collection. In the standard library configuration,
* `That` is always `HashMap[A, B]` if the elements contained in the resulting collection are
@@ -138,7 +138,7 @@ extends AbstractMap[A, B]
}
/** $factoryInfo
- * @define Coll mutable.HashMap
+ * @define Coll `mutable.HashMap`
* @define coll mutable hash map
*/
object HashMap extends MutableMapFactory[HashMap] {
diff --git a/src/library/scala/collection/mutable/HashSet.scala b/src/library/scala/collection/mutable/HashSet.scala
index 8ed6b925aa..e040d1e421 100644
--- a/src/library/scala/collection/mutable/HashSet.scala
+++ b/src/library/scala/collection/mutable/HashSet.scala
@@ -25,7 +25,7 @@ import collection.parallel.mutable.ParHashSet
* @see [[http://docs.scala-lang.org/overviews/collections/concrete-mutable-collection-classes.html#hash_tables "Scala's Collection Library overview"]]
* section on `Hash Tables` for more information.
*
- * @define Coll mutable.HashSet
+ * @define Coll `mutable.HashSet`
* @define coll mutable hash set
* @define thatinfo the class of the returned collection. In the standard library configuration,
* `That` is always `HashSet[B]` because an implicit of type `CanBuildFrom[HashSet, B, HashSet[B]]`
@@ -98,7 +98,7 @@ extends AbstractSet[A]
}
/** $factoryInfo
- * @define Coll mutable.HashSet
+ * @define Coll `mutable.HashSet`
* @define coll mutable hash set
*/
object HashSet extends MutableSetFactory[HashSet] {
diff --git a/src/library/scala/collection/mutable/HashTable.scala b/src/library/scala/collection/mutable/HashTable.scala
index 06b7d40bfc..a2f78dbde9 100644
--- a/src/library/scala/collection/mutable/HashTable.scala
+++ b/src/library/scala/collection/mutable/HashTable.scala
@@ -187,7 +187,7 @@ trait HashTable[A, Entry >: Null <: HashEntry[A, Entry]] extends HashTable.HashU
}
/** Avoid iterator for a 2x faster traversal. */
- protected final def foreachEntry[C](f: Entry => C) {
+ protected def foreachEntry[C](f: Entry => C) {
val iterTable = table
var idx = lastPopulatedIndex
var es = iterTable(idx)
diff --git a/src/library/scala/collection/mutable/IndexedSeq.scala b/src/library/scala/collection/mutable/IndexedSeq.scala
index 0e2e06df84..686f90c9e8 100644
--- a/src/library/scala/collection/mutable/IndexedSeq.scala
+++ b/src/library/scala/collection/mutable/IndexedSeq.scala
@@ -29,7 +29,7 @@ trait IndexedSeq[A] extends Seq[A]
/** $factoryInfo
* The current default implementation of a $Coll is an `ArrayBuffer`.
* @define coll mutable indexed sequence
- * @define Coll mutable.IndexedSeq
+ * @define Coll `mutable.IndexedSeq`
*/
object IndexedSeq extends SeqFactory[IndexedSeq] {
implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, IndexedSeq[A]] = ReusableCBF.asInstanceOf[GenericCanBuildFrom[A]]
diff --git a/src/library/scala/collection/mutable/IndexedSeqLike.scala b/src/library/scala/collection/mutable/IndexedSeqLike.scala
index 0c1df17ead..4bd5ea1e89 100644
--- a/src/library/scala/collection/mutable/IndexedSeqLike.scala
+++ b/src/library/scala/collection/mutable/IndexedSeqLike.scala
@@ -27,7 +27,7 @@ import generic._
* @tparam A the element type of the $coll
* @tparam Repr the type of the actual $coll containing the elements.
*
- * @define Coll IndexedSeq
+ * @define Coll `IndexedSeq`
* @define coll mutable indexed sequence
* @define indexedSeqInfo
* @author Martin Odersky
diff --git a/src/library/scala/collection/mutable/Iterable.scala b/src/library/scala/collection/mutable/Iterable.scala
index 54fe11f98c..3b5ee63ea3 100644
--- a/src/library/scala/collection/mutable/Iterable.scala
+++ b/src/library/scala/collection/mutable/Iterable.scala
@@ -29,7 +29,7 @@ trait Iterable[A] extends Traversable[A]
/** $factoryInfo
* The current default implementation of a $Coll is an `ArrayBuffer`.
* @define coll mutable iterable collection
- * @define Coll mutable.Iterable
+ * @define Coll `mutable.Iterable`
*/
object Iterable extends TraversableFactory[Iterable] {
implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Iterable[A]] = ReusableCBF.asInstanceOf[GenericCanBuildFrom[A]]
diff --git a/src/library/scala/collection/mutable/LinearSeq.scala b/src/library/scala/collection/mutable/LinearSeq.scala
index 522ebfd277..443b458342 100644
--- a/src/library/scala/collection/mutable/LinearSeq.scala
+++ b/src/library/scala/collection/mutable/LinearSeq.scala
@@ -17,7 +17,7 @@ import generic._
* that can be mutated.
* $linearSeqInfo
*
- * @define Coll LinearSeq
+ * @define Coll `LinearSeq`
* @define coll linear sequence
* @see [[http://docs.scala-lang.org/overviews/collections/concrete-mutable-collection-classes.html#mutable_lists "Scala's Collection Library overview"]]
* section on `Mutable Lists` for more information.
@@ -33,7 +33,7 @@ trait LinearSeq[A] extends Seq[A]
/** $factoryInfo
* The current default implementation of a $Coll is a `MutableList`.
* @define coll mutable linear sequence
- * @define Coll mutable.LinearSeq
+ * @define Coll `mutable.LinearSeq`
*/
object LinearSeq extends SeqFactory[LinearSeq] {
implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, LinearSeq[A]] = ReusableCBF.asInstanceOf[GenericCanBuildFrom[A]]
diff --git a/src/library/scala/collection/mutable/LinkedHashMap.scala b/src/library/scala/collection/mutable/LinkedHashMap.scala
index e4090637ec..4150cf9eba 100644
--- a/src/library/scala/collection/mutable/LinkedHashMap.scala
+++ b/src/library/scala/collection/mutable/LinkedHashMap.scala
@@ -14,7 +14,7 @@ package mutable
import generic._
/** $factoryInfo
- * @define Coll LinkedHashMap
+ * @define Coll `LinkedHashMap`
* @define coll linked hash map
*/
object LinkedHashMap extends MutableMapFactory[LinkedHashMap] {
@@ -28,7 +28,7 @@ object LinkedHashMap extends MutableMapFactory[LinkedHashMap] {
* @tparam A the type of the keys contained in this hash map.
* @tparam B the type of the values assigned to keys in this hash map.
*
- * @define Coll LinkedHashMap
+ * @define Coll `LinkedHashMap`
* @define coll linked hash map
* @define thatinfo the class of the returned collection. In the standard library configuration,
* `That` is always `LinkedHashMap[A, B]` if the elements contained in the resulting collection are
@@ -132,6 +132,14 @@ class LinkedHashMap[A, B] extends AbstractMap[A, B]
}
}
+ protected override def foreachEntry[C](f: Entry => C) {
+ var cur = firstEntry
+ while (cur ne null) {
+ f(cur)
+ cur = cur.later
+ }
+ }
+
override def clear() {
clearTable()
firstEntry = null
diff --git a/src/library/scala/collection/mutable/LinkedHashSet.scala b/src/library/scala/collection/mutable/LinkedHashSet.scala
index d2815cf9de..3f789f9fa2 100644
--- a/src/library/scala/collection/mutable/LinkedHashSet.scala
+++ b/src/library/scala/collection/mutable/LinkedHashSet.scala
@@ -24,7 +24,7 @@ import generic._
*
* @tparam A the type of the elements contained in this set.
*
- * @define Coll LinkedHashSet
+ * @define Coll `LinkedHashSet`
* @define coll linked hash set
* @define thatinfo the class of the returned collection. In the standard library configuration,
* `That` is always `LinkedHashSet[B]` because an implicit of type `CanBuildFrom[LinkedHashSet, B, LinkedHashSet[B]]`
@@ -87,7 +87,7 @@ class LinkedHashSet[A] extends AbstractSet[A]
}
/** $factoryInfo
- * @define Coll LinkedHashSet
+ * @define Coll `LinkedHashSet`
* @define coll linked hash set
*/
object LinkedHashSet extends MutableSetFactory[LinkedHashSet] {
diff --git a/src/library/scala/collection/mutable/LinkedList.scala b/src/library/scala/collection/mutable/LinkedList.scala
index 8510827697..335ddccf56 100644
--- a/src/library/scala/collection/mutable/LinkedList.scala
+++ b/src/library/scala/collection/mutable/LinkedList.scala
@@ -40,7 +40,7 @@ import generic._
*
* @constructor Creates an "empty" list, defined as a single node with no data element and next pointing to itself.
- * @define Coll LinkedList
+ * @define Coll `LinkedList`
* @define coll linked list
* @define thatinfo the class of the returned collection. In the standard library configuration,
* `That` is always `LinkedList[B]` because an implicit of type `CanBuildFrom[LinkedList, B, LinkedList[B]]`
@@ -109,7 +109,7 @@ class LinkedList[A]() extends AbstractSeq[A]
}
/** $factoryInfo
- * @define Coll LinkedList
+ * @define Coll `LinkedList`
* @define coll linked list
*/
object LinkedList extends SeqFactory[LinkedList] {
diff --git a/src/library/scala/collection/mutable/LinkedListLike.scala b/src/library/scala/collection/mutable/LinkedListLike.scala
index ebec31ca98..07a8501ca4 100644
--- a/src/library/scala/collection/mutable/LinkedListLike.scala
+++ b/src/library/scala/collection/mutable/LinkedListLike.scala
@@ -29,7 +29,7 @@ import annotation.tailrec
* @tparam A type of the elements contained in the linked list
* @tparam This the type of the actual linked list holding the elements
*
- * @define Coll LinkedList
+ * @define Coll `LinkedList`
* @define coll linked list
*
* @define singleLinkedListExample
diff --git a/src/library/scala/collection/mutable/ListBuffer.scala b/src/library/scala/collection/mutable/ListBuffer.scala
index 96e73522b6..5c580f9c09 100644
--- a/src/library/scala/collection/mutable/ListBuffer.scala
+++ b/src/library/scala/collection/mutable/ListBuffer.scala
@@ -27,7 +27,7 @@ import java.io._
*
* @tparam A the type of this list buffer's elements.
*
- * @define Coll ListBuffer
+ * @define Coll `ListBuffer`
* @define coll list buffer
* @define thatinfo the class of the returned collection. In the standard library configuration,
* `That` is always `ListBuffer[B]` because an implicit of type `CanBuildFrom[ListBuffer, B, ListBuffer[B]]`
@@ -425,7 +425,7 @@ final class ListBuffer[A]
}
/** $factoryInfo
- * @define Coll ListBuffer
+ * @define Coll `ListBuffer`
* @define coll list buffer
*/
object ListBuffer extends SeqFactory[ListBuffer] {
diff --git a/src/library/scala/collection/mutable/ListMap.scala b/src/library/scala/collection/mutable/ListMap.scala
index d8d60d1c9a..61810c4ddf 100644
--- a/src/library/scala/collection/mutable/ListMap.scala
+++ b/src/library/scala/collection/mutable/ListMap.scala
@@ -18,7 +18,7 @@ import generic._
* @tparam A the type of the keys contained in this list map.
* @tparam B the type of the values assigned to keys in this list map.
*
- * @define Coll mutable.ListMap
+ * @define Coll `mutable.ListMap`
* @define coll mutable list map
* @define thatinfo the class of the returned collection. In the standard library configuration,
* `That` is always `ListMap[A, B]` if the elements contained in the resulting collection are
@@ -60,7 +60,7 @@ extends AbstractMap[A, B]
}
/** $factoryInfo
- * @define Coll mutable.ListMap
+ * @define Coll `mutable.ListMap`
* @define coll mutable list map
*/
object ListMap extends MutableMapFactory[ListMap] {
diff --git a/src/library/scala/collection/mutable/Map.scala b/src/library/scala/collection/mutable/Map.scala
index 0d40a1c70d..207b3f3324 100644
--- a/src/library/scala/collection/mutable/Map.scala
+++ b/src/library/scala/collection/mutable/Map.scala
@@ -63,7 +63,7 @@ trait Map[A, B]
/** $factoryInfo
* The current default implementation of a $Coll is a `HashMap`.
* @define coll mutable map
- * @define Coll mutable.Map
+ * @define Coll `mutable.Map`
*/
object Map extends MutableMapFactory[Map] {
/** $canBuildFromInfo */
diff --git a/src/library/scala/collection/mutable/MultiMap.scala b/src/library/scala/collection/mutable/MultiMap.scala
index 0f298c4a8a..d21624759d 100644
--- a/src/library/scala/collection/mutable/MultiMap.scala
+++ b/src/library/scala/collection/mutable/MultiMap.scala
@@ -19,7 +19,7 @@ package mutable
* `B` objects.
*
* @define coll multimap
- * @define Coll MultiMap
+ * @define Coll `MultiMap`
* @author Matthias Zenger
* @author Martin Odersky
* @version 2.8
diff --git a/src/library/scala/collection/mutable/OpenHashMap.scala b/src/library/scala/collection/mutable/OpenHashMap.scala
index 87e5c061fa..2634deb819 100644
--- a/src/library/scala/collection/mutable/OpenHashMap.scala
+++ b/src/library/scala/collection/mutable/OpenHashMap.scala
@@ -10,7 +10,7 @@ package scala.collection
package mutable
/**
- * @define Coll OpenHashMap
+ * @define Coll `OpenHashMap`
* @define coll open hash map
*
* @since 2.7
@@ -42,7 +42,7 @@ object OpenHashMap {
* @author David MacIver
* @since 2.7
*
- * @define Coll OpenHashMap
+ * @define Coll `OpenHashMap`
* @define coll open hash map
* @define mayNotTerminateInf
* @define willNotTerminateInf
diff --git a/src/library/scala/collection/mutable/Queue.scala b/src/library/scala/collection/mutable/Queue.scala
index 77b1ae21cb..605d37aec6 100644
--- a/src/library/scala/collection/mutable/Queue.scala
+++ b/src/library/scala/collection/mutable/Queue.scala
@@ -23,7 +23,7 @@ import generic._
* @see [[http://docs.scala-lang.org/overviews/collections/concrete-mutable-collection-classes.html#mutable_queues "Scala's Collection Library overview"]]
* section on `Queues` for more information.
*
- * @define Coll mutable.Queue
+ * @define Coll `mutable.Queue`
* @define coll mutable queue
* @define orderDependent
* @define orderDependentFold
diff --git a/src/library/scala/collection/mutable/Seq.scala b/src/library/scala/collection/mutable/Seq.scala
index 89b930e36f..ceed76cf88 100644
--- a/src/library/scala/collection/mutable/Seq.scala
+++ b/src/library/scala/collection/mutable/Seq.scala
@@ -21,7 +21,7 @@ import generic._
*
* The class adds an `update` method to `collection.Seq`.
*
- * @define Coll mutable.Seq
+ * @define Coll `mutable.Seq`
* @define coll mutable sequence
*/
trait Seq[A] extends Iterable[A]
@@ -36,7 +36,7 @@ trait Seq[A] extends Iterable[A]
/** $factoryInfo
* The current default implementation of a $Coll is an `ArrayBuffer`.
* @define coll mutable sequence
- * @define Coll mutable.Seq
+ * @define Coll `mutable.Seq`
*/
object Seq extends SeqFactory[Seq] {
implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Seq[A]] = ReusableCBF.asInstanceOf[GenericCanBuildFrom[A]]
diff --git a/src/library/scala/collection/mutable/Set.scala b/src/library/scala/collection/mutable/Set.scala
index 744768e8dd..33a99e9474 100644
--- a/src/library/scala/collection/mutable/Set.scala
+++ b/src/library/scala/collection/mutable/Set.scala
@@ -19,7 +19,7 @@ import generic._
*
* @since 1.0
* @author Matthias Zenger
- * @define Coll mutable.Set
+ * @define Coll `mutable.Set`
* @define coll mutable set
*/
trait Set[A] extends Iterable[A]
@@ -34,7 +34,7 @@ trait Set[A] extends Iterable[A]
/** $factoryInfo
* The current default implementation of a $Coll is a `HashSet`.
* @define coll mutable set
- * @define Coll mutable.Set
+ * @define Coll `mutable.Set`
*/
object Set extends MutableSetFactory[Set] {
implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Set[A]] = setCanBuildFrom[A]
diff --git a/src/library/scala/collection/mutable/SortedSet.scala b/src/library/scala/collection/mutable/SortedSet.scala
index f41a51d3ef..78d12f3d64 100644
--- a/src/library/scala/collection/mutable/SortedSet.scala
+++ b/src/library/scala/collection/mutable/SortedSet.scala
@@ -14,7 +14,7 @@ import generic._
/**
* Base trait for mutable sorted set.
*
- * @define Coll mutable.SortedSet
+ * @define Coll `mutable.SortedSet`
* @define coll mutable sorted set
*
* @author Lucien Pereira
@@ -31,7 +31,7 @@ trait SortedSet[A] extends collection.SortedSet[A] with collection.SortedSetLike
/**
* A template for mutable sorted set companion objects.
*
- * @define Coll mutable.SortedSet
+ * @define Coll `mutable.SortedSet`
* @define coll mutable sorted set
* @define factoryInfo
* This object provides a set of operations needed to create sorted sets of type mutable.SortedSet.
diff --git a/src/library/scala/collection/mutable/Stack.scala b/src/library/scala/collection/mutable/Stack.scala
index b70df05c55..042eac517a 100644
--- a/src/library/scala/collection/mutable/Stack.scala
+++ b/src/library/scala/collection/mutable/Stack.scala
@@ -20,7 +20,7 @@ import annotation.migration
*
* $factoryInfo
* @define coll mutable stack
- * @define Coll mutable.Stack
+ * @define Coll `mutable.Stack`
*/
object Stack extends SeqFactory[Stack] {
class StackBuilder[A] extends Builder[A, Stack[A]] {
@@ -46,7 +46,7 @@ object Stack extends SeqFactory[Stack] {
* @since 1
* @see [[http://docs.scala-lang.org/overviews/collections/concrete-mutable-collection-classes.html#stacks "Scala's Collection Library overview"]]
* section on `Stacks` for more information.
- * @define Coll Stack
+ * @define Coll `Stack`
* @define coll stack
* @define orderDependent
* @define orderDependentFold
diff --git a/src/library/scala/collection/mutable/SynchronizedBuffer.scala b/src/library/scala/collection/mutable/SynchronizedBuffer.scala
index 23552e9d52..a14605d60a 100644
--- a/src/library/scala/collection/mutable/SynchronizedBuffer.scala
+++ b/src/library/scala/collection/mutable/SynchronizedBuffer.scala
@@ -21,7 +21,7 @@ import script._
* @author Matthias Zenger
* @version 1.0, 08/07/2003
* @since 1
- * @define Coll SynchronizedBuffer
+ * @define Coll `SynchronizedBuffer`
* @define coll synchronized buffer
*/
trait SynchronizedBuffer[A] extends Buffer[A] {
diff --git a/src/library/scala/collection/mutable/SynchronizedMap.scala b/src/library/scala/collection/mutable/SynchronizedMap.scala
index 6e3ae13ada..037b8ec5f5 100644
--- a/src/library/scala/collection/mutable/SynchronizedMap.scala
+++ b/src/library/scala/collection/mutable/SynchronizedMap.scala
@@ -22,7 +22,7 @@ import annotation.migration
* @author Matthias Zenger, Martin Odersky
* @version 2.0, 31/12/2006
* @since 1
- * @define Coll SynchronizedMap
+ * @define Coll `SynchronizedMap`
* @define coll synchronized map
*/
trait SynchronizedMap[A, B] extends Map[A, B] {
diff --git a/src/library/scala/collection/mutable/SynchronizedPriorityQueue.scala b/src/library/scala/collection/mutable/SynchronizedPriorityQueue.scala
index 159b8312b2..bc32537798 100644
--- a/src/library/scala/collection/mutable/SynchronizedPriorityQueue.scala
+++ b/src/library/scala/collection/mutable/SynchronizedPriorityQueue.scala
@@ -20,7 +20,7 @@ package mutable
* @author Matthias Zenger
* @version 1.0, 03/05/2004
* @since 1
- * @define Coll SynchronizedPriorityQueue
+ * @define Coll `SynchronizedPriorityQueue`
* @define coll synchronized priority queue
*/
class SynchronizedPriorityQueue[A](implicit ord: Ordering[A]) extends PriorityQueue[A] {
diff --git a/src/library/scala/collection/mutable/SynchronizedQueue.scala b/src/library/scala/collection/mutable/SynchronizedQueue.scala
index 56f74a5b9b..9e00c5d6fd 100644
--- a/src/library/scala/collection/mutable/SynchronizedQueue.scala
+++ b/src/library/scala/collection/mutable/SynchronizedQueue.scala
@@ -21,7 +21,7 @@ package mutable
* @author Matthias Zenger
* @version 1.0, 03/05/2004
* @since 1
- * @define Coll SynchronizedQueue
+ * @define Coll `SynchronizedQueue`
* @define coll synchronized queue
*/
class SynchronizedQueue[A] extends Queue[A] {
diff --git a/src/library/scala/collection/mutable/SynchronizedSet.scala b/src/library/scala/collection/mutable/SynchronizedSet.scala
index c945a859f3..c28764ff68 100644
--- a/src/library/scala/collection/mutable/SynchronizedSet.scala
+++ b/src/library/scala/collection/mutable/SynchronizedSet.scala
@@ -20,7 +20,7 @@ import script._
* @author Matthias Zenger
* @version 1.0, 08/07/2003
* @since 1
- * @define Coll SynchronizedSet
+ * @define Coll `SynchronizedSet`
* @define coll synchronized set
*/
trait SynchronizedSet[A] extends Set[A] {
diff --git a/src/library/scala/collection/mutable/SynchronizedStack.scala b/src/library/scala/collection/mutable/SynchronizedStack.scala
index a09ae21901..8363222295 100644
--- a/src/library/scala/collection/mutable/SynchronizedStack.scala
+++ b/src/library/scala/collection/mutable/SynchronizedStack.scala
@@ -21,7 +21,7 @@ package mutable
* @author Matthias Zenger
* @version 1.0, 03/05/2004
* @since 1
- * @define Coll SynchronizedStack
+ * @define Coll `SynchronizedStack`
* @define coll synchronized stack
*/
class SynchronizedStack[A] extends Stack[A] {
diff --git a/src/library/scala/collection/mutable/Traversable.scala b/src/library/scala/collection/mutable/Traversable.scala
index 04b67c0bad..28241fdec9 100644
--- a/src/library/scala/collection/mutable/Traversable.scala
+++ b/src/library/scala/collection/mutable/Traversable.scala
@@ -29,7 +29,7 @@ trait Traversable[A] extends scala.collection.Traversable[A]
/** $factoryInfo
* The current default implementation of a $Coll is an `ArrayBuffer`.
* @define coll mutable traversable collection
- * @define Coll mutable.Traversable
+ * @define Coll `mutable.Traversable`
*/
object Traversable extends TraversableFactory[Traversable] {
implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Traversable[A]] = ReusableCBF.asInstanceOf[GenericCanBuildFrom[A]]
diff --git a/src/library/scala/collection/mutable/TreeSet.scala b/src/library/scala/collection/mutable/TreeSet.scala
index 02ee811193..00675b9119 100644
--- a/src/library/scala/collection/mutable/TreeSet.scala
+++ b/src/library/scala/collection/mutable/TreeSet.scala
@@ -12,7 +12,7 @@ package mutable
import generic._
/**
- * @define Coll mutable.TreeSet
+ * @define Coll `mutable.TreeSet`
* @define coll mutable tree set
* @factoryInfo
* Companion object of TreeSet providing factory related utilities.
diff --git a/src/library/scala/collection/mutable/UnrolledBuffer.scala b/src/library/scala/collection/mutable/UnrolledBuffer.scala
index 889768d471..cd76c7de4e 100644
--- a/src/library/scala/collection/mutable/UnrolledBuffer.scala
+++ b/src/library/scala/collection/mutable/UnrolledBuffer.scala
@@ -36,7 +36,7 @@ import annotation.tailrec
* should still be avoided for such a purpose.
*
* @define coll unrolled buffer
- * @define Coll UnrolledBuffer
+ * @define Coll `UnrolledBuffer`
* @author Aleksandar Prokopec
*
*/
diff --git a/src/library/scala/collection/mutable/WeakHashMap.scala b/src/library/scala/collection/mutable/WeakHashMap.scala
index 4e09755acf..ec99197bb9 100644
--- a/src/library/scala/collection/mutable/WeakHashMap.scala
+++ b/src/library/scala/collection/mutable/WeakHashMap.scala
@@ -23,7 +23,7 @@ import convert.Wrappers._
* @see [[http://docs.scala-lang.org/overviews/collections/concrete-mutable-collection-classes.html#weak_hash_maps "Scala's Collection Library overview"]]
* section on `Weak Hash Maps` for more information.
*
- * @define Coll WeakHashMap
+ * @define Coll `WeakHashMap`
* @define coll weak hash map
* @define thatinfo the class of the returned collection. In the standard library configuration,
* `That` is always `WeakHashMap[A, B]` if the elements contained in the resulting collection are
@@ -43,7 +43,7 @@ class WeakHashMap[A, B] extends JMapWrapper[A, B](new java.util.WeakHashMap)
}
/** $factoryInfo
- * @define Coll WeakHashMap
+ * @define Coll `WeakHashMap`
* @define coll weak hash map
*/
object WeakHashMap extends MutableMapFactory[WeakHashMap] {
diff --git a/src/library/scala/collection/mutable/WrappedArray.scala b/src/library/scala/collection/mutable/WrappedArray.scala
index 9d170b2832..86317819a1 100644
--- a/src/library/scala/collection/mutable/WrappedArray.scala
+++ b/src/library/scala/collection/mutable/WrappedArray.scala
@@ -24,7 +24,7 @@ import scala.collection.parallel.mutable.ParArray
* @author Martin Odersky, Stephane Micheloud
* @version 1.0
* @since 2.8
- * @define Coll WrappedArray
+ * @define Coll `WrappedArray`
* @define coll wrapped array
* @define orderDependent
* @define orderDependentFold
diff --git a/src/library/scala/collection/parallel/ParIterable.scala b/src/library/scala/collection/parallel/ParIterable.scala
index 0b5faf15ee..0bd6abaf78 100644
--- a/src/library/scala/collection/parallel/ParIterable.scala
+++ b/src/library/scala/collection/parallel/ParIterable.scala
@@ -24,7 +24,7 @@ import scala.collection.parallel.mutable.ParArray
* @author Aleksandar Prokopec
* @since 2.9
*
- * @define Coll ParIterable
+ * @define Coll `ParIterable`
* @define coll parallel iterable
*/
trait ParIterable[+T]
diff --git a/src/library/scala/collection/parallel/ParIterableLike.scala b/src/library/scala/collection/parallel/ParIterableLike.scala
index 014b9b1a42..4cb229fc0f 100644
--- a/src/library/scala/collection/parallel/ParIterableLike.scala
+++ b/src/library/scala/collection/parallel/ParIterableLike.scala
@@ -178,10 +178,30 @@ self: ParIterableLike[T, Repr, Sequential] =>
def repr: Repr = this.asInstanceOf[Repr]
+ final def isTraversableAgain = true
+
def hasDefiniteSize = true
+ def isEmpty = size == 0
+
def nonEmpty = size != 0
-
+
+ def head = iterator.next
+
+ def headOption = if (nonEmpty) Some(head) else None
+
+ def tail = drop(1)
+
+ def last = {
+ var lst = head
+ for (x <- this.seq) lst = x
+ lst
+ }
+
+ def lastOption = if (nonEmpty) Some(last) else None
+
+ def init = take(size - 1)
+
/** Creates a new parallel iterator used to traverse the elements of this parallel collection.
* This iterator is more specific than the iterator of the returned by `iterator`, and augmented
* with additional accessor and transformer methods.
diff --git a/src/library/scala/collection/parallel/immutable/ParHashMap.scala b/src/library/scala/collection/parallel/immutable/ParHashMap.scala
index e630a9dbed..ad882390c8 100644
--- a/src/library/scala/collection/parallel/immutable/ParHashMap.scala
+++ b/src/library/scala/collection/parallel/immutable/ParHashMap.scala
@@ -39,7 +39,7 @@ import collection.parallel.Task
* @see [[http://docs.scala-lang.org/overviews/parallel-collections/concrete-parallel-collections.html#parallel_hash_tries Scala's Parallel Collections Library overview]]
* section on Parallel Hash Tries for more information.
*
- * @define Coll immutable.ParHashMap
+ * @define Coll `immutable.ParHashMap`
* @define coll immutable parallel hash map
*/
@SerialVersionUID(1L)
@@ -140,7 +140,7 @@ self =>
/** $factoryInfo
- * @define Coll immutable.ParHashMap
+ * @define Coll `immutable.ParHashMap`
* @define coll immutable parallel hash map
*/
object ParHashMap extends ParMapFactory[ParHashMap] {
diff --git a/src/library/scala/collection/parallel/immutable/ParHashSet.scala b/src/library/scala/collection/parallel/immutable/ParHashSet.scala
index 084637c5dc..d1899601d7 100644
--- a/src/library/scala/collection/parallel/immutable/ParHashSet.scala
+++ b/src/library/scala/collection/parallel/immutable/ParHashSet.scala
@@ -38,7 +38,7 @@ import collection.parallel.Task
* @see [[http://docs.scala-lang.org/overviews/parallel-collections/concrete-parallel-collections.html#parallel_hash_tries Scala's Parallel Collections Library overview]]
* section on Parallel Hash Tries for more information.
*
- * @define Coll immutable.ParHashSet
+ * @define Coll `immutable.ParHashSet`
* @define coll immutable parallel hash set
*/
@SerialVersionUID(1L)
@@ -118,7 +118,7 @@ self =>
/** $factoryInfo
- * @define Coll immutable.ParHashSet
+ * @define Coll `immutable.ParHashSet`
* @define coll immutable parallel hash set
*/
object ParHashSet extends ParSetFactory[ParHashSet] {
diff --git a/src/library/scala/collection/parallel/immutable/ParNumericRange.scala.disabled b/src/library/scala/collection/parallel/immutable/ParNumericRange.scala.disabled
index fb411ec0ac..04bc8b8d29 100644
--- a/src/library/scala/collection/parallel/immutable/ParNumericRange.scala.disabled
+++ b/src/library/scala/collection/parallel/immutable/ParNumericRange.scala.disabled
@@ -29,7 +29,7 @@ import scala.collection.parallel.ParIterableIterator
* @author Aleksandar Prokopec
* @since 2.9
*
- * @define Coll immutable.ParRange
+ * @define Coll `immutable.ParRange`
* @define coll immutable parallel range
*/
@SerialVersionUID(1L)
diff --git a/src/library/scala/collection/parallel/immutable/ParRange.scala b/src/library/scala/collection/parallel/immutable/ParRange.scala
index 277fd5fdd3..9553704caa 100644
--- a/src/library/scala/collection/parallel/immutable/ParRange.scala
+++ b/src/library/scala/collection/parallel/immutable/ParRange.scala
@@ -28,7 +28,7 @@ import scala.collection.Iterator
* @see [[http://docs.scala-lang.org/overviews/parallel-collections/concrete-parallel-collections.html#parallel_range Scala's Parallel Collections Library overview]]
* section on `ParRange` for more information.
*
- * @define Coll immutable.ParRange
+ * @define Coll `immutable.ParRange`
* @define coll immutable parallel range
*/
@SerialVersionUID(1L)
diff --git a/src/library/scala/collection/parallel/immutable/ParSeq.scala b/src/library/scala/collection/parallel/immutable/ParSeq.scala
index bf3d3a5aa8..dde6533c82 100644
--- a/src/library/scala/collection/parallel/immutable/ParSeq.scala
+++ b/src/library/scala/collection/parallel/immutable/ParSeq.scala
@@ -24,7 +24,7 @@ import scala.collection.GenSeq
/** An immutable variant of `ParSeq`.
*
- * @define Coll mutable.ParSeq
+ * @define Coll `mutable.ParSeq`
* @define coll mutable parallel sequence
*/
trait ParSeq[+T]
@@ -40,7 +40,7 @@ extends collection/*.immutable*/.GenSeq[T]
/** $factoryInfo
- * @define Coll mutable.ParSeq
+ * @define Coll `mutable.ParSeq`
* @define coll mutable parallel sequence
*/
object ParSeq extends ParFactory[ParSeq] {
diff --git a/src/library/scala/collection/parallel/immutable/ParSet.scala b/src/library/scala/collection/parallel/immutable/ParSet.scala
index d64858ed10..40429280ac 100644
--- a/src/library/scala/collection/parallel/immutable/ParSet.scala
+++ b/src/library/scala/collection/parallel/immutable/ParSet.scala
@@ -16,7 +16,7 @@ import scala.collection.parallel.Combiner
/** An immutable variant of `ParSet`.
*
- * @define Coll mutable.ParSet
+ * @define Coll `mutable.ParSet`
* @define coll mutable parallel set
*/
trait ParSet[T]
@@ -38,7 +38,7 @@ self =>
}
/** $factoryInfo
- * @define Coll mutable.ParSet
+ * @define Coll `mutable.ParSet`
* @define coll mutable parallel set
*/
object ParSet extends ParSetFactory[ParSet] {
diff --git a/src/library/scala/collection/parallel/immutable/ParVector.scala b/src/library/scala/collection/parallel/immutable/ParVector.scala
index 8baa84b77c..1ece663a1d 100644
--- a/src/library/scala/collection/parallel/immutable/ParVector.scala
+++ b/src/library/scala/collection/parallel/immutable/ParVector.scala
@@ -37,7 +37,7 @@ import immutable.VectorIterator
* @see [[http://docs.scala-lang.org/overviews/parallel-collections/concrete-parallel-collections.html#parallel_vector Scala's Parallel Collections Library overview]]
* section on `ParVector` for more information.
*
- * @define Coll immutable.ParVector
+ * @define Coll `immutable.ParVector`
* @define coll immutable parallel vector
*/
class ParVector[+T](private[this] val vector: Vector[T])
@@ -86,7 +86,7 @@ extends ParSeq[T]
/** $factoryInfo
- * @define Coll immutable.ParVector
+ * @define Coll `immutable.ParVector`
* @define coll immutable parallel vector
*/
object ParVector extends ParFactory[ParVector] {
diff --git a/src/library/scala/collection/parallel/mutable/ParArray.scala b/src/library/scala/collection/parallel/mutable/ParArray.scala
index 92ba701f7c..29d84408db 100644
--- a/src/library/scala/collection/parallel/mutable/ParArray.scala
+++ b/src/library/scala/collection/parallel/mutable/ParArray.scala
@@ -49,7 +49,7 @@ import scala.collection.GenTraversableOnce
* @see [[http://docs.scala-lang.org/overviews/parallel-collections/concrete-parallel-collections.html#parallel_array Scala's Parallel Collections Library overview]]
* section on `ParArray` for more information.
*
- * @define Coll ParArray
+ * @define Coll `ParArray`
* @define coll parallel array
*
*/
@@ -685,7 +685,7 @@ self =>
/** $factoryInfo
- * @define Coll mutable.ParArray
+ * @define Coll `mutable.ParArray`
* @define coll parallel array
*/
object ParArray extends ParFactory[ParArray] {
diff --git a/src/library/scala/collection/parallel/mutable/ParFlatHashTable.scala b/src/library/scala/collection/parallel/mutable/ParFlatHashTable.scala
index 35c748916c..d0c7f6050e 100644
--- a/src/library/scala/collection/parallel/mutable/ParFlatHashTable.scala
+++ b/src/library/scala/collection/parallel/mutable/ParFlatHashTable.scala
@@ -15,7 +15,7 @@ import collection.parallel.IterableSplitter
*
* @tparam T type of the elements in the $coll.
* @define coll table
- * @define Coll flat hash table
+ * @define Coll `ParFlatHashTable`
*
* @author Aleksandar Prokopec
*/
diff --git a/src/library/scala/collection/parallel/mutable/ParHashMap.scala b/src/library/scala/collection/parallel/mutable/ParHashMap.scala
index 23b23d55a1..05b3f89fa1 100644
--- a/src/library/scala/collection/parallel/mutable/ParHashMap.scala
+++ b/src/library/scala/collection/parallel/mutable/ParHashMap.scala
@@ -28,7 +28,7 @@ import collection.parallel.Task
*
* @tparam T type of the elements in the parallel hash map
*
- * @define Coll ParHashMap
+ * @define Coll `ParHashMap`
* @define coll parallel hash map
*
* @author Aleksandar Prokopec
@@ -141,7 +141,7 @@ self =>
/** $factoryInfo
- * @define Coll mutable.ParHashMap
+ * @define Coll `mutable.ParHashMap`
* @define coll parallel hash map
*/
object ParHashMap extends ParMapFactory[ParHashMap] {
diff --git a/src/library/scala/collection/parallel/mutable/ParHashSet.scala b/src/library/scala/collection/parallel/mutable/ParHashSet.scala
index 4e9a38c13f..783f8dce77 100644
--- a/src/library/scala/collection/parallel/mutable/ParHashSet.scala
+++ b/src/library/scala/collection/parallel/mutable/ParHashSet.scala
@@ -25,7 +25,7 @@ import collection.parallel.Task
*
* @tparam T type of the elements in the $coll.
*
- * @define Coll ParHashSet
+ * @define Coll `ParHashSet`
* @define coll parallel hash set
*
* @author Aleksandar Prokopec
@@ -104,7 +104,7 @@ extends ParSet[T]
/** $factoryInfo
- * @define Coll mutable.ParHashSet
+ * @define Coll `mutable.ParHashSet`
* @define coll parallel hash set
*/
object ParHashSet extends ParSetFactory[ParHashSet] {
diff --git a/src/library/scala/collection/parallel/mutable/ParSeq.scala b/src/library/scala/collection/parallel/mutable/ParSeq.scala
index a48ba48d56..f46b369494 100644
--- a/src/library/scala/collection/parallel/mutable/ParSeq.scala
+++ b/src/library/scala/collection/parallel/mutable/ParSeq.scala
@@ -26,7 +26,7 @@ import scala.collection.GenSeq
/** A mutable variant of `ParSeq`.
*
- * @define Coll mutable.ParSeq
+ * @define Coll `mutable.ParSeq`
* @define coll mutable parallel sequence
*/
trait ParSeq[T] extends collection/*.mutable*/.GenSeq[T] // was: collection.mutable.Seq[T]
@@ -47,7 +47,7 @@ self =>
/** $factoryInfo
- * @define Coll mutable.ParSeq
+ * @define Coll `mutable.ParSeq`
* @define coll mutable parallel sequence
*/
object ParSeq extends ParFactory[ParSeq] {
diff --git a/src/library/scala/collection/parallel/mutable/ParSet.scala b/src/library/scala/collection/parallel/mutable/ParSet.scala
index 1d295fd5fe..6da4c8a7bc 100644
--- a/src/library/scala/collection/parallel/mutable/ParSet.scala
+++ b/src/library/scala/collection/parallel/mutable/ParSet.scala
@@ -21,7 +21,7 @@ import scala.collection.GenSet
/** A mutable variant of `ParSet`.
*
- * @define Coll mutable.ParSet
+ * @define Coll `mutable.ParSet`
* @define coll mutable parallel set
*
* @author Aleksandar Prokopec
@@ -41,7 +41,7 @@ self =>
/** $factoryInfo
- * @define Coll mutable.ParSet
+ * @define Coll `mutable.ParSet`
* @define coll mutable parallel set
*/
object ParSet extends ParSetFactory[ParSet] {
diff --git a/src/library/scala/concurrent/ConcurrentPackageObject.scala b/src/library/scala/concurrent/ConcurrentPackageObject.scala
index fafd7fd238..a3d985733e 100644
--- a/src/library/scala/concurrent/ConcurrentPackageObject.scala
+++ b/src/library/scala/concurrent/ConcurrentPackageObject.scala
@@ -22,7 +22,7 @@ abstract class ConcurrentPackageObject {
*/
lazy val defaultExecutionContext = new impl.ExecutionContextImpl(null)
- private val currentExecutionContext = new ThreadLocal[ExecutionContext]
+ val currentExecutionContext = new ThreadLocal[ExecutionContext]
val handledFutureException: PartialFunction[Throwable, Throwable] = {
case t: Throwable if isFutureThrowable(t) => t
@@ -82,7 +82,7 @@ abstract class ConcurrentPackageObject {
* - TimeoutException - in the case that the blockable object timed out
*/
def blocking[T](body: =>T): T =
- blocking(impl.Future.body2awaitable(body), Duration.fromNanos(0))
+ blocking(impl.Future.body2awaitable(body), Duration.Inf)
/** Blocks on an awaitable object.
*
@@ -93,11 +93,12 @@ abstract class ConcurrentPackageObject {
* - InterruptedException - in the case that a wait within the blockable object was interrupted
* - TimeoutException - in the case that the blockable object timed out
*/
- def blocking[T](awaitable: Awaitable[T], atMost: Duration): T =
+ def blocking[T](awaitable: Awaitable[T], atMost: Duration): T = {
currentExecutionContext.get match {
- case null => Await.result(awaitable, atMost)
+ case null => awaitable.result(atMost)(Await.canAwaitEvidence)
case ec => ec.internalBlockingCall(awaitable, atMost)
}
+ }
@inline implicit final def int2durationops(x: Int): DurationOps = new DurationOps(x)
}
diff --git a/src/library/scala/concurrent/ExecutionContext.scala b/src/library/scala/concurrent/ExecutionContext.scala
index 3f62f58bf8..4666674b5b 100644
--- a/src/library/scala/concurrent/ExecutionContext.scala
+++ b/src/library/scala/concurrent/ExecutionContext.scala
@@ -47,11 +47,18 @@ object ExecutionContext {
/** Creates an `ExecutionContext` from the given `ExecutorService`.
*/
- def fromExecutorService(e: ExecutorService): ExecutionContext with Executor = new impl.ExecutionContextImpl(e)
+ def fromExecutorService(e: ExecutorService, reporter: Throwable => Unit = defaultReporter): ExecutionContext with Executor = new impl.ExecutionContextImpl(e, reporter)
/** Creates an `ExecutionContext` from the given `Executor`.
*/
- def fromExecutor(e: Executor): ExecutionContext with Executor = new impl.ExecutionContextImpl(e)
+ def fromExecutor(e: Executor, reporter: Throwable => Unit = defaultReporter): ExecutionContext with Executor = new impl.ExecutionContextImpl(e, reporter)
+
+ def defaultReporter: Throwable => Unit = {
+ // `Error`s are currently wrapped by `resolver`.
+ // Also, re-throwing `Error`s here causes an exception handling test to fail.
+ //case e: Error => throw e
+ case t => t.printStackTrace()
+ }
}
diff --git a/src/library/scala/concurrent/Future.scala b/src/library/scala/concurrent/Future.scala
index def086bc03..70b3c3dbbb 100644
--- a/src/library/scala/concurrent/Future.scala
+++ b/src/library/scala/concurrent/Future.scala
@@ -131,10 +131,6 @@ trait Future[+T] extends Awaitable[T] {
/* Miscellaneous */
- /** Creates a new promise.
- */
- protected def newPromise[S]: Promise[S]
-
/** Returns whether the future has already been completed with
* a value or an exception.
*
@@ -169,7 +165,7 @@ trait Future[+T] extends Awaitable[T] {
* and throws a corresponding exception if the original future fails.
*/
def failed: Future[Throwable] = {
- val p = newPromise[Throwable]
+ val p = Promise[Throwable]()
onComplete {
case Left(t) => p success t
@@ -198,7 +194,7 @@ trait Future[+T] extends Awaitable[T] {
* $forComprehensionExample
*/
def map[S](f: T => S): Future[S] = {
- val p = newPromise[S]
+ val p = Promise[S]()
onComplete {
case Left(t) => p failure t
@@ -220,7 +216,7 @@ trait Future[+T] extends Awaitable[T] {
* $forComprehensionExample
*/
def flatMap[S](f: T => Future[S]): Future[S] = {
- val p = newPromise[S]
+ val p = Promise[S]()
onComplete {
case Left(t) => p failure t
@@ -255,7 +251,7 @@ trait Future[+T] extends Awaitable[T] {
* }}}
*/
def filter(pred: T => Boolean): Future[T] = {
- val p = newPromise[T]
+ val p = Promise[T]()
onComplete {
case Left(t) => p failure t
@@ -304,7 +300,7 @@ trait Future[+T] extends Awaitable[T] {
* }}}
*/
def collect[S](pf: PartialFunction[T, S]): Future[S] = {
- val p = newPromise[S]
+ val p = Promise[S]()
onComplete {
case Left(t) => p failure t
@@ -333,7 +329,7 @@ trait Future[+T] extends Awaitable[T] {
* }}}
*/
def recover[U >: T](pf: PartialFunction[Throwable, U]): Future[U] = {
- val p = newPromise[U]
+ val p = Promise[U]()
onComplete {
case Left(t) if pf isDefinedAt t =>
@@ -359,7 +355,7 @@ trait Future[+T] extends Awaitable[T] {
* }}}
*/
def recoverWith[U >: T](pf: PartialFunction[Throwable, Future[U]]): Future[U] = {
- val p = newPromise[U]
+ val p = Promise[U]()
onComplete {
case Left(t) if pf isDefinedAt t =>
@@ -383,19 +379,19 @@ trait Future[+T] extends Awaitable[T] {
* with the throwable stored in `that`.
*/
def zip[U](that: Future[U]): Future[(T, U)] = {
- val p = newPromise[(T, U)]
-
+ val p = Promise[(T, U)]()
+
this onComplete {
case Left(t) => p failure t
- case Right(r) => that onSuccess {
- case r2 => p success ((r, r2))
- }
- }
-
- that onFailure {
- case f => p failure f
+ case Right(r) =>
+ that onSuccess {
+ case r2 => p success ((r, r2))
+ }
+ that onFailure {
+ case f => p failure f
+ }
}
-
+
p.future
}
@@ -414,7 +410,7 @@ trait Future[+T] extends Awaitable[T] {
* }}}
*/
def fallbackTo[U >: T](that: Future[U]): Future[U] = {
- val p = newPromise[U]
+ val p = Promise[U]()
onComplete {
case r @ Right(_) ⇒ p complete r
case _ ⇒ p completeWith that
@@ -426,24 +422,11 @@ trait Future[+T] extends Awaitable[T] {
* that conforms to `S`'s erased type or a `ClassCastException` otherwise.
*/
def mapTo[S](implicit tag: ClassTag[S]): Future[S] = {
- import java.{ lang => jl }
- val toBoxed = Map[Class[_], Class[_]](
- classOf[Boolean] -> classOf[jl.Boolean],
- classOf[Byte] -> classOf[jl.Byte],
- classOf[Char] -> classOf[jl.Character],
- classOf[Short] -> classOf[jl.Short],
- classOf[Int] -> classOf[jl.Integer],
- classOf[Long] -> classOf[jl.Long],
- classOf[Float] -> classOf[jl.Float],
- classOf[Double] -> classOf[jl.Double],
- classOf[Unit] -> classOf[scala.runtime.BoxedUnit]
- )
-
def boxedType(c: Class[_]): Class[_] = {
- if (c.isPrimitive) toBoxed(c) else c
+ if (c.isPrimitive) Future.toBoxed(c) else c
}
- val p = newPromise[S]
+ val p = Promise[S]()
onComplete {
case l: Left[Throwable, _] => p complete l.asInstanceOf[Either[Throwable, S]]
@@ -482,7 +465,7 @@ trait Future[+T] extends Awaitable[T] {
* }}}
*/
def andThen[U](pf: PartialFunction[Either[Throwable, T], U]): Future[T] = {
- val p = newPromise[T]
+ val p = Promise[T]()
onComplete {
case r =>
@@ -507,7 +490,7 @@ trait Future[+T] extends Awaitable[T] {
* }}}
*/
def either[U >: T](that: Future[U]): Future[U] = {
- val p = newPromise[U]
+ val p = Promise[U]()
val completePromise: PartialFunction[Either[Throwable, U], _] = {
case Left(t) => p tryFailure t
@@ -530,7 +513,22 @@ trait Future[+T] extends Awaitable[T] {
* Note: using this method yields nondeterministic dataflow programs.
*/
object Future {
- /** Starts an asynchronous computation and returns a `Future` object with the result of that computation.
+
+ import java.{ lang => jl }
+
+ private[concurrent] val toBoxed = Map[Class[_], Class[_]](
+ classOf[Boolean] -> classOf[jl.Boolean],
+ classOf[Byte] -> classOf[jl.Byte],
+ classOf[Char] -> classOf[jl.Character],
+ classOf[Short] -> classOf[jl.Short],
+ classOf[Int] -> classOf[jl.Integer],
+ classOf[Long] -> classOf[jl.Long],
+ classOf[Float] -> classOf[jl.Float],
+ classOf[Double] -> classOf[jl.Double],
+ classOf[Unit] -> classOf[scala.runtime.BoxedUnit]
+ )
+
+ /** Starts an asynchronous computation and returns a `Future` object with the result of that computation.
*
* The result becomes available once the asynchronous computation is completed.
*
@@ -544,10 +542,10 @@ object Future {
import scala.collection.mutable.Builder
import scala.collection.generic.CanBuildFrom
- /** Simple version of `Futures.traverse`. Transforms a `Traversable[Future[A]]` into a `Future[Traversable[A]]`.
+ /** Simple version of `Futures.traverse`. Transforms a `TraversableOnce[Future[A]]` into a `Future[TraversableOnce[A]]`.
* Useful for reducing many `Future`s into a single `Future`.
*/
- def sequence[A, M[_] <: Traversable[_]](in: M[Future[A]])(implicit cbf: CanBuildFrom[M[Future[A]], A, M[A]], executor: ExecutionContext): Future[M[A]] = {
+ def sequence[A, M[_] <: TraversableOnce[_]](in: M[Future[A]])(implicit cbf: CanBuildFrom[M[Future[A]], A, M[A]], executor: ExecutionContext): Future[M[A]] = {
in.foldLeft(Promise.successful(cbf(in)).future) {
(fr, fa) => for (r <- fr; a <- fa.asInstanceOf[Future[A]]) yield (r += a)
} map (_.result)
@@ -555,7 +553,7 @@ object Future {
/** Returns a `Future` to the result of the first future in the list that is completed.
*/
- def firstCompletedOf[T](futures: Traversable[Future[T]])(implicit executor: ExecutionContext): Future[T] = {
+ def firstCompletedOf[T](futures: TraversableOnce[Future[T]])(implicit executor: ExecutionContext): Future[T] = {
val p = Promise[T]()
val completeFirst: Either[Throwable, T] => Unit = p tryComplete _
@@ -566,7 +564,8 @@ object Future {
/** Returns a `Future` that will hold the optional result of the first `Future` with a result that matches the predicate.
*/
- def find[T](futures: Traversable[Future[T]])(predicate: T => Boolean)(implicit executor: ExecutionContext): Future[Option[T]] = {
+ def find[T](futurestravonce: TraversableOnce[Future[T]])(predicate: T => Boolean)(implicit executor: ExecutionContext): Future[Option[T]] = {
+ val futures = futurestravonce.toBuffer
if (futures.isEmpty) Promise.successful[Option[T]](None).future
else {
val result = Promise[Option[T]]()
@@ -577,8 +576,9 @@ object Future {
case _ =>
}
} finally {
- if (ref.decrementAndGet == 0)
+ if (ref.decrementAndGet == 0) {
result tryComplete Right(None)
+ }
}
futures.foreach(_ onComplete search)
@@ -597,7 +597,7 @@ object Future {
* val result = Await.result(Future.fold(futures)(0)(_ + _), 5 seconds)
* }}}
*/
- def fold[T, R](futures: Traversable[Future[T]])(zero: R)(foldFun: (R, T) => R)(implicit executor: ExecutionContext): Future[R] = {
+ def fold[T, R](futures: TraversableOnce[Future[T]])(zero: R)(foldFun: (R, T) => R)(implicit executor: ExecutionContext): Future[R] = {
if (futures.isEmpty) Promise.successful(zero).future
else sequence(futures).map(_.foldLeft(zero)(foldFun))
}
@@ -609,12 +609,12 @@ object Future {
* val result = Await.result(Futures.reduce(futures)(_ + _), 5 seconds)
* }}}
*/
- def reduce[T, R >: T](futures: Traversable[Future[T]])(op: (R, T) => R)(implicit executor: ExecutionContext): Future[R] = {
+ def reduce[T, R >: T](futures: TraversableOnce[Future[T]])(op: (R, T) => R)(implicit executor: ExecutionContext): Future[R] = {
if (futures.isEmpty) Promise[R].failure(new NoSuchElementException("reduce attempted on empty collection")).future
else sequence(futures).map(_ reduceLeft op)
}
- /** Transforms a `Traversable[A]` into a `Future[Traversable[B]]` using the provided function `A => Future[B]`.
+ /** Transforms a `TraversableOnce[A]` into a `Future[TraversableOnce[B]]` using the provided function `A => Future[B]`.
* This is useful for performing a parallel map. For example, to apply a function to all items of a list
* in parallel:
*
@@ -622,7 +622,7 @@ object Future {
* val myFutureList = Future.traverse(myList)(x => Future(myFunc(x)))
* }}}
*/
- def traverse[A, B, M[_] <: Traversable[_]](in: M[A])(fn: A => Future[B])(implicit cbf: CanBuildFrom[M[A], B, M[B]], executor: ExecutionContext): Future[M[B]] =
+ def traverse[A, B, M[_] <: TraversableOnce[_]](in: M[A])(fn: A => Future[B])(implicit cbf: CanBuildFrom[M[A], B, M[B]], executor: ExecutionContext): Future[M[B]] =
in.foldLeft(Promise.successful(cbf(in)).future) { (fr, a) =>
val fb = fn(a.asInstanceOf[A])
for (r <- fr; b <- fb) yield (r += b)
diff --git a/src/library/scala/concurrent/Promise.scala b/src/library/scala/concurrent/Promise.scala
index cd22a55ce7..f7ec0714cf 100644
--- a/src/library/scala/concurrent/Promise.scala
+++ b/src/library/scala/concurrent/Promise.scala
@@ -35,7 +35,8 @@ trait Promise[T] {
*
* $promiseCompletion
*/
- def complete(result: Either[Throwable, T]): this.type = if (tryComplete(result)) this else throwCompleted
+ def complete(result: Either[Throwable, T]): this.type =
+ if (tryComplete(result)) this else throw new IllegalStateException("Promise already completed.")
/** Tries to complete the promise with either a value or the exception.
*
@@ -50,9 +51,16 @@ trait Promise[T] {
* @return This promise
*/
final def completeWith(other: Future[T]): this.type = {
- other onComplete {
- this complete _
- }
+ other onComplete { this complete _ }
+ this
+ }
+
+ /** Attempts to complete this promise with the specified future, once that future is completed.
+ *
+ * @return This promise
+ */
+ final def tryCompleteWith(other: Future[T]): this.type = {
+ other onComplete { this tryComplete _ }
this
}
@@ -62,7 +70,7 @@ trait Promise[T] {
*
* $promiseCompletion
*/
- def success(v: T): this.type = if (trySuccess(v)) this else throwCompleted
+ def success(v: T): this.type = complete(Right(v))
/** Tries to complete the promise with a value.
*
@@ -80,7 +88,7 @@ trait Promise[T] {
*
* $promiseCompletion
*/
- def failure(t: Throwable): this.type = if (tryFailure(t)) this else throwCompleted
+ def failure(t: Throwable): this.type = complete(Left(t))
/** Tries to complete the promise with an exception.
*
@@ -89,18 +97,6 @@ trait Promise[T] {
* @return If the promise has already been completed returns `false`, or `true` otherwise.
*/
def tryFailure(t: Throwable): Boolean = tryComplete(Left(t))
-
- /** Wraps a `Throwable` in an `ExecutionException` if necessary. TODO replace with `resolver` from scala.concurrent
- *
- * $allowedThrowables
- */
- protected def wrap(t: Throwable): Throwable = t match {
- case t: Throwable if isFutureThrowable(t) => t
- case _ => new ExecutionException(t)
- }
-
- private def throwCompleted = throw new IllegalStateException("Promise already completed.")
-
}
diff --git a/src/library/scala/concurrent/impl/AbstractPromise.java b/src/library/scala/concurrent/impl/AbstractPromise.java
index 8aac5de042..b1799c5fa9 100644
--- a/src/library/scala/concurrent/impl/AbstractPromise.java
+++ b/src/library/scala/concurrent/impl/AbstractPromise.java
@@ -9,13 +9,32 @@
package scala.concurrent.impl;
-
+import scala.concurrent.util.Unsafe;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
abstract class AbstractPromise {
private volatile Object _ref;
+
+ final static long _refoffset;
+
+ static {
+ try {
+ _refoffset = Unsafe.instance.objectFieldOffset(AbstractPromise.class.getDeclaredField("_ref"));
+ } catch (Throwable t) {
+ throw new ExceptionInInitializerError(t);
+ }
+ }
+
+ protected final boolean updateState(Object oldState, Object newState) {
+ return Unsafe.instance.compareAndSwapObject(this, _refoffset, oldState, newState);
+ }
+
+ protected final Object getState() {
+ return _ref;
+ }
+
protected final static AtomicReferenceFieldUpdater<AbstractPromise, Object> updater =
- AtomicReferenceFieldUpdater.newUpdater(AbstractPromise.class, Object.class, "_ref");
+ AtomicReferenceFieldUpdater.newUpdater(AbstractPromise.class, Object.class, "_ref");
} \ No newline at end of file
diff --git a/src/library/scala/concurrent/impl/ExecutionContextImpl.scala b/src/library/scala/concurrent/impl/ExecutionContextImpl.scala
index ad98331241..7dc3ed2988 100644
--- a/src/library/scala/concurrent/impl/ExecutionContextImpl.scala
+++ b/src/library/scala/concurrent/impl/ExecutionContextImpl.scala
@@ -17,7 +17,8 @@ import scala.concurrent.util.{ Duration }
-private[scala] class ExecutionContextImpl(es: AnyRef) extends ExecutionContext with Executor {
+private[scala] class ExecutionContextImpl(es: AnyRef, reporter: Throwable => Unit = ExecutionContext.defaultReporter)
+extends ExecutionContext with Executor {
import ExecutionContextImpl._
val executorService: AnyRef = if (es eq null) getExecutorService else es
@@ -26,7 +27,7 @@ private[scala] class ExecutionContextImpl(es: AnyRef) extends ExecutionContext w
def executorsThreadFactory = new ThreadFactory {
def newThread(r: Runnable) = new Thread(new Runnable {
override def run() {
- currentExecutionContext.set(ExecutionContextImpl.this)
+ scala.concurrent.currentExecutionContext.set(ExecutionContextImpl.this)
r.run()
}
})
@@ -36,7 +37,7 @@ private[scala] class ExecutionContextImpl(es: AnyRef) extends ExecutionContext w
def forkJoinPoolThreadFactory = new ForkJoinPool.ForkJoinWorkerThreadFactory {
def newThread(fjp: ForkJoinPool) = new ForkJoinWorkerThread(fjp) {
override def onStart() {
- currentExecutionContext.set(ExecutionContextImpl.this)
+ scala.concurrent.currentExecutionContext.set(ExecutionContextImpl.this)
}
}
}
@@ -92,22 +93,13 @@ private[scala] class ExecutionContextImpl(es: AnyRef) extends ExecutionContext w
}
}
- def reportFailure(t: Throwable) = t match {
- // `Error`s are currently wrapped by `resolver`.
- // Also, re-throwing `Error`s here causes an exception handling test to fail.
- //case e: Error => throw e
- case t => t.printStackTrace()
- }
+ def reportFailure(t: Throwable) = reporter(t)
}
private[concurrent] object ExecutionContextImpl {
-
- private[concurrent] def currentExecutionContext: ThreadLocal[ExecutionContext] = new ThreadLocal[ExecutionContext] {
- override protected def initialValue = null
- }
-
+
}
diff --git a/src/library/scala/concurrent/impl/Future.scala b/src/library/scala/concurrent/impl/Future.scala
index 548524c9fe..20d4122e8f 100644
--- a/src/library/scala/concurrent/impl/Future.scala
+++ b/src/library/scala/concurrent/impl/Future.scala
@@ -19,29 +19,23 @@ private[concurrent] trait Future[+T] extends scala.concurrent.Future[T] with Awa
implicit def executor: ExecutionContext
- /** For use only within a Future.flow block or another compatible Delimited Continuations reset block.
- *
- * Returns the result of this Future without blocking, by suspending execution and storing it as a
- * continuation until the result is available.
- */
- //def apply(): T @cps[Future[Any]] = shift(this flatMap (_: T => Future[Any]))
-
- /** Tests whether this Future has been completed.
- */
- def isCompleted: Boolean
-
- /** The contained value of this Future. Before this Future is completed
- * the value will be None. After completion the value will be Some(Right(t))
- * if it contains a valid result, or Some(Left(error)) if it contains
- * an exception.
- */
- def value: Option[Either[Throwable, T]]
-
- def onComplete[U](func: Either[Throwable, T] => U): this.type
-
}
-object Future {
+private[concurrent] object Future {
+ import java.{ lang => jl }
+
+ private val toBoxed = Map[Class[_], Class[_]](
+ classOf[Boolean] -> classOf[jl.Boolean],
+ classOf[Byte] -> classOf[jl.Byte],
+ classOf[Char] -> classOf[jl.Character],
+ classOf[Short] -> classOf[jl.Short],
+ classOf[Int] -> classOf[jl.Integer],
+ classOf[Long] -> classOf[jl.Long],
+ classOf[Float] -> classOf[jl.Float],
+ classOf[Double] -> classOf[jl.Double],
+ classOf[Unit] -> classOf[scala.runtime.BoxedUnit]
+ )
+
/** Wraps a block of code into an awaitable object. */
private[concurrent] def body2awaitable[T](body: =>T) = new Awaitable[T] {
def ready(atMost: Duration)(implicit permit: CanAwait) = {
@@ -51,24 +45,23 @@ object Future {
def result(atMost: Duration)(implicit permit: CanAwait) = body
}
+ def boxedType(c: Class[_]): Class[_] = if (c.isPrimitive) toBoxed(c) else c
+
def apply[T](body: =>T)(implicit executor: ExecutionContext): Future[T] = {
val promise = new Promise.DefaultPromise[T]()
//TODO: use `dispatchFuture`?
executor.execute(new Runnable {
- def run = {
- promise complete {
- try {
- Right(body)
- } catch {
- case NonFatal(e) =>
- // Commenting out reporting for now, since it produces too much output in the tests
- //executor.reportFailure(e)
- scala.concurrent.resolver(e)
- }
+ def run = promise complete {
+ try Right(body) catch {
+ case NonFatal(e) =>
+ // Commenting out reporting for now, since it produces too much output in the tests
+ //executor.reportFailure(e)
+ scala.concurrent.resolver(e)
}
}
})
+
promise.future
}
diff --git a/src/library/scala/concurrent/impl/Promise.scala b/src/library/scala/concurrent/impl/Promise.scala
index ee1841aaff..da70b3dea5 100644
--- a/src/library/scala/concurrent/impl/Promise.scala
+++ b/src/library/scala/concurrent/impl/Promise.scala
@@ -11,7 +11,6 @@ package scala.concurrent.impl
import java.util.concurrent.TimeUnit.{ NANOSECONDS, MILLISECONDS }
-import java.util.concurrent.atomic.AtomicReferenceFieldUpdater
import scala.concurrent.{Awaitable, ExecutionContext, resolveEither, resolver, blocking, CanAwait, TimeoutException}
//import scala.util.continuations._
import scala.concurrent.util.Duration
@@ -22,54 +21,7 @@ import scala.annotation.tailrec
private[concurrent] trait Promise[T] extends scala.concurrent.Promise[T] with Future[T] {
-
- def future = this
-
- def newPromise[S]: scala.concurrent.Promise[S] = new Promise.DefaultPromise()
-
- // TODO refine answer and return types here from Any to type parameters
- // then move this up in the hierarchy
- /*
- final def <<(value: T): Future[T] @cps[Future[Any]] = shift {
- cont: (Future[T] => Future[Any]) =>
- cont(complete(Right(value)))
- }
-
- final def <<(other: Future[T]): Future[T] @cps[Future[Any]] = shift {
- cont: (Future[T] => Future[Any]) =>
- val p = executor.promise[Any]
- val thisPromise = this
-
- thisPromise completeWith other
- thisPromise onComplete { v =>
- try {
- p completeWith cont(thisPromise)
- } catch {
- case e => p complete resolver(e)
- }
- }
-
- p.future
- }
- */
- // TODO finish this once we introduce something like dataflow streams
-
- /*
- final def <<(stream: PromiseStreamOut[T]): Future[T] @cps[Future[Any]] = shift { cont: (Future[T] => Future[Any]) =>
- val fr = executor.promise[Any]
- val f = stream.dequeue(this)
- f.onComplete { _ =>
- try {
- fr completeWith cont(f)
- } catch {
- case e =>
- fr failure e
- }
- }
- fr
- }
- */
-
+ def future: this.type = this
}
@@ -77,8 +29,8 @@ object Promise {
/** Default promise implementation.
*/
class DefaultPromise[T](implicit val executor: ExecutionContext) extends AbstractPromise with Promise[T] { self =>
- updater.set(this, Nil) // Start at "No callbacks" //FIXME switch to Unsafe instead of ARFU
-
+ updateState(null, Nil) // Start at "No callbacks" //FIXME switch to Unsafe instead of ARFU
+
protected final def tryAwait(atMost: Duration): Boolean = {
@tailrec
def awaitUnsafe(waitTimeNanos: Long): Boolean = {
@@ -88,7 +40,7 @@ object Promise {
val start = System.nanoTime()
try {
synchronized {
- while (!isCompleted) wait(ms, ns)
+ if (!isCompleted) wait(ms, ns) // previously - this was a `while`, ending up in an infinite loop
}
} catch {
case e: InterruptedException =>
@@ -99,7 +51,7 @@ object Promise {
isCompleted
}
//FIXME do not do this if there'll be no waiting
- blocking(Future.body2awaitable(awaitUnsafe(if (atMost.isFinite) atMost.toNanos else Long.MaxValue)), atMost)
+ awaitUnsafe(if (atMost.isFinite) atMost.toNanos else Long.MaxValue)
}
@throws(classOf[TimeoutException])
@@ -124,56 +76,37 @@ object Promise {
case _ => false
}
- @inline
- private[this] final def updater = AbstractPromise.updater.asInstanceOf[AtomicReferenceFieldUpdater[AbstractPromise, AnyRef]]
-
- @inline
- protected final def updateState(oldState: AnyRef, newState: AnyRef): Boolean = updater.compareAndSet(this, oldState, newState)
-
- @inline
- protected final def getState: AnyRef = updater.get(this)
-
def tryComplete(value: Either[Throwable, T]): Boolean = {
- val callbacks: List[Either[Throwable, T] => Unit] = {
- try {
- @tailrec
- def tryComplete(v: Either[Throwable, T]): List[Either[Throwable, T] => Unit] = {
- getState match {
- case raw: List[_] =>
- val cur = raw.asInstanceOf[List[Either[Throwable, T] => Unit]]
- if (updateState(cur, v)) cur else tryComplete(v)
- case _ => null
- }
+ val resolved = resolveEither(value)
+ (try {
+ @tailrec
+ def tryComplete(v: Either[Throwable, T]): List[Either[Throwable, T] => Unit] = {
+ getState match {
+ case raw: List[_] =>
+ val cur = raw.asInstanceOf[List[Either[Throwable, T] => Unit]]
+ if (updateState(cur, v)) cur else tryComplete(v)
+ case _ => null
}
- tryComplete(resolveEither(value))
- } finally {
- synchronized { notifyAll() } //Notify any evil blockers
}
- }
-
- callbacks match {
+ tryComplete(resolved)
+ } finally {
+ synchronized { notifyAll() } //Notify any evil blockers
+ }) match {
case null => false
case cs if cs.isEmpty => true
- case cs => Future.dispatchFuture(executor, () => cs.foreach(f => notifyCompleted(f, value))); true
+ case cs => Future.dispatchFuture(executor, () => cs.foreach(f => notifyCompleted(f, resolved))); true
}
}
def onComplete[U](func: Either[Throwable, T] => U): this.type = {
- @tailrec //Returns the future's results if it has already been completed, or null otherwise.
- def tryAddCallback(): Either[Throwable, T] = {
- val cur = getState
- cur match {
- case r: Either[_, _] => r.asInstanceOf[Either[Throwable, T]]
- case listeners: List[_] => if (updateState(listeners, func :: listeners)) null else tryAddCallback()
+ @tailrec //Tries to add the callback, if already completed, it dispatches the callback to be executed
+ def dispatchOrAddCallback(): Unit =
+ getState match {
+ case r: Either[_, _] => Future.dispatchFuture(executor, () => notifyCompleted(func, r.asInstanceOf[Either[Throwable, T]]))
+ case listeners: List[_] => if (updateState(listeners, func :: listeners)) () else dispatchOrAddCallback()
}
- }
-
- tryAddCallback() match {
- case null => this
- case completed =>
- Future.dispatchFuture(executor, () => notifyCompleted(func, completed))
- this
- }
+ dispatchOrAddCallback()
+ this
}
private final def notifyCompleted(func: Either[Throwable, T] => Any, result: Either[Throwable, T]) {
diff --git a/src/library/scala/concurrent/package.scala b/src/library/scala/concurrent/package.scala
index b06c6f3c63..e8921ef531 100644
--- a/src/library/scala/concurrent/package.scala
+++ b/src/library/scala/concurrent/package.scala
@@ -26,9 +26,15 @@ package concurrent {
object Await {
private[concurrent] implicit val canAwaitEvidence = new CanAwait {}
- def ready[T](awaitable: Awaitable[T], atMost: Duration): Awaitable[T] = awaitable.ready(atMost)
+ def ready[T](awaitable: Awaitable[T], atMost: Duration): awaitable.type = {
+ blocking(awaitable, atMost)
+ awaitable
+ }
+
+ def result[T](awaitable: Awaitable[T], atMost: Duration): T = {
+ blocking(awaitable, atMost)
+ }
- def result[T](awaitable: Awaitable[T], atMost: Duration): T = awaitable.result(atMost)
}
final class DurationOps private[concurrent] (x: Int) {
diff --git a/src/library/scala/concurrent/util/Duration.scala b/src/library/scala/concurrent/util/Duration.scala
index c4e5fa491a..bab664727e 100644
--- a/src/library/scala/concurrent/util/Duration.scala
+++ b/src/library/scala/concurrent/util/Duration.scala
@@ -1,12 +1,16 @@
-/**
- * Copyright (C) 2009-2012 Typesafe Inc. <http://www.typesafe.com>
- */
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2003-2012, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
package scala.concurrent.util
import java.util.concurrent.TimeUnit
import TimeUnit._
-import java.lang.{ Double ⇒ JDouble }
+import java.lang.{ Double => JDouble }
import language.implicitConversions
case class Deadline private (time: Duration) {
@@ -115,13 +119,13 @@ object Duration {
* Parse TimeUnit from string representation.
*/
protected[util] def timeUnit(unit: String): TimeUnit = unit.toLowerCase match {
- case "d" | "day" | "days" ⇒ DAYS
- case "h" | "hour" | "hours" ⇒ HOURS
- case "min" | "minute" | "minutes" ⇒ MINUTES
- case "s" | "sec" | "second" | "seconds" ⇒ SECONDS
- case "ms" | "milli" | "millis" | "millisecond" | "milliseconds" ⇒ MILLISECONDS
- case "µs" | "micro" | "micros" | "microsecond" | "microseconds" ⇒ MICROSECONDS
- case "ns" | "nano" | "nanos" | "nanosecond" | "nanoseconds" ⇒ NANOSECONDS
+ case "d" | "day" | "days" => DAYS
+ case "h" | "hour" | "hours" => HOURS
+ case "min" | "minute" | "minutes" => MINUTES
+ case "s" | "sec" | "second" | "seconds" => SECONDS
+ case "ms" | "milli" | "millis" | "millisecond" | "milliseconds" => MILLISECONDS
+ case "µs" | "micro" | "micros" | "microsecond" | "microseconds" => MICROSECONDS
+ case "ns" | "nano" | "nanos" | "nanosecond" | "nanoseconds" => NANOSECONDS
}
val Zero: FiniteDuration = new FiniteDuration(0, NANOSECONDS)
@@ -138,26 +142,26 @@ object Duration {
}
trait Infinite {
- this: Duration ⇒
+ this: Duration =>
def +(other: Duration): Duration =
other match {
- case _: this.type ⇒ this
- case _: Infinite ⇒ throw new IllegalArgumentException("illegal addition of infinities")
- case _ ⇒ this
+ case _: this.type => this
+ case _: Infinite => throw new IllegalArgumentException("illegal addition of infinities")
+ case _ => this
}
def -(other: Duration): Duration =
other match {
- case _: this.type ⇒ throw new IllegalArgumentException("illegal subtraction of infinities")
- case _ ⇒ this
+ case _: this.type => throw new IllegalArgumentException("illegal subtraction of infinities")
+ case _ => this
}
def *(factor: Double): Duration = this
def /(factor: Double): Duration = this
def /(other: Duration): Double =
other match {
- case _: Infinite ⇒ throw new IllegalArgumentException("illegal division of infinities")
+ case _: Infinite => throw new IllegalArgumentException("illegal division of infinities")
// maybe questionable but pragmatic: Inf / 0 => Inf
- case x ⇒ Double.PositiveInfinity * (if ((this > Zero) ^ (other >= Zero)) -1 else 1)
+ case x => Double.PositiveInfinity * (if ((this > Zero) ^ (other >= Zero)) -1 else 1)
}
def finite_? = false
@@ -300,20 +304,20 @@ class FiniteDuration(val length: Long, val unit: TimeUnit) extends Duration {
def toUnit(u: TimeUnit) = toNanos.toDouble / NANOSECONDS.convert(1, u)
override def toString = this match {
- case Duration(1, DAYS) ⇒ "1 day"
- case Duration(x, DAYS) ⇒ x + " days"
- case Duration(1, HOURS) ⇒ "1 hour"
- case Duration(x, HOURS) ⇒ x + " hours"
- case Duration(1, MINUTES) ⇒ "1 minute"
- case Duration(x, MINUTES) ⇒ x + " minutes"
- case Duration(1, SECONDS) ⇒ "1 second"
- case Duration(x, SECONDS) ⇒ x + " seconds"
- case Duration(1, MILLISECONDS) ⇒ "1 millisecond"
- case Duration(x, MILLISECONDS) ⇒ x + " milliseconds"
- case Duration(1, MICROSECONDS) ⇒ "1 microsecond"
- case Duration(x, MICROSECONDS) ⇒ x + " microseconds"
- case Duration(1, NANOSECONDS) ⇒ "1 nanosecond"
- case Duration(x, NANOSECONDS) ⇒ x + " nanoseconds"
+ case Duration(1, DAYS) => "1 day"
+ case Duration(x, DAYS) => x + " days"
+ case Duration(1, HOURS) => "1 hour"
+ case Duration(x, HOURS) => x + " hours"
+ case Duration(1, MINUTES) => "1 minute"
+ case Duration(x, MINUTES) => x + " minutes"
+ case Duration(1, SECONDS) => "1 second"
+ case Duration(x, SECONDS) => x + " seconds"
+ case Duration(1, MILLISECONDS) => "1 millisecond"
+ case Duration(x, MILLISECONDS) => x + " milliseconds"
+ case Duration(1, MICROSECONDS) => "1 microsecond"
+ case Duration(x, MICROSECONDS) => x + " microseconds"
+ case Duration(1, NANOSECONDS) => "1 nanosecond"
+ case Duration(x, NANOSECONDS) => x + " nanoseconds"
}
def compare(other: Duration) =
diff --git a/src/library/scala/concurrent/impl/Unsafe.java b/src/library/scala/concurrent/util/Unsafe.java
index 21f7e638e5..0cd48758d5 100644
--- a/src/library/scala/concurrent/impl/Unsafe.java
+++ b/src/library/scala/concurrent/util/Unsafe.java
@@ -6,22 +6,25 @@
** |/ **
\* */
+package scala.concurrent.util;
+
-package scala.concurrent;
import java.lang.reflect.Field;
-final class Unsafe {
+
+
+public final class Unsafe {
public final static sun.misc.Unsafe instance;
static {
try {
sun.misc.Unsafe found = null;
for(Field field : sun.misc.Unsafe.class.getDeclaredFields()) {
- if (field.getType() == sun.misc.Unsafe.class) {
- field.setAccessible(true);
- found = (sun.misc.Unsafe) field.get(null);
- break;
- }
+ if (field.getType() == sun.misc.Unsafe.class) {
+ field.setAccessible(true);
+ found = (sun.misc.Unsafe) field.get(null);
+ break;
+ }
}
if (found == null) throw new IllegalStateException("Can't find instance of sun.misc.Unsafe");
else instance = found;
diff --git a/src/library/scala/math/package.scala b/src/library/scala/math/package.scala
index 0417461f85..71a7f8e5ed 100644
--- a/src/library/scala/math/package.scala
+++ b/src/library/scala/math/package.scala
@@ -115,21 +115,10 @@ package object math {
def min(x: Float, y: Float): Float = java.lang.Math.min(x, y)
def min(x: Double, y: Double): Double = java.lang.Math.min(x, y)
- def signum(x: Double): Double =
- if (x == 0d) 0d
- else if (x < 0) -1.0
- else if (x > 0) 1.0
- else x // NaN
-
- def signum(x: Float): Float =
- if (x == 0f) 0f
- else if (x < 0) -1.0f
- else if (x > 0) 1.0f
- else x // NaN
-
- def signum(x: Long): Long = java.lang.Long.signum(x)
-
def signum(x: Int): Int = java.lang.Integer.signum(x)
+ def signum(x: Long): Long = java.lang.Long.signum(x)
+ def signum(x: Float): Float = java.lang.Math.signum(x)
+ def signum(x: Double): Double = java.lang.Math.signum(x)
// -----------------------------------------------------------------------
// root functions
diff --git a/src/library/scala/reflect/DummyMirror.scala b/src/library/scala/reflect/DummyMirror.scala
index 422598caef..aa731f62db 100644
--- a/src/library/scala/reflect/DummyMirror.scala
+++ b/src/library/scala/reflect/DummyMirror.scala
@@ -306,7 +306,6 @@ class DummyMirror(cl: ClassLoader) extends api.Mirror {
val THIS: TermName = DummyName
val BITMAP_NORMAL: TermName = DummyName
val BITMAP_TRANSIENT: TermName = DummyName
- val BITMAP_PRIVATE: TermName = DummyName
val BITMAP_CHECKINIT: TermName = DummyName
val BITMAP_CHECKINIT_TRANSIENT: TermName = DummyName
val INTERPRETER_IMPORT_WRAPPER: String = ""
diff --git a/src/library/scala/reflect/api/RequiredFile.scala b/src/library/scala/reflect/api/RequiredFile.scala
new file mode 100644
index 0000000000..4a54595940
--- /dev/null
+++ b/src/library/scala/reflect/api/RequiredFile.scala
@@ -0,0 +1,7 @@
+package scala.reflect
+package api
+
+trait RequiredFile {
+ def path: String
+ def canonicalPath: String
+}
diff --git a/src/library/scala/reflect/api/StandardNames.scala b/src/library/scala/reflect/api/StandardNames.scala
index 60c64f947a..a17ea216f7 100644
--- a/src/library/scala/reflect/api/StandardNames.scala
+++ b/src/library/scala/reflect/api/StandardNames.scala
@@ -73,7 +73,6 @@ trait StandardNames {
val BITMAP_NORMAL: TermName
val BITMAP_TRANSIENT: TermName
- val BITMAP_PRIVATE: TermName
val BITMAP_CHECKINIT: TermName
val BITMAP_CHECKINIT_TRANSIENT: TermName
diff --git a/src/library/scala/reflect/api/Trees.scala b/src/library/scala/reflect/api/Trees.scala
index 9f8906a8cd..ca4e60f3f6 100644
--- a/src/library/scala/reflect/api/Trees.scala
+++ b/src/library/scala/reflect/api/Trees.scala
@@ -16,6 +16,9 @@ trait Trees { self: Universe =>
type Modifiers >: Null <: AbsModifiers
val NoMods: Modifiers
+ // TODO - Where do I put this?
+ object BackquotedIdentifier
+
abstract class AbsModifiers {
def modifiers: Set[Modifier]
def hasModifier(mod: Modifier): Boolean
@@ -96,6 +99,20 @@ trait Trees { self: Universe =>
case _ =>
rawatt = NontrivialAttachment(pos, collection.mutable.ListBuffer[Any](att))
}
+
+ // a) why didn't this method already exist
+ // b) what is all this "Any" business?
+ // c) am I reverse-engineering this correctly? It shouldn't be hard
+ // to figure out what is attached.
+ def attachments: List[Any] = rawatt match {
+ case NoPosition => Nil
+ case NontrivialAttachment(pos, atts) => pos :: atts.toList
+ case x => List(x)
+ }
+ // Writing "Any" repeatedly to work within this structure
+ // is making my skin crawl.
+ def hasAttachment(x: Any) = attachments contains x
+
def withAttachment(att: Any): this.type = { attach(att); this }
def detach(att: Any): Unit =
detach(att.getClass)
@@ -110,13 +127,12 @@ trait Trees { self: Universe =>
def withoutAttachment(att: Any): this.type = { detach(att); this }
def attachment[T: ClassTag]: T = attachmentOpt[T] getOrElse { throw new Error("no attachment of type %s".format(classTag[T].erasure)) }
def attachmentOpt[T: ClassTag]: Option[T] =
+ firstAttachment { case attachment if attachment.getClass == classTag[T].erasure => attachment.asInstanceOf[T] }
+
+ def firstAttachment[T](p: PartialFunction[Any, T]): Option[T] =
rawatt match {
- case NontrivialAttachment(pos, payload) =>
- val index = payload.indexWhere(p => p.getClass == classTag[T].erasure)
- if (index != -1) Some(payload(index).asInstanceOf[T])
- else None
- case _ =>
- None
+ case NontrivialAttachment(pos, payload) => payload.collectFirst(p)
+ case _ => None
}
private[this] var rawtpe: Type = _
@@ -124,6 +140,9 @@ trait Trees { self: Universe =>
def tpe = rawtpe
def tpe_=(t: Type) = rawtpe = t
+ def resetType(): this.type = { tpe = null ; this }
+ def resetSymbol(): this.type = { if (hasSymbol) symbol = NoSymbol ; this }
+
/** Set tpe to give `tp` and return this.
*/
def setType(tp: Type): this.type = { rawtpe = tp; this }
@@ -134,7 +153,7 @@ trait Trees { self: Universe =>
* @PP: Attempting to elaborate on the above, I find: If defineType
* is called on a TypeTree whose type field is null or NoType,
* this is recorded as "wasEmpty = true". That value is used in
- * ResetAttrsTraverser, which nulls out the type field of TypeTrees
+ * ResetAttrs, which nulls out the type field of TypeTrees
* for which wasEmpty is true, leaving the others alone.
*
* resetAllAttrs is used in situations where some speculative
@@ -169,9 +188,14 @@ trait Trees { self: Universe =>
def hasSymbol = false
def isDef = false
def isEmpty = false
- def orElse(alt: => Tree) = if (!isEmpty) this else alt
+ @inline final def orElse(alt: => Tree) = if (!isEmpty) this else alt
+ @inline final def andAlso(f: Tree => Unit): Tree = { if (!this.isEmpty) f(this) ; this }
- def hasSymbolWhich(f: Symbol => Boolean) = hasSymbol && f(symbol)
+ def hasAssignedType = (tpe ne null) && (tpe ne NoType)
+ def hasAssignedSymbol = (symbol ne null) && (symbol ne NoSymbol)
+
+ @inline final def hasSymbolWhich(f: Symbol => Boolean) = hasAssignedSymbol && f(symbol)
+ @inline final def hasTypeWhich(f: Type => Boolean) = hasAssignedType && f(tpe)
/** The canonical way to test if a Tree represents a term.
*/
@@ -325,6 +349,7 @@ trait Trees { self: Universe =>
override def tpe_=(t: Type) =
if (t != NoType) throw new UnsupportedOperationException("tpe_=("+t+") inapplicable for <empty>")
override def isEmpty = true
+ override def resetType(): this.type = this
}
/** Common base class for all member definitions: types, classes,
@@ -622,6 +647,9 @@ trait Trees { self: Universe =>
*/
case class TypeApply(fun: Tree, args: List[Tree])
extends GenericApply {
+
+ // Testing the above theory re: args.nonEmpty.
+ require(args.nonEmpty, this)
override def symbol: Symbol = fun.symbol
override def symbol_=(sym: Symbol) { fun.symbol = sym }
}
@@ -691,16 +719,13 @@ trait Trees { self: Universe =>
/** Identifier <name> */
case class Ident(name: Name) extends RefTree {
def qualifier: Tree = EmptyTree
+ def isBackquoted = this hasAttachment BackquotedIdentifier
}
def Ident(name: String): Ident
def Ident(sym: Symbol): Ident
- // TODO remove this class, add a tree attachment to Ident to track whether it was backquoted
- // copying trees will all too easily forget to distinguish subclasses
- class BackQuotedIdent(name: Name) extends Ident(name)
-
/** Marks underlying reference to id as boxed.
* @pre: id must refer to a captured variable
* A reference such marked will refer to the boxed entity, no dereferencing
@@ -773,8 +798,8 @@ trait Trees { self: Universe =>
case t => t
}
- orig = followOriginal(tree); setPos(tree.pos);
- this
+ orig = followOriginal(tree)
+ this setPos tree.pos
}
override def defineType(tp: Type): this.type = {
@@ -1152,11 +1177,11 @@ trait Trees { self: Universe =>
new This(qual.toTypeName).copyAttrs(tree)
def Select(tree: Tree, qualifier: Tree, selector: Name) =
new Select(qualifier, selector).copyAttrs(tree)
- def Ident(tree: Tree, name: Name) =
- (tree match { // TODO: use a tree attachment to track whether this identifier was backquoted
- case _ : BackQuotedIdent => new BackQuotedIdent(name)
- case _ => new Ident(name)
- }).copyAttrs(tree)
+ def Ident(tree: Tree, name: Name) = {
+ val t = new Ident(name) copyAttrs tree
+ if (tree hasAttachment BackquotedIdentifier) t withAttachment BackquotedIdentifier
+ else t
+ }
def ReferenceToBoxed(tree: Tree, idt: Ident) =
new ReferenceToBoxed(idt).copyAttrs(tree)
def Literal(tree: Tree, value: Constant) =
diff --git a/src/library/scala/reflect/api/Types.scala b/src/library/scala/reflect/api/Types.scala
index e06bb37cba..5c7563c2c5 100755
--- a/src/library/scala/reflect/api/Types.scala
+++ b/src/library/scala/reflect/api/Types.scala
@@ -464,10 +464,10 @@ trait Types { self: Universe =>
def unapply(tpe: AnnotatedType): Option[(List[AnnotationInfo], Type, Symbol)]
}
- /** The least upper bound wrt <:< of a list of types */
+ /** The least upper bound of a list of types, as determined by `<:<`. */
def lub(xs: List[Type]): Type
- /** The greatest lower bound wrt <:< of a list of types */
+ /** The greatest lower bound of a list of types, as determined by `<:<`. */
def glb(ts: List[Type]): Type
// Creators ---------------------------------------------------------------
@@ -515,15 +515,17 @@ trait Types { self: Universe =>
/** A creator for existential types. This generates:
*
- * tpe1 where { tparams }
+ * {{{
+ * tpe1 where { tparams }
+ * }}}
*
- * where `tpe1` is the result of extrapolating `tpe` wrt to `tparams`.
+ * where `tpe1` is the result of extrapolating `tpe` with regard to `tparams`.
* Extrapolating means that type variables in `tparams` occurring
* in covariant positions are replaced by upper bounds, (minus any
* SingletonClass markers), type variables in `tparams` occurring in
* contravariant positions are replaced by upper bounds, provided the
- * resulting type is legal wrt to stability, and does not contain any type
- * variable in `tparams`.
+ * resulting type is legal with regard to stability, and does not contain
+ * any type variable in `tparams`.
*
* The abstraction drops all type parameters that are not directly or
* indirectly referenced by type `tpe1`. If there are no remaining type
diff --git a/src/library/scala/runtime/ScalaRunTime.scala b/src/library/scala/runtime/ScalaRunTime.scala
index 9d67644d61..4c5e0e408b 100644
--- a/src/library/scala/runtime/ScalaRunTime.scala
+++ b/src/library/scala/runtime/ScalaRunTime.scala
@@ -130,16 +130,18 @@ object ScalaRunTime {
case null => throw new NullPointerException
}
- /** Convert a numeric value array to an object array.
+ /** Convert an array to an object array.
* Needed to deal with vararg arguments of primitive types that are passed
* to a generic Java vararg parameter T ...
*/
- def toObjectArray(src: AnyRef): Array[Object] = {
- val length = array_length(src)
- val dest = new Array[Object](length)
- for (i <- 0 until length)
- array_update(dest, i, array_apply(src, i))
- dest
+ def toObjectArray(src: AnyRef): Array[Object] = src match {
+ case x: Array[AnyRef] => x
+ case _ =>
+ val length = array_length(src)
+ val dest = new Array[Object](length)
+ for (i <- 0 until length)
+ array_update(dest, i, array_apply(src, i))
+ dest
}
def toArray[T](xs: collection.Seq[T]) = {
@@ -293,8 +295,12 @@ object ScalaRunTime {
*/
def stringOf(arg: Any): String = stringOf(arg, scala.Int.MaxValue)
def stringOf(arg: Any, maxElements: Int): String = {
- def isScalaClass(x: AnyRef) =
- Option(x.getClass.getPackage) exists (_.getName startsWith "scala.")
+ def packageOf(x: AnyRef) = x.getClass.getPackage match {
+ case null => ""
+ case p => p.getName
+ }
+ def isScalaClass(x: AnyRef) = packageOf(x) startsWith "scala."
+ def isScalaCompilerClass(x: AnyRef) = packageOf(x) startsWith "scala.tools.nsc."
// When doing our own iteration is dangerous
def useOwnToString(x: Any) = x match {
@@ -310,7 +316,8 @@ object ScalaRunTime {
case _: TraversableView[_, _] => true
// Don't want to a) traverse infinity or b) be overly helpful with peoples' custom
// collections which may have useful toString methods - ticket #3710
- case x: Traversable[_] => !x.hasDefiniteSize || !isScalaClass(x)
+ // or c) print AbstractFiles which are somehow also Iterable[AbstractFile]s.
+ case x: Traversable[_] => !x.hasDefiniteSize || !isScalaClass(x) || isScalaCompilerClass(x)
// Otherwise, nothing could possibly go wrong
case _ => false
}
diff --git a/src/library/scala/runtime/SeqCharSequence.scala b/src/library/scala/runtime/SeqCharSequence.scala
new file mode 100644
index 0000000000..8ef1a9a33e
--- /dev/null
+++ b/src/library/scala/runtime/SeqCharSequence.scala
@@ -0,0 +1,44 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+package scala.runtime
+
+import java.util.Arrays.copyOfRange
+
+final class SeqCharSequence(val xs: collection.IndexedSeq[Char]) extends CharSequence {
+ def length: Int = xs.length
+ def charAt(index: Int): Char = xs(index)
+ def subSequence(start: Int, end: Int): CharSequence = new SeqCharSequence(xs.slice(start, end))
+ override def toString = xs.mkString("")
+}
+
+final class ArrayCharSequence(val xs: Array[Char], start: Int, end: Int) extends CharSequence {
+ // yikes
+ // java.lang.VerifyError: (class: scala/runtime/ArrayCharSequence, method: <init> signature: ([C)V)
+ // Constructor must call super() or this()
+ //
+ // def this(xs: Array[Char]) = this(xs, 0, xs.length)
+
+ def length: Int = math.max(0, end - start)
+ def charAt(index: Int): Char = {
+ if (0 <= index && index < length)
+ xs(start + index)
+ else throw new ArrayIndexOutOfBoundsException(index)
+ }
+ def subSequence(start0: Int, end0: Int): CharSequence = {
+ if (start0 < 0) throw new ArrayIndexOutOfBoundsException(start0)
+ else if (end0 > length) throw new ArrayIndexOutOfBoundsException(end0)
+ else if (end0 <= start0) new ArrayCharSequence(xs, 0, 0)
+ else {
+ val newlen = end0 - start0
+ val start1 = start + start0
+ new ArrayCharSequence(xs, start1, start1 + newlen)
+ }
+ }
+ override def toString = xs drop start take length mkString ""
+}
diff --git a/src/library/scala/runtime/Tuple2Zipped.scala b/src/library/scala/runtime/Tuple2Zipped.scala
new file mode 100644
index 0000000000..5ad364c8a5
--- /dev/null
+++ b/src/library/scala/runtime/Tuple2Zipped.scala
@@ -0,0 +1,130 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+package scala.runtime
+
+import scala.collection.{ TraversableLike, IterableLike }
+import scala.collection.generic.{ CanBuildFrom => CBF }
+
+/** This interface is intended as a minimal interface, not complicated
+ * by the requirement to resolve type constructors, for implicit search (which only
+ * needs to find an implicit conversion to Traversable for our purposes.)
+ */
+trait ZippedTraversable2[+El1, +El2] {
+ def foreach[U](f: (El1, El2) => U): Unit
+}
+object ZippedTraversable2 {
+ implicit def zippedTraversable2ToTraversable[El1, El2](zz: ZippedTraversable2[El1, El2]): Traversable[(El1, El2)] = {
+ new collection.AbstractTraversable[(El1, El2)] {
+ def foreach[U](f: ((El1, El2)) => U): Unit = zz foreach Function.untupled(f)
+ }
+ }
+}
+
+class Tuple2Zipped[El1, Repr1, El2, Repr2](
+ coll1: TraversableLike[El1, Repr1],
+ coll2: IterableLike[El2, Repr2]
+) extends ZippedTraversable2[El1, El2] {
+ def map[B, To](f: (El1, El2) => B)(implicit cbf: CBF[Repr1, B, To]): To = {
+ val b = cbf(coll1.repr)
+ b.sizeHint(coll1)
+ val elems2 = coll2.iterator
+
+ for (el1 <- coll1) {
+ if (elems2.hasNext)
+ b += f(el1, elems2.next)
+ else
+ return b.result
+ }
+
+ b.result
+ }
+
+ def flatMap[B, To](f: (El1, El2) => TraversableOnce[B])(implicit cbf: CBF[Repr1, B, To]): To = {
+ val b = cbf(coll1.repr)
+ val elems2 = coll2.iterator
+
+ for (el1 <- coll1) {
+ if (elems2.hasNext)
+ b ++= f(el1, elems2.next)
+ else
+ return b.result
+ }
+
+ b.result
+ }
+
+ def filter[To1, To2](f: (El1, El2) => Boolean)(implicit cbf1: CBF[Repr1, El1, To1], cbf2: CBF[Repr2, El2, To2]): (To1, To2) = {
+ val b1 = cbf1(coll1.repr)
+ val b2 = cbf2(coll2.repr)
+ val elems2 = coll2.iterator
+
+ for (el1 <- coll1) {
+ if (elems2.hasNext) {
+ val el2 = elems2.next
+ if (f(el1, el2)) {
+ b1 += el1
+ b2 += el2
+ }
+ }
+ else return (b1.result, b2.result)
+ }
+
+ (b1.result, b2.result)
+ }
+
+ def exists(f: (El1, El2) => Boolean): Boolean = {
+ val elems2 = coll2.iterator
+
+ for (el1 <- coll1) {
+ if (elems2.hasNext) {
+ if (f(el1, elems2.next))
+ return true
+ }
+ else return false
+ }
+ false
+ }
+
+ def forall(f: (El1, El2) => Boolean): Boolean =
+ !exists((x, y) => !f(x, y))
+
+ def foreach[U](f: (El1, El2) => U): Unit = {
+ val elems2 = coll2.iterator
+
+ for (el1 <- coll1) {
+ if (elems2.hasNext)
+ f(el1, elems2.next)
+ else
+ return
+ }
+ }
+}
+
+object Tuple2Zipped {
+ class Ops[T1, T2](x: (T1, T2)) {
+ def invert[El1, CC1[X] <: TraversableOnce[X], El2, CC2[X] <: TraversableOnce[X], That]
+ (implicit w1: T1 <:< CC1[El1],
+ w2: T2 <:< CC2[El2],
+ bf: collection.generic.CanBuildFrom[CC1[_], (El1, El2), That]
+ ): That = {
+ val buf = bf(x._1)
+ val it1 = x._1.toIterator
+ val it2 = x._2.toIterator
+ while (it1.hasNext && it2.hasNext)
+ buf += ((it1.next, it2.next))
+
+ buf.result
+ }
+
+ def zipped[El1, Repr1, El2, Repr2]
+ (implicit w1: T1 => TraversableLike[El1, Repr1],
+ w2: T2 => IterableLike[El2, Repr2]
+ ): Tuple2Zipped[El1, Repr1, El2, Repr2] = new Tuple2Zipped(x._1, x._2)
+ }
+}
diff --git a/src/library/scala/runtime/Tuple3Zipped.scala b/src/library/scala/runtime/Tuple3Zipped.scala
new file mode 100644
index 0000000000..4e9c542c58
--- /dev/null
+++ b/src/library/scala/runtime/Tuple3Zipped.scala
@@ -0,0 +1,141 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+package scala.runtime
+
+import scala.collection.{ TraversableLike, IterableLike }
+import scala.collection.generic.{ CanBuildFrom => CBF }
+
+/** See comment on ZippedTraversable2. */
+trait ZippedTraversable3[+El1, +El2, +El3] {
+ def foreach[U](f: (El1, El2, El3) => U): Unit
+}
+object ZippedTraversable3 {
+ implicit def zippedTraversable3ToTraversable[El1, El2, El3](zz: ZippedTraversable3[El1, El2, El3]): Traversable[(El1, El2, El3)] = {
+ new collection.AbstractTraversable[(El1, El2, El3)] {
+ def foreach[U](f: ((El1, El2, El3)) => U): Unit = zz foreach Function.untupled(f)
+ }
+ }
+}
+
+class Tuple3Zipped[El1, Repr1, El2, Repr2, El3, Repr3](
+ coll1: TraversableLike[El1, Repr1],
+ coll2: IterableLike[El2, Repr2],
+ coll3: IterableLike[El3, Repr3]
+) extends ZippedTraversable3[El1, El2, El3] {
+ def map[B, To](f: (El1, El2, El3) => B)(implicit cbf: CBF[Repr1, B, To]): To = {
+ val b = cbf(coll1.repr)
+ val elems2 = coll2.iterator
+ val elems3 = coll3.iterator
+
+ for (el1 <- coll1) {
+ if (elems2.hasNext && elems3.hasNext)
+ b += f(el1, elems2.next, elems3.next)
+ else
+ return b.result
+ }
+ b.result
+ }
+
+ def flatMap[B, To](f: (El1, El2, El3) => TraversableOnce[B])(implicit cbf: CBF[Repr1, B, To]): To = {
+ val b = cbf(coll1.repr)
+ val elems2 = coll2.iterator
+ val elems3 = coll3.iterator
+
+ for (el1 <- coll1) {
+ if (elems2.hasNext && elems3.hasNext)
+ b ++= f(el1, elems2.next, elems3.next)
+ else
+ return b.result
+ }
+ b.result
+ }
+
+ def filter[To1, To2, To3](f: (El1, El2, El3) => Boolean)(
+ implicit cbf1: CBF[Repr1, El1, To1],
+ cbf2: CBF[Repr2, El2, To2],
+ cbf3: CBF[Repr3, El3, To3]): (To1, To2, To3) = {
+ val b1 = cbf1(coll1.repr)
+ val b2 = cbf2(coll2.repr)
+ val b3 = cbf3(coll3.repr)
+ val elems2 = coll2.iterator
+ val elems3 = coll3.iterator
+ def result = (b1.result, b2.result, b3.result)
+
+ for (el1 <- coll1) {
+ if (elems2.hasNext && elems3.hasNext) {
+ val el2 = elems2.next
+ val el3 = elems3.next
+
+ if (f(el1, el2, el3)) {
+ b1 += el1
+ b2 += el2
+ b3 += el3
+ }
+ }
+ else return result
+ }
+
+ result
+ }
+
+ def exists(f: (El1, El2, El3) => Boolean): Boolean = {
+ val elems2 = coll2.iterator
+ val elems3 = coll3.iterator
+
+ for (el1 <- coll1) {
+ if (elems2.hasNext && elems3.hasNext) {
+ if (f(el1, elems2.next, elems3.next))
+ return true
+ }
+ else return false
+ }
+ false
+ }
+
+ def forall(f: (El1, El2, El3) => Boolean): Boolean =
+ !exists((x, y, z) => !f(x, y, z))
+
+ def foreach[U](f: (El1, El2, El3) => U): Unit = {
+ val elems2 = coll2.iterator
+ val elems3 = coll3.iterator
+
+ for (el1 <- coll1) {
+ if (elems2.hasNext && elems3.hasNext)
+ f(el1, elems2.next, elems3.next)
+ else
+ return
+ }
+ }
+}
+
+object Tuple3Zipped {
+ class Ops[T1, T2, T3](x: (T1, T2, T3)) {
+ def invert[El1, CC1[X] <: TraversableOnce[X], El2, CC2[X] <: TraversableOnce[X], El3, CC3[X] <: TraversableOnce[X], That]
+ (implicit w1: T1 <:< CC1[El1],
+ w2: T2 <:< CC2[El2],
+ w3: T3 <:< CC3[El3],
+ bf: collection.generic.CanBuildFrom[CC1[_], (El1, El2, El3), That]
+ ): That = {
+ val buf = bf(x._1)
+ val it1 = x._1.toIterator
+ val it2 = x._2.toIterator
+ val it3 = x._3.toIterator
+ while (it1.hasNext && it2.hasNext && it3.hasNext)
+ buf += ((it1.next, it2.next, it3.next))
+
+ buf.result
+ }
+
+ def zipped[El1, Repr1, El2, Repr2, El3, Repr3]
+ (implicit w1: T1 => TraversableLike[El1, Repr1],
+ w2: T2 => IterableLike[El2, Repr2],
+ w3: T3 => IterableLike[El3, Repr3]
+ ): Tuple3Zipped[El1, Repr1, El2, Repr2, El3, Repr3] = new Tuple3Zipped(x._1, x._2, x._3)
+ }
+}
diff --git a/src/library/scala/util/matching/Regex.scala b/src/library/scala/util/matching/Regex.scala
index a83619cf01..3655a0a019 100644
--- a/src/library/scala/util/matching/Regex.scala
+++ b/src/library/scala/util/matching/Regex.scala
@@ -145,6 +145,7 @@ import java.util.regex.{ Pattern, Matcher }
*/
@SerialVersionUID(-2094783597747625537L)
class Regex(regex: String, groupNames: String*) extends Serializable {
+ outer =>
import Regex._
@@ -179,15 +180,14 @@ class Regex(regex: String, groupNames: String*) extends Serializable {
* @return The matches
*/
def unapplySeq(target: Any): Option[List[String]] = target match {
- case s: java.lang.CharSequence =>
- val m = pattern.matcher(s)
- if (m.matches) Some((1 to m.groupCount).toList map m.group)
+ case s: CharSequence =>
+ val m = pattern matcher s
+ if (runMatcher(m)) Some((1 to m.groupCount).toList map m.group)
else None
- case Match(s) =>
- unapplySeq(s)
- case _ =>
- None
+ case m: Match => unapplySeq(m.matched)
+ case _ => None
}
+ protected def runMatcher(m: Matcher) = m.matches()
/** Return all matches of this regexp in given character sequence as a [[scala.util.matching.Regex.MatchIterator]],
* which is a special [[scala.collection.Iterator]] that returns the
@@ -373,10 +373,35 @@ class Regex(regex: String, groupNames: String*) extends Serializable {
def split(toSplit: java.lang.CharSequence): Array[String] =
pattern.split(toSplit)
+ /** Create a new Regex with the same pattern, but no requirement that
+ * the entire String matches in extractor patterns. For instance, the strings
+ * shown below lead to successful matches, where they would not otherwise.
+ *
+ * {{{
+ * val dateP1 = """(\d\d\d\d)-(\d\d)-(\d\d)""".r.unanchored
+ *
+ * val dateP1(year, month, day) = "Date 2011-07-15"
+ *
+ * val copyright: String = "Date of this document: 2011-07-15" match {
+ * case dateP1(year, month, day) => "Copyright "+year
+ * case _ => "No copyright"
+ * }
+ * }}}
+ *
+ * @return The new unanchored regex
+ */
+ def unanchored: UnanchoredRegex = new Regex(regex, groupNames: _*) with UnanchoredRegex { override def anchored = outer }
+ def anchored: Regex = this
+
/** The string defining the regular expression */
override def toString = regex
}
+trait UnanchoredRegex extends Regex {
+ override protected def runMatcher(m: Matcher) = m.find()
+ override def unanchored = this
+}
+
/** This object defines inner classes that describe
* regex matches and helper objects. The class hierarchy
* is as follows:
diff --git a/src/library/scala/util/parsing/combinator/Parsers.scala b/src/library/scala/util/parsing/combinator/Parsers.scala
index e5458f89af..66e0a496d8 100644
--- a/src/library/scala/util/parsing/combinator/Parsers.scala
+++ b/src/library/scala/util/parsing/combinator/Parsers.scala
@@ -13,6 +13,7 @@ import scala.collection.mutable.ListBuffer
import scala.annotation.tailrec
import annotation.migration
import language.implicitConversions
+import scala.util.DynamicVariable
// TODO: better error handling (labelling like parsec's <?>)
@@ -154,13 +155,14 @@ trait Parsers {
val successful = true
}
- var lastNoSuccess: NoSuccess = null
+ private lazy val lastNoSuccess = new DynamicVariable[Option[NoSuccess]](None)
/** A common super-class for unsuccessful parse results. */
sealed abstract class NoSuccess(val msg: String, override val next: Input) extends ParseResult[Nothing] { // when we don't care about the difference between Failure and Error
val successful = false
- if (!(lastNoSuccess != null && next.pos < lastNoSuccess.next.pos))
- lastNoSuccess = this
+
+ if (lastNoSuccess.value map { v => !(next.pos < v.next.pos) } getOrElse true)
+ lastNoSuccess.value = Some(this)
def map[U](f: Nothing => U) = this
def mapPartial[U](f: PartialFunction[Nothing, U], error: Nothing => String): ParseResult[U] = this
@@ -596,7 +598,8 @@ trait Parsers {
* @return A parser for elements satisfying p(e).
*/
def acceptIf(p: Elem => Boolean)(err: Elem => String): Parser[Elem] = Parser { in =>
- if (p(in.first)) Success(in.first, in.rest)
+ if (in.atEnd) Failure("end of input", in)
+ else if (p(in.first)) Success(in.first, in.rest)
else Failure(err(in.first), in)
}
@@ -614,7 +617,8 @@ trait Parsers {
* applying `f` to it to produce the result.
*/
def acceptMatch[U](expected: String, f: PartialFunction[Elem, U]): Parser[U] = Parser{ in =>
- if (f.isDefinedAt(in.first)) Success(f(in.first), in.rest)
+ if (in.atEnd) Failure("end of input", in)
+ else if (f.isDefinedAt(in.first)) Success(f(in.first), in.rest)
else Failure(expected+" expected", in)
}
@@ -877,16 +881,15 @@ trait Parsers {
* if `p` consumed all the input.
*/
def phrase[T](p: Parser[T]) = new Parser[T] {
- lastNoSuccess = null
- def apply(in: Input) = p(in) match {
+ def apply(in: Input) = lastNoSuccess.withValue(None) {
+ p(in) match {
case s @ Success(out, in1) =>
if (in1.atEnd)
s
- else if (lastNoSuccess == null || lastNoSuccess.next.pos < in1.pos)
- Failure("end of input expected", in1)
else
- lastNoSuccess
- case _ => lastNoSuccess
+ lastNoSuccess.value filterNot { _.next.pos < in1.pos } getOrElse Failure("end of input expected", in1)
+ case ns => lastNoSuccess.value.getOrElse(ns)
+ }
}
}