diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2015-01-29 10:23:06 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2015-01-29 10:23:06 +1000 |
commit | 09f92d2b74badcdd989e9f17e60344e63b5483cf (patch) | |
tree | bc991e16497412c0c5ca291124ea9d27eb7e6069 /src/library/scala/collection | |
parent | af3881623cde655b37af77edb46b9e8c1b46b067 (diff) | |
parent | 7ba38a07916426314cc3bff6999f3992757e0b26 (diff) | |
download | scala-09f92d2b74badcdd989e9f17e60344e63b5483cf.tar.gz scala-09f92d2b74badcdd989e9f17e60344e63b5483cf.tar.bz2 scala-09f92d2b74badcdd989e9f17e60344e63b5483cf.zip |
Merge commit '7ba38a0' into merge/2.11.x-to-2.12.x-20150129
Conflicts:
build.number
src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala
src/library/scala/collection/Iterator.scala
versions.properties
Diffstat (limited to 'src/library/scala/collection')
47 files changed, 164 insertions, 123 deletions
diff --git a/src/library/scala/collection/GenSeqLike.scala b/src/library/scala/collection/GenSeqLike.scala index c3bad60072..1c4f233e22 100644 --- a/src/library/scala/collection/GenSeqLike.scala +++ b/src/library/scala/collection/GenSeqLike.scala @@ -47,7 +47,7 @@ trait GenSeqLike[+A, +Repr] extends Any with GenIterableLike[A, Repr] with Equal * * @param idx The index to select. * @return the element of this $coll at index `idx`, where `0` indicates the first element. - * @throws `IndexOutOfBoundsException` if `idx` does not satisfy `0 <= idx < length`. + * @throws IndexOutOfBoundsException if `idx` does not satisfy `0 <= idx < length`. */ def apply(idx: Int): A diff --git a/src/library/scala/collection/GenTraversableLike.scala b/src/library/scala/collection/GenTraversableLike.scala index ca098e57b9..8b9d3e7a17 100644 --- a/src/library/scala/collection/GenTraversableLike.scala +++ b/src/library/scala/collection/GenTraversableLike.scala @@ -63,7 +63,7 @@ trait GenTraversableLike[+A, +Repr] extends Any with GenTraversableOnce[A] with /** Selects the first element of this $coll. * $orderDependent * @return the first element of this $coll. - * @throws `NoSuchElementException` if the $coll is empty. + * @throws NoSuchElementException if the $coll is empty. */ def head: A @@ -83,7 +83,7 @@ trait GenTraversableLike[+A, +Repr] extends Any with GenTraversableOnce[A] with * $orderDependent * @return a $coll consisting of all elements of this $coll * except the first one. - * @throws `UnsupportedOperationException` if the $coll is empty. + * @throws UnsupportedOperationException if the $coll is empty. */ def tail: Repr @@ -105,7 +105,7 @@ trait GenTraversableLike[+A, +Repr] extends Any with GenTraversableOnce[A] with * $orderDependent * @return a $coll consisting of all elements of this $coll * except the last one. - * @throws `UnsupportedOperationException` if the $coll is empty. + * @throws UnsupportedOperationException if the $coll is empty. */ def init: Repr diff --git a/src/library/scala/collection/GenTraversableOnce.scala b/src/library/scala/collection/GenTraversableOnce.scala index 0cd91409cf..8c7c754af8 100644 --- a/src/library/scala/collection/GenTraversableOnce.scala +++ b/src/library/scala/collection/GenTraversableOnce.scala @@ -268,7 +268,7 @@ trait GenTraversableOnce[+A] extends Any { * op(x_1, op(x_2, ..., op(x_{n-1}, x_n)...)) * }}} * where `x,,1,,, ..., x,,n,,` are the elements of this $coll. - * @throws `UnsupportedOperationException` if this $coll is empty. + * @throws UnsupportedOperationException if this $coll is empty. */ def reduceRight[B >: A](op: (A, B) => B): B diff --git a/src/library/scala/collection/IndexedSeqOptimized.scala b/src/library/scala/collection/IndexedSeqOptimized.scala index 42cb37aa24..a7e06b4d1a 100755 --- a/src/library/scala/collection/IndexedSeqOptimized.scala +++ b/src/library/scala/collection/IndexedSeqOptimized.scala @@ -141,10 +141,10 @@ trait IndexedSeqOptimized[+A, +Repr] extends Any with IndexedSeqLike[A, Repr] { def drop(n: Int): Repr = slice(n, length) override /*IterableLike*/ - def takeRight(n: Int): Repr = slice(length - n, length) + def takeRight(n: Int): Repr = slice(length - math.max(n, 0), length) override /*IterableLike*/ - def dropRight(n: Int): Repr = slice(0, length - n) + def dropRight(n: Int): Repr = slice(0, length - math.max(n, 0)) override /*TraversableLike*/ def splitAt(n: Int): (Repr, Repr) = (take(n), drop(n)) diff --git a/src/library/scala/collection/IterableViewLike.scala b/src/library/scala/collection/IterableViewLike.scala index e25cc78b6c..c254ed7480 100644 --- a/src/library/scala/collection/IterableViewLike.scala +++ b/src/library/scala/collection/IterableViewLike.scala @@ -155,10 +155,10 @@ trait IterableViewLike[+A, sliding(size, 1) // we could inherit this, but that implies knowledge of the way the super class is implemented. override def dropRight(n: Int): This = - take(thisSeq.length - n) + take(thisSeq.length - math.max(n, 0)) override def takeRight(n: Int): This = - drop(thisSeq.length - n) + drop(thisSeq.length - math.max(n, 0)) override def stringPrefix = "IterableView" } diff --git a/src/library/scala/collection/Iterator.scala b/src/library/scala/collection/Iterator.scala index 4e3abf2286..67cb3f2b63 100644 --- a/src/library/scala/collection/Iterator.scala +++ b/src/library/scala/collection/Iterator.scala @@ -364,7 +364,14 @@ trait Iterator[+A] extends TraversableOnce[A] { * it omits the first `n` values. * @note Reuse: $consumesAndProducesIterator */ - def drop(n: Int): Iterator[A] = sliceIterator(n, -1) + def drop(n: Int): Iterator[A] = { + var j = 0 + while (j < n && hasNext) { + next() + j += 1 + } + this + } /** Creates an iterator returning an interval of the values produced by this iterator. * diff --git a/src/library/scala/collection/JavaConverters.scala b/src/library/scala/collection/JavaConverters.scala index a4fa58b13c..875f6e1c02 100755 --- a/src/library/scala/collection/JavaConverters.scala +++ b/src/library/scala/collection/JavaConverters.scala @@ -37,8 +37,8 @@ import convert._ * val sl2 : scala.collection.mutable.Buffer[Int] = jl.asScala * assert(sl eq sl2) * }}} - * The following conversions also are supported, but the - * direction Scala to Java is done my a more specifically named method: + * The following conversions are also supported, but the + * direction from Scala to Java is done by the more specifically named methods: * `asJavaCollection`, `asJavaEnumeration`, `asJavaDictionary`. * * - `scala.collection.Iterable` <=> `java.util.Collection` diff --git a/src/library/scala/collection/LinearSeq.scala b/src/library/scala/collection/LinearSeq.scala index 49fbb902ab..5a7bb5891e 100644 --- a/src/library/scala/collection/LinearSeq.scala +++ b/src/library/scala/collection/LinearSeq.scala @@ -15,7 +15,14 @@ import generic._ import mutable.Builder /** A base trait for linear sequences. + * * $linearSeqInfo + * + * @define linearSeqInfo + * Linear sequences have reasonably efficient `head`, `tail`, and `isEmpty` methods. + * If these methods provide the fastest way to traverse the collection, a + * collection `Coll` that extends this trait should also extend + * `LinearSeqOptimized[A, Coll[A]]`. */ trait LinearSeq[+A] extends Seq[A] with GenericTraversableTemplate[A, LinearSeq] diff --git a/src/library/scala/collection/LinearSeqLike.scala b/src/library/scala/collection/LinearSeqLike.scala index ff7985bf0d..96e2135fd1 100644 --- a/src/library/scala/collection/LinearSeqLike.scala +++ b/src/library/scala/collection/LinearSeqLike.scala @@ -14,22 +14,10 @@ import scala.annotation.tailrec /** A template trait for linear sequences of type `LinearSeq[A]`. * - * $linearSeqInfo - * - * This trait just implements `iterator` in terms of `isEmpty, ``head`, and `tail`. - * However, see `LinearSeqOptimized` for an implementation trait that overrides operations + * This trait just implements `iterator` and `corresponds` in terms of `isEmpty, ``head`, and `tail`. + * However, see `LinearSeqOptimized` for an implementation trait that overrides many more operations * to make them run faster under the assumption of fast linear access with `head` and `tail`. * - * @define linearSeqInfo - * Linear sequences are defined in terms of three abstract methods, which are assumed - * to have efficient implementations. These are: - * {{{ - * def isEmpty: Boolean - * def head: A - * def tail: Repr - * }}} - * Here, `A` is the type of the sequence elements and `Repr` is the type of the sequence itself. - * * Linear sequences do not add any new methods to `Seq`, but promise efficient implementations * of linear access patterns. * @author Martin Odersky @@ -58,12 +46,18 @@ trait LinearSeqLike[+A, +Repr <: LinearSeqLike[A, Repr]] extends SeqLike[A, Repr val result = these.head; these = these.tail; result } else Iterator.empty.next() - /** Have to clear `these` so the iterator is exhausted like - * it would be without the optimization. - */ override def toList: List[A] = { + /* Have to clear `these` so the iterator is exhausted like + * it would be without the optimization. + * + * Calling "newBuilder.result()" in toList method + * prevents original seq from garbage collection, + * so we use these.take(0) here. + * + * Check SI-8924 for details + */ val xs = these.toList - these = newBuilder.result() + these = these.take(0) xs } } diff --git a/src/library/scala/collection/LinearSeqOptimized.scala b/src/library/scala/collection/LinearSeqOptimized.scala index 8635b090b9..64248aa755 100755 --- a/src/library/scala/collection/LinearSeqOptimized.scala +++ b/src/library/scala/collection/LinearSeqOptimized.scala @@ -13,10 +13,24 @@ import mutable.ListBuffer import immutable.List import scala.annotation.tailrec -/** A template trait for linear sequences of type `LinearSeq[A]` which optimizes - * the implementation of several methods under the assumption of fast linear access. +/** A template trait for linear sequences of type `LinearSeq[A]` which optimizes + * the implementation of various methods under the assumption of fast linear access. + * + * $linearSeqOptim + * + * @define linearSeqOptim + * Linear-optimized sequences implement most operations in in terms of three methods, + * which are assumed to have efficient implementations. These are: + * {{{ + * def isEmpty: Boolean + * def head: A + * def tail: Repr + * }}} + * Here, `A` is the type of the sequence elements and `Repr` is the type of the sequence itself. + * Note that default implementations are provided via inheritance, but these + * should be overridden for performance. + * * - * $linearSeqInfo */ trait LinearSeqOptimized[+A, +Repr <: LinearSeqOptimized[A, Repr]] extends LinearSeqLike[A, Repr] { self: Repr => @@ -44,7 +58,7 @@ trait LinearSeqOptimized[+A, +Repr <: LinearSeqOptimized[A, Repr]] extends Linea /** Selects an element by its index in the $coll. * Note: the execution of `apply` may take time proportial to the index value. - * @throws `IndexOutOfBoundsException` if `idx` does not satisfy `0 <= idx < length`. + * @throws IndexOutOfBoundsException if `idx` does not satisfy `0 <= idx < length`. */ def apply(n: Int): A = { val rest = drop(n) @@ -235,13 +249,16 @@ trait LinearSeqOptimized[+A, +Repr <: LinearSeqOptimized[A, Repr]] extends Linea override /*IterableLike*/ def sameElements[B >: A](that: GenIterable[B]): Boolean = that match { case that1: LinearSeq[_] => - var these = this - var those = that1 - while (!these.isEmpty && !those.isEmpty && these.head == those.head) { - these = these.tail - those = those.tail + // Probably immutable, so check reference identity first (it's quick anyway) + (this eq that1) || { + var these = this + var those = that1 + while (!these.isEmpty && !those.isEmpty && these.head == those.head) { + these = these.tail + those = those.tail + } + these.isEmpty && those.isEmpty } - these.isEmpty && those.isEmpty case _ => super.sameElements(that) } diff --git a/src/library/scala/collection/MapLike.scala b/src/library/scala/collection/MapLike.scala index 38a598321f..b474abc12a 100644 --- a/src/library/scala/collection/MapLike.scala +++ b/src/library/scala/collection/MapLike.scala @@ -222,7 +222,7 @@ self => * but it might be overridden in subclasses. * * @param key the given key value for which a binding is missing. - * @throws `NoSuchElementException` + * @throws NoSuchElementException */ def default(key: A): B = throw new NoSuchElementException("key not found: " + key) diff --git a/src/library/scala/collection/SeqLike.scala b/src/library/scala/collection/SeqLike.scala index fdfb1f2efc..329273df5b 100644 --- a/src/library/scala/collection/SeqLike.scala +++ b/src/library/scala/collection/SeqLike.scala @@ -140,7 +140,15 @@ trait SeqLike[+A, +Repr] extends Any with IterableLike[A, Repr] with GenSeqLike[ if (isEmpty) Iterator(repr) else new PermutationsItr - /** Iterates over combinations. + /** Iterates over combinations. A _combination_ of length `n` is a subsequence of + * the original sequence, with the elements taken in order. Thus, `"xy"` and `"yy"` + * are both length-2 combinations of `"xyy"`, but `"yx"` is not. If there is + * more than one way to generate the same subsequence, only one will be returned. + * + * For example, `"xyyy"` has three different ways to generate `"xy"` depending on + * whether the first, second, or third `"y"` is selected. However, since all are + * identical, only one will be chosen. Which of the three will be taken is an + * implementation detail that is not defined. * * @return An Iterator which traverses the possible n-element combinations of this $coll. * @example `"abbbc".combinations(2) = Iterator(ab, ac, bb, bc)` diff --git a/src/library/scala/collection/SeqViewLike.scala b/src/library/scala/collection/SeqViewLike.scala index 92d5547fd2..587ec133a5 100644 --- a/src/library/scala/collection/SeqViewLike.scala +++ b/src/library/scala/collection/SeqViewLike.scala @@ -55,7 +55,7 @@ trait SeqViewLike[+A, trait Sliced extends super.Sliced with Transformed[A] { def length = iterator.size def apply(idx: Int): A = - if (idx + from < until) self.apply(idx + from) + if (idx >= 0 && idx + from < until) self.apply(idx + from) else throw new IndexOutOfBoundsException(idx.toString) override def foreach[U](f: A => U) = iterator foreach f @@ -83,6 +83,7 @@ trait SeqViewLike[+A, } def length = index(self.length) def apply(idx: Int) = { + if (idx < 0 || idx >= self.length) throw new IndexOutOfBoundsException(idx.toString) val row = findRow(idx, 0, self.length - 1) mapping(self(row)).seq.toSeq(idx - index(row)) } diff --git a/src/library/scala/collection/TraversableLike.scala b/src/library/scala/collection/TraversableLike.scala index a8731a51b1..5a07874fd6 100644 --- a/src/library/scala/collection/TraversableLike.scala +++ b/src/library/scala/collection/TraversableLike.scala @@ -419,7 +419,7 @@ trait TraversableLike[+A, +Repr] extends Any /** Selects the first element of this $coll. * $orderDependent * @return the first element of this $coll. - * @throws `NoSuchElementException` if the $coll is empty. + * @throws NoSuchElementException if the $coll is empty. */ def head: A = { var result: () => A = () => throw new NoSuchElementException @@ -473,7 +473,7 @@ trait TraversableLike[+A, +Repr] extends Any * $orderDependent * @return a $coll consisting of all elements of this $coll * except the last one. - * @throws `UnsupportedOperationException` if the $coll is empty. + * @throws UnsupportedOperationException if the $coll is empty. */ def init: Repr = { if (isEmpty) throw new UnsupportedOperationException("empty.init") diff --git a/src/library/scala/collection/TraversableOnce.scala b/src/library/scala/collection/TraversableOnce.scala index 13cd99d910..2eab58009c 100644 --- a/src/library/scala/collection/TraversableOnce.scala +++ b/src/library/scala/collection/TraversableOnce.scala @@ -159,7 +159,7 @@ trait TraversableOnce[+A] extends Any with GenTraversableOnce[A] { * op( op( ... op(x_1, x_2) ..., x_{n-1}), x_n) * }}} * where `x,,1,,, ..., x,,n,,` are the elements of this $coll. - * @throws `UnsupportedOperationException` if this $coll is empty. */ + * @throws UnsupportedOperationException if this $coll is empty. */ def reduceLeft[B >: A](op: (B, A) => B): B = { if (isEmpty) throw new UnsupportedOperationException("empty.reduceLeft") diff --git a/src/library/scala/collection/concurrent/Map.scala b/src/library/scala/collection/concurrent/Map.scala index 02e5dd01f5..2eea15b8dc 100644 --- a/src/library/scala/collection/concurrent/Map.scala +++ b/src/library/scala/collection/concurrent/Map.scala @@ -20,7 +20,7 @@ package collection.concurrent * @tparam A the key type of the map * @tparam B the value type of the map * - * @define Coll `ConcurrentMap` + * @define Coll `concurrent.Map` * @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/GenericTraversableTemplate.scala b/src/library/scala/collection/generic/GenericTraversableTemplate.scala index cd48cd23f4..54455c531a 100644 --- a/src/library/scala/collection/generic/GenericTraversableTemplate.scala +++ b/src/library/scala/collection/generic/GenericTraversableTemplate.scala @@ -25,7 +25,7 @@ import scala.language.higherKinds * @author Martin Odersky * @since 2.8 * @define coll collection - * @define Coll CC + * @define Coll Traversable */ trait GenericTraversableTemplate[+A, +CC[X] <: GenTraversable[X]] extends HasNewBuilder[A, CC[A] @uncheckedVariance] { @@ -45,7 +45,7 @@ trait GenericTraversableTemplate[+A, +CC[X] <: GenTraversable[X]] extends HasNew /** Selects the first element of this $coll. * * @return the first element of this $coll. - * @throws `NoSuchElementException` if the $coll is empty. + * @throws NoSuchElementException if the $coll is empty. */ def head: A @@ -202,7 +202,7 @@ trait GenericTraversableTemplate[+A, +CC[X] <: GenTraversable[X]] extends HasNew * element type of this $coll is a `Traversable`. * @return a two-dimensional $coll of ${coll}s which has as ''n''th row * the ''n''th column of this $coll. - * @throws `IllegalArgumentException` if all collections in this $coll + * @throws IllegalArgumentException if all collections in this $coll * are not of the same size. */ @migration("`transpose` throws an `IllegalArgumentException` if collections are not uniformly sized.", "2.9.0") diff --git a/src/library/scala/collection/immutable/List.scala b/src/library/scala/collection/immutable/List.scala index a8f1149615..89b4ee1145 100644 --- a/src/library/scala/collection/immutable/List.scala +++ b/src/library/scala/collection/immutable/List.scala @@ -80,6 +80,7 @@ import java.io.{ObjectOutputStream, ObjectInputStream} * @define mayNotTerminateInf * @define willNotTerminateInf */ +@SerialVersionUID(-6084104484083858598L) // value computed by serialver for 2.11.2, annotation added in 2.11.4 sealed abstract class List[+A] extends AbstractSeq[A] with LinearSeq[A] with Product @@ -290,7 +291,6 @@ sealed abstract class List[+A] extends AbstractSeq[A] if (this eq Nil) Nil.asInstanceOf[That] else { var rest = this var h: ::[B] = null - var x: A = null.asInstanceOf[A] // Special case for first element do { val x: Any = pf.applyOrElse(rest.head, List.partialNotApplied) @@ -428,13 +428,14 @@ case object Nil extends List[Nothing] { } /** A non empty list characterized by a head and a tail. - * @param hd the first element of the list + * @param head the first element of the list * @param tl the list containing the remaining elements of this list after the first one. * @tparam B the type of the list elements. * @author Martin Odersky * @version 1.0, 15/07/2003 * @since 2.8 */ +@SerialVersionUID(509929039250432923L) // value computed by serialver for 2.11.2, annotation added in 2.11.4 final case class ::[B](override val head: B, private[scala] var tl: List[B]) extends List[B] { override def tail : List[B] = tl override def isEmpty: Boolean = false diff --git a/src/library/scala/collection/immutable/ListSet.scala b/src/library/scala/collection/immutable/ListSet.scala index 89d1a9640e..a6e6fba0a5 100644 --- a/src/library/scala/collection/immutable/ListSet.scala +++ b/src/library/scala/collection/immutable/ListSet.scala @@ -111,7 +111,7 @@ class ListSet[A] extends AbstractSet[A] /** Creates a new iterator over all elements contained in this set. * - * @throws Predef.NoSuchElementException + * @throws java.util.NoSuchElementException * @return the new iterator */ def iterator: Iterator[A] = new AbstractIterator[A] { @@ -127,12 +127,12 @@ class ListSet[A] extends AbstractSet[A] } /** - * @throws Predef.NoSuchElementException + * @throws java.util.NoSuchElementException */ override def head: A = throw new NoSuchElementException("Set has no elements") /** - * @throws Predef.NoSuchElementException + * @throws java.util.NoSuchElementException */ override def tail: ListSet[A] = throw new NoSuchElementException("Next of an empty set") diff --git a/src/library/scala/collection/immutable/PagedSeq.scala b/src/library/scala/collection/immutable/PagedSeq.scala index fb9f6703a9..8910ee16b9 100644 --- a/src/library/scala/collection/immutable/PagedSeq.scala +++ b/src/library/scala/collection/immutable/PagedSeq.scala @@ -158,7 +158,7 @@ extends scala.collection.AbstractSeq[T] * @note Calling this method will force the entire sequence to be read. */ def length: Int = { - while (!latest.isLast) addMore() + while (!latest.isLast && latest.end < end) addMore() (latest.end min end) - start } @@ -175,7 +175,8 @@ extends scala.collection.AbstractSeq[T] */ override def isDefinedAt(index: Int) = index >= 0 && index < end - start && { - val p = page(index + start); index + start < p.end + val absidx = index + start + absidx >= 0 && absidx < page(absidx).end } /** The subsequence from index `start` up to `end -1` if `end` @@ -192,6 +193,9 @@ extends scala.collection.AbstractSeq[T] if (f.next eq null) f.addMore(more) f = f.next } + // Warning -- not refining `more` means that slices can freely request and obtain + // data outside of their slice. This is part of the design of PagedSeq + // (to read pages!) but can be surprising. new PagedSeq(more, f, s, e) } diff --git a/src/library/scala/collection/immutable/Queue.scala b/src/library/scala/collection/immutable/Queue.scala index 264304db68..98266716cc 100644 --- a/src/library/scala/collection/immutable/Queue.scala +++ b/src/library/scala/collection/immutable/Queue.scala @@ -53,7 +53,7 @@ class Queue[+A] protected(protected val in: List[A], protected val out: List[A]) * * @param n index of the element to return * @return the element at position `n` in this queue. - * @throws Predef.NoSuchElementException if the queue is too short. + * @throws java.util.NoSuchElementException if the queue is too short. */ override def apply(n: Int): A = { val len = out.length @@ -120,7 +120,7 @@ class Queue[+A] protected(protected val in: List[A], protected val out: List[A]) /** Returns a tuple with the first element in the queue, * and a new queue with this element removed. * - * @throws Predef.NoSuchElementException + * @throws java.util.NoSuchElementException * @return the first element of the queue. */ def dequeue: (A, Queue[A]) = out match { @@ -139,7 +139,7 @@ class Queue[+A] protected(protected val in: List[A], protected val out: List[A]) /** Returns the first element in the queue, or throws an error if there * is no element contained in the queue. * - * @throws Predef.NoSuchElementException + * @throws java.util.NoSuchElementException * @return the first element. */ def front: A = head diff --git a/src/library/scala/collection/immutable/Stack.scala b/src/library/scala/collection/immutable/Stack.scala index b77b16f23f..1c28093b2c 100644 --- a/src/library/scala/collection/immutable/Stack.scala +++ b/src/library/scala/collection/immutable/Stack.scala @@ -95,7 +95,7 @@ class Stack[+A] protected (protected val elems: List[A]) /** Returns the top element of the stack. An error is signaled if * there is no element on the stack. * - * @throws Predef.NoSuchElementException + * @throws java.util.NoSuchElementException * @return the top element. */ def top: A = @@ -105,7 +105,7 @@ class Stack[+A] protected (protected val elems: List[A]) /** Removes the top element from the stack. * Note: should return `(A, Stack[A])` as for queues (mics) * - * @throws Predef.NoSuchElementException + * @throws java.util.NoSuchElementException * @return the new stack without the former top element. */ def pop: Stack[A] = diff --git a/src/library/scala/collection/immutable/Stream.scala b/src/library/scala/collection/immutable/Stream.scala index 91a4e1c43d..c95d4665b9 100644 --- a/src/library/scala/collection/immutable/Stream.scala +++ b/src/library/scala/collection/immutable/Stream.scala @@ -225,7 +225,7 @@ self => * }}} * * @return The first element of the `Stream`. - * @throws Predef.NoSuchElementException if the stream is empty. + * @throws java.util.NoSuchElementException if the stream is empty. */ def head: A @@ -236,7 +236,7 @@ self => * returns the lazy result. * * @return The tail of the `Stream`. - * @throws Predef.UnsupportedOperationException if the stream is empty. + * @throws UnsupportedOperationException if the stream is empty. */ def tail: Stream[A] @@ -878,7 +878,7 @@ self => * @return A new `Stream` containing everything but the last element. If your * `Stream` represents an infinite series, this method will not return. * - * @throws `Predef.UnsupportedOperationException` if the stream is empty. + * @throws UnsupportedOperationException if the stream is empty. */ override def init: Stream[A] = if (isEmpty) super.init diff --git a/src/library/scala/collection/immutable/StringLike.scala b/src/library/scala/collection/immutable/StringLike.scala index bf93a38f55..f0daaf25a5 100644 --- a/src/library/scala/collection/immutable/StringLike.scala +++ b/src/library/scala/collection/immutable/StringLike.scala @@ -230,31 +230,31 @@ self => def r(groupNames: String*): Regex = new Regex(toString, groupNames: _*) /** - * @throws `java.lang.IllegalArgumentException` - If the string does not contain a parsable boolean. + * @throws java.lang.IllegalArgumentException - If the string does not contain a parsable boolean. */ def toBoolean: Boolean = parseBoolean(toString) /** - * @throws `java.lang.NumberFormatException` - If the string does not contain a parsable byte. + * @throws java.lang.NumberFormatException - If the string does not contain a parsable byte. */ def toByte: Byte = java.lang.Byte.parseByte(toString) /** - * @throws `java.lang.NumberFormatException` - If the string does not contain a parsable short. + * @throws java.lang.NumberFormatException - If the string does not contain a parsable short. */ def toShort: Short = java.lang.Short.parseShort(toString) /** - * @throws `java.lang.NumberFormatException` - If the string does not contain a parsable int. + * @throws java.lang.NumberFormatException - If the string does not contain a parsable int. */ def toInt: Int = java.lang.Integer.parseInt(toString) /** - * @throws `java.lang.NumberFormatException` - If the string does not contain a parsable long. + * @throws java.lang.NumberFormatException - If the string does not contain a parsable long. */ def toLong: Long = java.lang.Long.parseLong(toString) /** - * @throws `java.lang.NumberFormatException` - If the string does not contain a parsable float. + * @throws java.lang.NumberFormatException - If the string does not contain a parsable float. */ def toFloat: Float = java.lang.Float.parseFloat(toString) /** - * @throws `java.lang.NumberFormatException` - If the string does not contain a parsable double. + * @throws java.lang.NumberFormatException - If the string does not contain a parsable double. */ def toDouble: Double = java.lang.Double.parseDouble(toString) @@ -287,7 +287,7 @@ self => * understands. * * @param args the arguments used to instantiating the pattern. - * @throws `java.lang.IllegalArgumentException` + * @throws java.lang.IllegalArgumentException */ def format(args : Any*): String = java.lang.String.format(toString, args map unwrapArg: _*) @@ -304,7 +304,7 @@ self => * * @param l an instance of `java.util.Locale` * @param args the arguments used to instantiating the pattern. - * @throws `java.lang.IllegalArgumentException` + * @throws java.lang.IllegalArgumentException */ def formatLocal(l: java.util.Locale, args: Any*): String = java.lang.String.format(l, toString, args map unwrapArg: _*) diff --git a/src/library/scala/collection/immutable/TreeMap.scala b/src/library/scala/collection/immutable/TreeMap.scala index 8cc99a53e6..662075cd93 100644 --- a/src/library/scala/collection/immutable/TreeMap.scala +++ b/src/library/scala/collection/immutable/TreeMap.scala @@ -101,8 +101,8 @@ class TreeMap[A, +B] private (tree: RB.Tree[A, B])(implicit val ordering: Orderi else new TreeMap(RB.slice(tree, from, until)) } - override def dropRight(n: Int) = take(size - n) - override def takeRight(n: Int) = drop(size - n) + override def dropRight(n: Int) = take(size - math.max(n, 0)) + override def takeRight(n: Int) = drop(size - math.max(n, 0)) override def splitAt(n: Int) = (take(n), drop(n)) private[this] def countWhile(p: ((A, B)) => Boolean): Int = { diff --git a/src/library/scala/collection/immutable/TreeSet.scala b/src/library/scala/collection/immutable/TreeSet.scala index 681dbbd1a8..7378211db0 100644 --- a/src/library/scala/collection/immutable/TreeSet.scala +++ b/src/library/scala/collection/immutable/TreeSet.scala @@ -87,8 +87,8 @@ class TreeSet[A] private (tree: RB.Tree[A, Unit])(implicit val ordering: Orderin else newSet(RB.slice(tree, from, until)) } - override def dropRight(n: Int) = take(size - n) - override def takeRight(n: Int) = drop(size - n) + override def dropRight(n: Int) = take(size - math.max(n, 0)) + override def takeRight(n: Int) = drop(size - math.max(n, 0)) override def splitAt(n: Int) = (take(n), drop(n)) private[this] def countWhile(p: A => Boolean): Int = { diff --git a/src/library/scala/collection/mutable/AnyRefMap.scala b/src/library/scala/collection/mutable/AnyRefMap.scala index 2c7e76c5f5..ed6ca1939d 100644 --- a/src/library/scala/collection/mutable/AnyRefMap.scala +++ b/src/library/scala/collection/mutable/AnyRefMap.scala @@ -224,7 +224,7 @@ extends AbstractMap[K, V] override def put(key: K, value: V): Option[V] = { val h = hashOf(key) val k = key - var i = seekEntryOrOpen(h, k) + val i = seekEntryOrOpen(h, k) if (i < 0) { val j = i & IndexMask _hashes(j) = h @@ -251,7 +251,7 @@ extends AbstractMap[K, V] override def update(key: K, value: V): Unit = { val h = hashOf(key) val k = key - var i = seekEntryOrOpen(h, k) + val i = seekEntryOrOpen(h, k) if (i < 0) { val j = i & IndexMask _hashes(j) = h diff --git a/src/library/scala/collection/mutable/ArrayBuffer.scala b/src/library/scala/collection/mutable/ArrayBuffer.scala index 2d43b352c5..011fd415ee 100644 --- a/src/library/scala/collection/mutable/ArrayBuffer.scala +++ b/src/library/scala/collection/mutable/ArrayBuffer.scala @@ -30,8 +30,8 @@ import parallel.mutable.ParArray * * @tparam A the type of this arraybuffer's elements. * - * @define Coll `ArrayBuffer` - * @define coll arraybuffer + * @define Coll `mutable.ArrayBuffer` + * @define coll array buffer * @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]]` * is defined in object `ArrayBuffer`. @@ -128,21 +128,22 @@ class ArrayBuffer[A](override protected val initialSize: Int) override def ++=:(xs: TraversableOnce[A]): this.type = { insertAll(0, xs.toTraversable); this } /** Inserts new elements at the index `n`. Opposed to method - * `update`, this method will not replace an element with a + * `update`, this method will not replace an element with a new * one. Instead, it will insert a new element at index `n`. * * @param n the index where a new element will be inserted. * @param seq the traversable object providing all elements to insert. - * @throws Predef.IndexOutOfBoundsException if `n` is out of bounds. + * @throws IndexOutOfBoundsException if `n` is out of bounds. */ def insertAll(n: Int, seq: Traversable[A]) { if (n < 0 || n > size0) throw new IndexOutOfBoundsException(n.toString) - val xs = seq.toList - val len = xs.length - ensureSize(size0 + len) + val len = seq.size + val newSize = size0 + len + ensureSize(newSize) + copy(n, n + len, size0 - n) - xs.copyToArray(array.asInstanceOf[scala.Array[Any]], n) - size0 += len + seq.copyToArray(array.asInstanceOf[Array[Any]], n) + size0 = newSize } /** Removes the element on a given index position. It takes time linear in @@ -150,7 +151,7 @@ class ArrayBuffer[A](override protected val initialSize: Int) * * @param n the index which refers to the first element to delete. * @param count the number of elements to delete - * @throws Predef.IndexOutOfBoundsException if `n` is out of bounds. + * @throws IndexOutOfBoundsException if `n` is out of bounds. */ override def remove(n: Int, count: Int) { require(count >= 0, "removing negative number of elements") diff --git a/src/library/scala/collection/mutable/BitSet.scala b/src/library/scala/collection/mutable/BitSet.scala index 43d23acc1a..faa4155317 100644 --- a/src/library/scala/collection/mutable/BitSet.scala +++ b/src/library/scala/collection/mutable/BitSet.scala @@ -110,7 +110,7 @@ class BitSet(protected final var elems: Array[Long]) extends AbstractSet[Int] * @return the bitset itself. */ def |= (other: BitSet): this.type = { - ensureCapacity(other.nwords) + ensureCapacity(other.nwords - 1) for (i <- 0 until other.nwords) elems(i) = elems(i) | other.word(i) this @@ -121,7 +121,7 @@ class BitSet(protected final var elems: Array[Long]) extends AbstractSet[Int] * @return the bitset itself. */ def &= (other: BitSet): this.type = { - ensureCapacity(other.nwords) + ensureCapacity(other.nwords - 1) for (i <- 0 until other.nwords) elems(i) = elems(i) & other.word(i) this @@ -132,7 +132,7 @@ class BitSet(protected final var elems: Array[Long]) extends AbstractSet[Int] * @return the bitset itself. */ def ^= (other: BitSet): this.type = { - ensureCapacity(other.nwords) + ensureCapacity(other.nwords - 1) for (i <- 0 until other.nwords) elems(i) = elems(i) ^ other.word(i) this @@ -143,7 +143,7 @@ class BitSet(protected final var elems: Array[Long]) extends AbstractSet[Int] * @return the bitset itself. */ def &~= (other: BitSet): this.type = { - ensureCapacity(other.nwords) + ensureCapacity(other.nwords - 1) for (i <- 0 until other.nwords) elems(i) = elems(i) & ~other.word(i) this diff --git a/src/library/scala/collection/mutable/IndexedSeqView.scala b/src/library/scala/collection/mutable/IndexedSeqView.scala index 31a4749960..7acdeeff18 100644 --- a/src/library/scala/collection/mutable/IndexedSeqView.scala +++ b/src/library/scala/collection/mutable/IndexedSeqView.scala @@ -50,7 +50,7 @@ self => trait Sliced extends super.Sliced with Transformed[A] { override def length = endpoints.width def update(idx: Int, elem: A) = - if (idx + from < until) self.update(idx + from, elem) + if (idx >= 0 && idx + from < until) self.update(idx + from, elem) else throw new IndexOutOfBoundsException(idx.toString) } diff --git a/src/library/scala/collection/mutable/ListBuffer.scala b/src/library/scala/collection/mutable/ListBuffer.scala index a611048da2..1906c47f61 100644 --- a/src/library/scala/collection/mutable/ListBuffer.scala +++ b/src/library/scala/collection/mutable/ListBuffer.scala @@ -132,7 +132,7 @@ final class ListBuffer[A] * * @param n the index of the element to replace. * @param x the new element. - * @throws Predef.IndexOutOfBoundsException if `n` is out of bounds. + * @throws IndexOutOfBoundsException if `n` is out of bounds. */ def update(n: Int, x: A) { // We check the bounds early, so that we don't trigger copying. @@ -217,7 +217,7 @@ final class ListBuffer[A] * * @param n the index where a new element will be inserted. * @param seq the iterable object providing all elements to insert. - * @throws Predef.IndexOutOfBoundsException if `n` is out of bounds. + * @throws IndexOutOfBoundsException if `n` is out of bounds. */ def insertAll(n: Int, seq: Traversable[A]) { // We check the bounds early, so that we don't trigger copying. @@ -330,7 +330,7 @@ final class ListBuffer[A] * @param n the index which refers to the element to delete. * @return n the element that was formerly at position `n`. * @note an element must exists at position `n`. - * @throws Predef.IndexOutOfBoundsException if `n` is out of bounds. + * @throws IndexOutOfBoundsException if `n` is out of bounds. */ def remove(n: Int): A = { if (n < 0 || n >= len) throw new IndexOutOfBoundsException(n.toString()) diff --git a/src/library/scala/collection/mutable/LongMap.scala b/src/library/scala/collection/mutable/LongMap.scala index eea33e3044..925e607151 100644 --- a/src/library/scala/collection/mutable/LongMap.scala +++ b/src/library/scala/collection/mutable/LongMap.scala @@ -81,7 +81,7 @@ extends AbstractMap[Long, V] private def toIndex(k: Long): Int = { // Part of the MurmurHash3 32 bit finalizer val h = ((k ^ (k >>> 32)) & 0xFFFFFFFFL).toInt - var x = (h ^ (h >>> 16)) * 0x85EBCA6B + val x = (h ^ (h >>> 16)) * 0x85EBCA6B (x ^ (x >>> 13)) & mask } @@ -311,7 +311,7 @@ extends AbstractMap[Long, V] } } else { - var i = seekEntryOrOpen(key) + val i = seekEntryOrOpen(key) if (i < 0) { val j = i & IndexMask _keys(j) = key diff --git a/src/library/scala/collection/mutable/MapLike.scala b/src/library/scala/collection/mutable/MapLike.scala index 8ba31d47b6..b87ca54965 100644 --- a/src/library/scala/collection/mutable/MapLike.scala +++ b/src/library/scala/collection/mutable/MapLike.scala @@ -18,6 +18,8 @@ import scala.collection.parallel.mutable.ParMap /** A template trait for mutable maps. * $mapNote * $mapTags + * @define Coll `mutable.Map` + * @define coll mutable map * @since 2.8 * * @define mapNote diff --git a/src/library/scala/collection/mutable/MultiMap.scala b/src/library/scala/collection/mutable/MultiMap.scala index 78dfc35268..ac2ebf31d8 100644 --- a/src/library/scala/collection/mutable/MultiMap.scala +++ b/src/library/scala/collection/mutable/MultiMap.scala @@ -65,10 +65,9 @@ trait MultiMap[A, B] extends Map[A, Set[B]] { */ protected def makeSet: Set[B] = new HashSet[B] - /** Assigns the specified `value` to a specified `key`, replacing - * the existing value assigned to that `key` if it is equal to - * the specified value. Otherwise, simply adds another binding to - * the `key`. + /** Assigns the specified `value` to a specified `key`. If the key + * already has a binding to equal to `value`, nothing is changed; + * otherwise a new binding is added for that `key`. * * @param key The key to which to bind the new value. * @param value The value to bind to the key. diff --git a/src/library/scala/collection/mutable/MutableList.scala b/src/library/scala/collection/mutable/MutableList.scala index a0d3ee0ef0..b852a4747b 100644 --- a/src/library/scala/collection/mutable/MutableList.scala +++ b/src/library/scala/collection/mutable/MutableList.scala @@ -22,6 +22,8 @@ import immutable.{List, Nil} * @author Martin Odersky * @version 2.8 * @since 1 + * @define Coll `mutable.MutableList` + * @define coll mutable list * @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. */ diff --git a/src/library/scala/collection/mutable/PriorityQueue.scala b/src/library/scala/collection/mutable/PriorityQueue.scala index a6e538528a..d3c4161e3b 100644 --- a/src/library/scala/collection/mutable/PriorityQueue.scala +++ b/src/library/scala/collection/mutable/PriorityQueue.scala @@ -126,7 +126,7 @@ class PriorityQueue[A](implicit val ord: Ordering[A]) /** Returns the element with the highest priority in the queue, * and removes this element from the queue. * - * @throws Predef.NoSuchElementException + * @throws java.util.NoSuchElementException * @return the element with the highest priority. */ def dequeue(): A = @@ -247,13 +247,6 @@ class PriorityQueue[A](implicit val ord: Ordering[A]) * @return a priority queue with the same elements. */ override def clone(): PriorityQueue[A] = new PriorityQueue[A] ++= this.iterator - - // def printstate() { - // println("-----------------------") - // println("Size: " + resarr.p_size0) - // println("Internal array: " + resarr.p_array.toList) - // println(toString) - // } } diff --git a/src/library/scala/collection/mutable/Queue.scala b/src/library/scala/collection/mutable/Queue.scala index 7c890fe309..03d387a535 100644 --- a/src/library/scala/collection/mutable/Queue.scala +++ b/src/library/scala/collection/mutable/Queue.scala @@ -58,7 +58,7 @@ extends MutableList[A] /** Returns the first element in the queue, and removes this element * from the queue. * - * @throws Predef.NoSuchElementException + * @throws java.util.NoSuchElementException * @return the first element of the queue. */ def dequeue(): A = diff --git a/src/library/scala/collection/mutable/SetLike.scala b/src/library/scala/collection/mutable/SetLike.scala index cbe7a639dd..40a5c93064 100644 --- a/src/library/scala/collection/mutable/SetLike.scala +++ b/src/library/scala/collection/mutable/SetLike.scala @@ -219,7 +219,7 @@ trait SetLike[A, +This <: SetLike[A, This] with Set[A]] /** Send a message to this scriptable object. * * @param cmd the message to send. - * @throws `Predef.UnsupportedOperationException` + * @throws UnsupportedOperationException * if the message was not understood. */ @deprecated("Scripting is deprecated.", "2.11.0") diff --git a/src/library/scala/collection/mutable/Stack.scala b/src/library/scala/collection/mutable/Stack.scala index 53b6c59939..1a92f23b7b 100644 --- a/src/library/scala/collection/mutable/Stack.scala +++ b/src/library/scala/collection/mutable/Stack.scala @@ -125,7 +125,7 @@ extends AbstractSeq[A] * the element from the stack. An error is signaled if there is no * element on the stack. * - * @throws Predef.NoSuchElementException + * @throws java.util.NoSuchElementException * @return the top element */ def top: A = @@ -133,7 +133,7 @@ extends AbstractSeq[A] /** Removes the top element from the stack. * - * @throws Predef.NoSuchElementException + * @throws java.util.NoSuchElementException * @return the top element */ def pop(): A = { diff --git a/src/library/scala/collection/mutable/StringBuilder.scala b/src/library/scala/collection/mutable/StringBuilder.scala index 498e9e461e..c56d40786e 100644 --- a/src/library/scala/collection/mutable/StringBuilder.scala +++ b/src/library/scala/collection/mutable/StringBuilder.scala @@ -22,6 +22,8 @@ import immutable.StringLike * @author Martin Odersky * @version 2.8 * @since 2.7 + * @define Coll `mutable.IndexedSeq` + * @define coll string builder * @see [[http://docs.scala-lang.org/overviews/collections/concrete-mutable-collection-classes.html# "Scala's Collection Library overview"]] * section on `StringBuilders` for more information. */ diff --git a/src/library/scala/collection/parallel/ParIterable.scala b/src/library/scala/collection/parallel/ParIterable.scala index 2ceeb18eef..a5ba8c49ad 100644 --- a/src/library/scala/collection/parallel/ParIterable.scala +++ b/src/library/scala/collection/parallel/ParIterable.scala @@ -23,9 +23,6 @@ import scala.collection.parallel.mutable.ParArrayCombiner * * @author Aleksandar Prokopec * @since 2.9 - * - * @define Coll `ParIterable` - * @define coll parallel iterable */ trait ParIterable[+T] extends GenIterable[T] diff --git a/src/library/scala/collection/parallel/ParIterableLike.scala b/src/library/scala/collection/parallel/ParIterableLike.scala index 445edd23cb..2b54e05841 100644 --- a/src/library/scala/collection/parallel/ParIterableLike.scala +++ b/src/library/scala/collection/parallel/ParIterableLike.scala @@ -150,7 +150,8 @@ import scala.collection.parallel.ParallelCollectionImplicits._ * @define indexsignalling * This method will use `indexFlag` signalling capabilities. This means * that splitters may set and read the `indexFlag` state. - * + * @define Coll `ParIterable` + * @define coll parallel iterable */ trait ParIterableLike[+T, +Repr <: ParIterable[T], +Sequential <: Iterable[T] with IterableLike[T, Sequential]] extends GenIterableLike[T, Repr] diff --git a/src/library/scala/collection/parallel/ParMapLike.scala b/src/library/scala/collection/parallel/ParMapLike.scala index d2b15c727a..ee1334ba55 100644 --- a/src/library/scala/collection/parallel/ParMapLike.scala +++ b/src/library/scala/collection/parallel/ParMapLike.scala @@ -24,6 +24,8 @@ import scala.collection.generic.Signalling * * @tparam K the key type of the map * @tparam V the value type of the map + * @define Coll `ParMap` + * @define coll parallel map * * @author Aleksandar Prokopec * @since 2.9 diff --git a/src/library/scala/collection/parallel/ParSetLike.scala b/src/library/scala/collection/parallel/ParSetLike.scala index 4e9a2e5751..4feda5ff07 100644 --- a/src/library/scala/collection/parallel/ParSetLike.scala +++ b/src/library/scala/collection/parallel/ParSetLike.scala @@ -20,6 +20,8 @@ import scala.collection.Set * $sideeffects * * @tparam T the element type of the set + * @define Coll `ParSet` + * @define coll parallel set * * @author Aleksandar Prokopec * @since 2.9 diff --git a/src/library/scala/collection/parallel/mutable/ParMapLike.scala b/src/library/scala/collection/parallel/mutable/ParMapLike.scala index 42027f5bac..5d99394a50 100644 --- a/src/library/scala/collection/parallel/mutable/ParMapLike.scala +++ b/src/library/scala/collection/parallel/mutable/ParMapLike.scala @@ -22,6 +22,8 @@ import scala.collection.generic.Shrinkable * * @tparam K the key type of the map * @tparam V the value type of the map + * @define Coll `ParMap` + * @define coll parallel map * * @author Aleksandar Prokopec * @since 2.9 diff --git a/src/library/scala/collection/parallel/mutable/ParSet.scala b/src/library/scala/collection/parallel/mutable/ParSet.scala index 9367f1424d..4e2d3e0e4c 100644 --- a/src/library/scala/collection/parallel/mutable/ParSet.scala +++ b/src/library/scala/collection/parallel/mutable/ParSet.scala @@ -14,9 +14,6 @@ import scala.collection.parallel.Combiner /** A mutable variant of `ParSet`. * - * @define Coll `mutable.ParSet` - * @define coll mutable parallel set - * * @author Aleksandar Prokopec */ trait ParSet[T] diff --git a/src/library/scala/collection/parallel/mutable/ParSetLike.scala b/src/library/scala/collection/parallel/mutable/ParSetLike.scala index 13af5ed649..08aa3b024b 100644 --- a/src/library/scala/collection/parallel/mutable/ParSetLike.scala +++ b/src/library/scala/collection/parallel/mutable/ParSetLike.scala @@ -21,6 +21,8 @@ import scala.collection.generic.Shrinkable * $sideeffects * * @tparam T the element type of the set + * @define Coll `mutable.ParSet` + * @define coll mutable parallel set * * @author Aleksandar Prokopec * @since 2.9 |