diff options
Diffstat (limited to 'src/library')
14 files changed, 87 insertions, 98 deletions
diff --git a/src/library/scala/collection/IterableLike.scala b/src/library/scala/collection/IterableLike.scala index 8d1fa80815..540bd84b79 100644 --- a/src/library/scala/collection/IterableLike.scala +++ b/src/library/scala/collection/IterableLike.scala @@ -171,7 +171,7 @@ self => * fewer elements than size. */ def sliding(size: Int): Iterator[Repr] = sliding(size, 1) - + /** Groups elements in fixed size blocks by passing a "sliding window" * over them (as opposed to partitioning them, as is done in grouped.) * @see [[scala.collection.Iterator]], method `sliding` @@ -293,7 +293,6 @@ self => override /*TraversableLike*/ def view = new IterableView[A, Repr] { protected lazy val underlying = self.repr - override def isEmpty = self.isEmpty override def iterator = self.iterator } diff --git a/src/library/scala/collection/SeqLike.scala b/src/library/scala/collection/SeqLike.scala index 48e1e04c44..603e0b6497 100644 --- a/src/library/scala/collection/SeqLike.scala +++ b/src/library/scala/collection/SeqLike.scala @@ -630,7 +630,6 @@ trait SeqLike[+A, +Repr] extends Any with IterableLike[A, Repr] with GenSeqLike[ override def view = new SeqView[A, Repr] { protected lazy val underlying = self.repr - override def isEmpty = self.isEmpty override def iterator = self.iterator override def length = self.length override def apply(idx: Int) = self.apply(idx) diff --git a/src/library/scala/collection/TraversableLike.scala b/src/library/scala/collection/TraversableLike.scala index 5ea1faa0df..c1a68b6b16 100644 --- a/src/library/scala/collection/TraversableLike.scala +++ b/src/library/scala/collection/TraversableLike.scala @@ -660,7 +660,6 @@ trait TraversableLike[+A, +Repr] extends Any def view = new TraversableView[A, Repr] { protected lazy val underlying = self.repr override def foreach[U](f: A => U) = self foreach f - override def isEmpty = self.isEmpty } /** Creates a non-strict view of a slice of this $coll. diff --git a/src/library/scala/collection/TraversableViewLike.scala b/src/library/scala/collection/TraversableViewLike.scala index 6846a505bf..36f6210ef4 100644 --- a/src/library/scala/collection/TraversableViewLike.scala +++ b/src/library/scala/collection/TraversableViewLike.scala @@ -192,15 +192,6 @@ trait TraversableViewLike[+A, override def span(p: A => Boolean): (This, This) = (newTakenWhile(p), newDroppedWhile(p)) override def splitAt(n: Int): (This, This) = (newTaken(n), newDropped(n)) - // Without this, isEmpty tests go back to the Traversable default, which - // involves starting a foreach, which can force the first element of the - // view. This is just a backstop - it's overridden at all the "def view" - // instantiation points in the collections where the Coll type is known. - override def isEmpty = underlying match { - case x: GenTraversableOnce[_] => x.isEmpty - case _ => super.isEmpty - } - override def scanLeft[B, That](z: B)(op: (B, A) => B)(implicit bf: CanBuildFrom[This, B, That]): That = newForced(thisSeq.scanLeft(z)(op)).asInstanceOf[That] diff --git a/src/library/scala/collection/generic/GenTraversableFactory.scala b/src/library/scala/collection/generic/GenTraversableFactory.scala index 318780ef6d..b36dd3ccaf 100644 --- a/src/library/scala/collection/generic/GenTraversableFactory.scala +++ b/src/library/scala/collection/generic/GenTraversableFactory.scala @@ -36,7 +36,7 @@ import scala.language.higherKinds * @see GenericCanBuildFrom */ abstract class GenTraversableFactory[CC[X] <: GenTraversable[X] with GenericTraversableTemplate[X, CC]] - extends GenericCompanion[CC] { +extends GenericCompanion[CC] { private[this] val ReusableCBFInstance: GenericCanBuildFrom[Nothing] = new GenericCanBuildFrom[Nothing] { override def apply() = newBuilder[Nothing] diff --git a/src/library/scala/collection/generic/IndexedSeqFactory.scala b/src/library/scala/collection/generic/IndexedSeqFactory.scala index e5162c640b..200d033c2d 100644 --- a/src/library/scala/collection/generic/IndexedSeqFactory.scala +++ b/src/library/scala/collection/generic/IndexedSeqFactory.scala @@ -13,7 +13,7 @@ import language.higherKinds /** A template for companion objects of IndexedSeq and subclasses thereof. * - * @since 2.8 + * @since 2.10 */ abstract class IndexedSeqFactory[CC[X] <: IndexedSeq[X] with GenericTraversableTemplate[X, CC]] extends SeqFactory[CC] { override def ReusableCBF: GenericCanBuildFrom[Nothing] = diff --git a/src/library/scala/collection/immutable/Stream.scala b/src/library/scala/collection/immutable/Stream.scala index e520ddc27c..3f7d27981b 100644 --- a/src/library/scala/collection/immutable/Stream.scala +++ b/src/library/scala/collection/immutable/Stream.scala @@ -969,7 +969,6 @@ self => override def view = new StreamView[A, Stream[A]] { protected lazy val underlying = self.repr - override def isEmpty = self.isEmpty override def iterator = self.iterator override def length = self.length override def apply(idx: Int) = self.apply(idx) diff --git a/src/library/scala/collection/mutable/IndexedSeqLike.scala b/src/library/scala/collection/mutable/IndexedSeqLike.scala index c5d0f58b94..7b582eb5cb 100644 --- a/src/library/scala/collection/mutable/IndexedSeqLike.scala +++ b/src/library/scala/collection/mutable/IndexedSeqLike.scala @@ -50,7 +50,6 @@ trait IndexedSeqLike[A, +Repr] extends Any with scala.collection.IndexedSeqLike[ */ override def view = new IndexedSeqView[A, Repr] { protected lazy val underlying = self.repr - override def isEmpty = self.isEmpty override def iterator = self.iterator override def length = self.length override def apply(idx: Int) = self.apply(idx) diff --git a/src/library/scala/collection/mutable/ListBuffer.scala b/src/library/scala/collection/mutable/ListBuffer.scala index bc38768e29..b7b487964c 100644 --- a/src/library/scala/collection/mutable/ListBuffer.scala +++ b/src/library/scala/collection/mutable/ListBuffer.scala @@ -135,29 +135,27 @@ final class ListBuffer[A] * @throws Predef.IndexOutOfBoundsException if `n` is out of bounds. */ def update(n: Int, x: A) { - try { - if (exported) copy() - if (n == 0) { - val newElem = new :: (x, start.tail); - if ((last0 eq null) || (last0 eq start)) { - last0 = newElem - } - start = newElem - } else { - var cursor = start - var i = 1 - while (i < n) { - cursor = cursor.tail - i += 1 - } - val newElem = new :: (x, cursor.tail.tail) - if (last0 eq cursor.tail) { - last0 = newElem - } - cursor.asInstanceOf[::[A]].tl = newElem + // We check the bounds early, so that we don't trigger copying. + if (n < 0 || n >= len) throw new IndexOutOfBoundsException(n.toString) + if (exported) copy() + if (n == 0) { + val newElem = new :: (x, start.tail); + if (last0 eq start) { + last0 = newElem + } + start = newElem + } else { + var cursor = start + var i = 1 + while (i < n) { + cursor = cursor.tail + i += 1 + } + val newElem = new :: (x, cursor.tail.tail) + if (last0 eq cursor.tail) { + last0 = newElem } - } catch { - case ex: Exception => throw new IndexOutOfBoundsException(n.toString()) + cursor.asInstanceOf[::[A]].tl = newElem } } @@ -219,34 +217,31 @@ final class ListBuffer[A] * @throws Predef.IndexOutOfBoundsException if `n` is out of bounds. */ def insertAll(n: Int, seq: Traversable[A]) { - try { - if (exported) copy() - var elems = seq.toList.reverse - len += elems.length - if (n == 0) { - while (!elems.isEmpty) { - val newElem = new :: (elems.head, start) - if (isEmpty) last0 = newElem - start = newElem - elems = elems.tail - } - } else { - var cursor = start - var i = 1 - while (i < n) { - cursor = cursor.tail - i += 1 - } - while (!elems.isEmpty) { - val newElem = new :: (elems.head, cursor.tail) - if (cursor.tail.isEmpty) last0 = newElem - cursor.asInstanceOf[::[A]].tl = newElem - elems = elems.tail - } + // We check the bounds early, so that we don't trigger copying. + if (n < 0 || n > len) throw new IndexOutOfBoundsException(n.toString) + if (exported) copy() + var elems = seq.toList.reverse + len += elems.length + if (n == 0) { + while (!elems.isEmpty) { + val newElem = new :: (elems.head, start) + if (start.isEmpty) last0 = newElem + start = newElem + elems = elems.tail + } + } else { + var cursor = start + var i = 1 + while (i < n) { + cursor = cursor.tail + i += 1 + } + while (!elems.isEmpty) { + val newElem = new :: (elems.head, cursor.tail) + if (cursor.tail.isEmpty) last0 = newElem + cursor.asInstanceOf[::[A]].tl = newElem + elems = elems.tail } - } catch { - case ex: Exception => - throw new IndexOutOfBoundsException(n.toString()) } } @@ -265,7 +260,12 @@ final class ListBuffer[A] * @param n the index which refers to the first element to remove. * @param count the number of elements to remove. */ + @annotation.migration("Invalid input values will be rejected in future releases.", "2.11") override def remove(n: Int, count: Int) { + if (n >= len) + return + if (count < 0) + throw new IllegalArgumentException(s"removing negative number ($count) of elements") if (exported) copy() val n1 = n max 0 val count1 = count min (len - n1) diff --git a/src/library/scala/collection/mutable/MultiMap.scala b/src/library/scala/collection/mutable/MultiMap.scala index 31c8a50a84..4635bfbe64 100644 --- a/src/library/scala/collection/mutable/MultiMap.scala +++ b/src/library/scala/collection/mutable/MultiMap.scala @@ -15,8 +15,36 @@ package mutable /** A trait for mutable maps with multiple values assigned to a key. * * This class is typically used as a mixin. It turns maps which map `A` - * to `Set[B]` objects into multi maps which map `A` to - * `B` objects. + * to `Set[B]` objects into multimaps that map `A` to `B` objects. + * + * @example {{{ + * // first import all necessary types from package `collection.mutable` + * import collection.mutable.{ HashMap, MultiMap, Set } + * + * // to create a `MultiMap` the easiest way is to mixin it into a normal + * // `Map` instance + * val mm = new HashMap[Int, Set[String]] with MultiMap[Int, String] + * + * // to add key-value pairs to a multimap it is important to use + * // the method `addBinding` because standard methods like `+` will + * // overwrite the complete key-value pair instead of adding the + * // value to the existing key + * mm.addBinding(1, "a") + * mm.addBinding(2, "b") + * mm.addBinding(1, "c") + * + * // mm now contains `Map(2 -> Set(b), 1 -> Set(c, a))` + * + * // to check if the multimap contains a value there is method + * // `entryExists`, which allows to traverse the including set + * mm.entryExists(1, _ == "a") == true + * mm.entryExists(1, _ == "b") == false + * mm.entryExists(2, _ == "b") == true + * + * // to remove a previous added value there is the method `removeBinding` + * mm.removeBinding(1, "a") + * mm.entryExists(1, _ == "a") == false + * }}} * * @define coll multimap * @define Coll `MultiMap` @@ -57,7 +85,8 @@ trait MultiMap[A, B] extends Map[A, Set[B]] { this } - /** Removes the binding of `value` to `key` if it exists. + /** Removes the binding of `value` to `key` if it exists, otherwise this + * operation doesn't have any effect. * * If this was the last value assigned to the specified key, the * set assigned to that key will be removed as well. diff --git a/src/library/scala/collection/parallel/ParIterableLike.scala b/src/library/scala/collection/parallel/ParIterableLike.scala index be9c934402..d77e5a6744 100644 --- a/src/library/scala/collection/parallel/ParIterableLike.scala +++ b/src/library/scala/collection/parallel/ParIterableLike.scala @@ -849,7 +849,6 @@ self: ParIterableLike[T, Repr, Sequential] => override def seq = self.seq.view def splitter = self.splitter def size = splitter.remaining - override def isEmpty = size == 0 } override def toArray[U >: T: ClassTag]: Array[U] = { diff --git a/src/library/scala/collection/parallel/ParSeqLike.scala b/src/library/scala/collection/parallel/ParSeqLike.scala index 4f1c3fa7a2..201b624c72 100644 --- a/src/library/scala/collection/parallel/ParSeqLike.scala +++ b/src/library/scala/collection/parallel/ParSeqLike.scala @@ -44,7 +44,7 @@ trait ParSeqLike[+T, +Repr <: ParSeq[T], +Sequential <: Seq[T] with SeqLike[T, S extends scala.collection.GenSeqLike[T, Repr] with ParIterableLike[T, Repr, Sequential] { self => - + type SuperParIterator = IterableSplitter[T] /** A more refined version of the iterator found in the `ParallelIterable` trait, @@ -330,7 +330,6 @@ self => def apply(idx: Int) = self(idx) override def seq = self.seq.view def splitter = self.splitter - override def isEmpty = size == 0 } /* tasks */ diff --git a/src/library/scala/concurrent/Future.scala b/src/library/scala/concurrent/Future.scala index 320a4f22b8..4b9e74708d 100644 --- a/src/library/scala/concurrent/Future.scala +++ b/src/library/scala/concurrent/Future.scala @@ -522,29 +522,6 @@ trait Future[+T] extends Awaitable[T] { p.future } - /** Creates a new future which holds the result of either this future or `that` future, depending on - * which future was completed first. - * - * $nonDeterministic - * - * Example: - * {{{ - * val f = future { sys.error("failed") } - * val g = future { 5 } - * val h = f either g - * await(h, 0) // evaluates to either 5 or throws a runtime exception - * }}} - */ - def either[U >: T](that: Future[U]): Future[U] = { - val p = Promise[U]() - val completePromise: PartialFunction[Try[U], _] = { case result => p tryComplete result } - - this onComplete completePromise - that onComplete completePromise - - p.future - } - } diff --git a/src/library/scala/concurrent/package.scala b/src/library/scala/concurrent/package.scala index f7c732b851..3e849f1722 100644 --- a/src/library/scala/concurrent/package.scala +++ b/src/library/scala/concurrent/package.scala @@ -29,13 +29,12 @@ package object concurrent { */ def future[T](body: =>T)(implicit execctx: ExecutionContext): Future[T] = Future[T](body) - /** Creates a promise object which can be completed with a value. + /** Creates a promise object which can be completed with a value or an exception. * * @tparam T the type of the value in the promise - * @param execctx the execution context on which the promise is created on * @return the newly created `Promise` object */ - def promise[T]()(implicit execctx: ExecutionContext): Promise[T] = Promise[T]() + def promise[T](): Promise[T] = Promise[T]() /** Used to designate a piece of code which potentially blocks, allowing the current [[BlockContext]] to adjust * the runtime's behavior. |