diff options
author | Martin Odersky <odersky@gmail.com> | 2011-04-27 10:26:39 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2011-04-27 10:26:39 +0000 |
commit | 6d653c3d07b31b160cf9444b06d9fe91fc32651a (patch) | |
tree | d12f9a700b69153ef916d886c0d36704098bc271 /src/library | |
parent | c79f8876aa04370fc99692f73825392ea48d02e2 (diff) | |
download | scala-6d653c3d07b31b160cf9444b06d9fe91fc32651a.tar.gz scala-6d653c3d07b31b160cf9444b06d9fe91fc32651a.tar.bz2 scala-6d653c3d07b31b160cf9444b06d9fe91fc32651a.zip |
More bridges in collections. Review by prokopec.
Diffstat (limited to 'src/library')
9 files changed, 34 insertions, 5 deletions
diff --git a/src/library/scala/collection/SeqViewLike.scala b/src/library/scala/collection/SeqViewLike.scala index 77dc15e695..37c66802ef 100644 --- a/src/library/scala/collection/SeqViewLike.scala +++ b/src/library/scala/collection/SeqViewLike.scala @@ -13,6 +13,7 @@ package scala.collection import generic._ import Seq.fill import TraversableView.NoBuilder +import annotation.bridge /** A template trait for non-strict views of sequences. * $seqViewInfo @@ -129,9 +130,13 @@ trait SeqViewLike[+A, override def diff[B >: A](that: GenSeq[B]): This = newForced(thisSeq diff that).asInstanceOf[This] + @bridge def diff[B >: A](that: Seq[B]): This = diff(that: GenSeq[B]) + override def intersect[B >: A](that: GenSeq[B]): This = newForced(thisSeq intersect that).asInstanceOf[This] + @bridge def intersect[B >: A](that: Seq[B]): This = intersect(that: GenSeq[B]) + override def sorted[B >: A](implicit ord: Ordering[B]): This = newForced(thisSeq sorted ord).asInstanceOf[This] diff --git a/src/library/scala/collection/immutable/ListMap.scala b/src/library/scala/collection/immutable/ListMap.scala index a0f20c6e96..edee4a9922 100644 --- a/src/library/scala/collection/immutable/ListMap.scala +++ b/src/library/scala/collection/immutable/ListMap.scala @@ -12,7 +12,7 @@ package scala.collection package immutable import generic._ -import annotation.tailrec +import annotation.{tailrec, bridge} /** $factoryInfo * @since 1 @@ -100,6 +100,9 @@ class ListMap[A, +B] extends Map[A, B] with MapLike[A, B, ListMap[A, B]] with Se override def ++[B1 >: B](xs: GenTraversableOnce[(A, B1)]): ListMap[A, B1] = ((repr: ListMap[A, B1]) /: xs.seq) (_ + _) + @bridge def ++[B1 >: B](xs: TraversableOnce[(A, B1)]): ListMap[A, B1] = + ++(xs: GenTraversableOnce[(A, B1)]) + /** This creates a new mapping without the given <code>key</code>. * If the map does not contain a mapping for the given key, the * method returns the same map. diff --git a/src/library/scala/collection/immutable/ListSet.scala b/src/library/scala/collection/immutable/ListSet.scala index 057b68d280..a298c629be 100644 --- a/src/library/scala/collection/immutable/ListSet.scala +++ b/src/library/scala/collection/immutable/ListSet.scala @@ -12,7 +12,7 @@ package scala.collection package immutable import generic._ -import annotation.tailrec +import annotation.{tailrec, bridge} import mutable.{ ListBuffer, Builder } /** $factoryInfo @@ -103,6 +103,8 @@ class ListSet[A] extends Set[A] if (xs.isEmpty) this else new ListSet.ListSetBuilder(this) ++= xs.seq result + @bridge def ++(xs: TraversableOnce[A]): ListSet[A] = ++(xs: GenTraversableOnce[A]): ListSet[A] + private[ListSet] def unchecked_+(e: A): ListSet[A] = new Node(e) private[ListSet] def unchecked_outer: ListSet[A] = throw new NoSuchElementException("Empty ListSet has no outer pointer") diff --git a/src/library/scala/collection/immutable/MapLike.scala b/src/library/scala/collection/immutable/MapLike.scala index d22adc03bc..fb2826b4df 100644 --- a/src/library/scala/collection/immutable/MapLike.scala +++ b/src/library/scala/collection/immutable/MapLike.scala @@ -11,6 +11,7 @@ package immutable import generic._ import parallel.immutable.ParMap +import annotation.bridge /** * A generic template for immutable maps from keys of type `A` @@ -85,6 +86,8 @@ trait MapLike[A, +B, +This <: MapLike[A, B, This] with Map[A, B]] override def ++[B1 >: B](xs: GenTraversableOnce[(A, B1)]): immutable.Map[A, B1] = ((repr: immutable.Map[A, B1]) /: xs.seq) (_ + _) + @bridge def ++[B1 >: B](xs: TraversableOnce[(A, B1)]): immutable.Map[A, B1] = ++(xs: GenTraversableOnce[(A, B1)]) + /** Filters this map by retaining only keys satisfying a predicate. * @param p the predicate used to test keys * @return an immutable map consisting only of those key value pairs of this map where the key satisfies diff --git a/src/library/scala/collection/immutable/SortedMap.scala b/src/library/scala/collection/immutable/SortedMap.scala index 64fa06bf2e..f7e05fef69 100644 --- a/src/library/scala/collection/immutable/SortedMap.scala +++ b/src/library/scala/collection/immutable/SortedMap.scala @@ -14,6 +14,7 @@ package immutable import generic._ import mutable.Builder import annotation.unchecked.uncheckedVariance +import annotation.bridge /** A map whose keys are sorted. * @@ -63,6 +64,8 @@ trait SortedMap[A, +B] extends Map[A, B] */ override def ++[B1 >: B](xs: GenTraversableOnce[(A, B1)]): SortedMap[A, B1] = ((repr: SortedMap[A, B1]) /: xs.seq) (_ + _) + + @bridge def ++[B1 >: B](xs: TraversableOnce[(A, B1)]): SortedMap[A, B1] = ++(xs: GenTraversableOnce[(A, B1)]) } /** $factoryInfo diff --git a/src/library/scala/collection/immutable/TreeMap.scala b/src/library/scala/collection/immutable/TreeMap.scala index 7552e1983c..a46583c541 100644 --- a/src/library/scala/collection/immutable/TreeMap.scala +++ b/src/library/scala/collection/immutable/TreeMap.scala @@ -13,6 +13,7 @@ package immutable import generic._ import mutable.Builder +import annotation.bridge /** $factoryInfo * @define Coll immutable.TreeMap @@ -110,9 +111,11 @@ class TreeMap[A, +B](override val size: Int, t: RedBlack[A]#Tree[B])(implicit va * * @param xs the traversable object. */ - override def ++[B1 >: B](xs: GenTraversableOnce[(A, B1)]): TreeMap[A, B1] = + override def ++[B1 >: B] (xs: GenTraversableOnce[(A, B1)]): TreeMap[A, B1] = ((repr: TreeMap[A, B1]) /: xs.seq) (_ + _) + @bridge def ++[B1 >: B] (xs: TraversableOnce[(A, B1)]): TreeMap[A, B1] = ++(xs: GenTraversableOnce[(A, B1)]) + /** A new TreeMap with the entry added is returned, * assuming that key is <em>not</em> in the TreeMap. * diff --git a/src/library/scala/collection/mutable/BufferLike.scala b/src/library/scala/collection/mutable/BufferLike.scala index c48dd5d621..9cab3bd656 100644 --- a/src/library/scala/collection/mutable/BufferLike.scala +++ b/src/library/scala/collection/mutable/BufferLike.scala @@ -312,4 +312,6 @@ trait BufferLike[A, +This <: BufferLike[A, This] with Buffer[A]] "Use --= instead if you intend to remove by side effect from an existing collection.\n" ) override def --(xs: GenTraversableOnce[A]): This = clone() --= xs.seq + + @bridge def --(xs: TraversableOnce[A]): This = --(xs: GenTraversableOnce[A]) } diff --git a/src/library/scala/collection/mutable/MapLike.scala b/src/library/scala/collection/mutable/MapLike.scala index e737bf5509..92c6e8c162 100644 --- a/src/library/scala/collection/mutable/MapLike.scala +++ b/src/library/scala/collection/mutable/MapLike.scala @@ -11,7 +11,7 @@ package scala.collection package mutable import generic._ -import annotation.migration +import annotation.{migration, bridge} import parallel.mutable.ParMap /** A template trait for mutable maps. @@ -128,6 +128,8 @@ trait MapLike[A, B, +This <: MapLike[A, B, This] with Map[A, B]] override def ++[B1 >: B](xs: GenTraversableOnce[(A, B1)]): Map[A, B1] = clone().asInstanceOf[Map[A, B1]] ++= xs.seq + @bridge def ++[B1 >: B](xs: TraversableOnce[(A, B1)]): Map[A, B1] = ++(xs: GenTraversableOnce[(A, B1)]) + /** Removes a key from this map, returning the value associated previously * with that key as an option. * @param key the key to be removed @@ -247,4 +249,6 @@ trait MapLike[A, B, +This <: MapLike[A, B, This] with Map[A, B]] "side effect to an existing map and return that map itself, use --=." ) override def --(xs: GenTraversableOnce[A]): This = clone() --= xs.seq + + @bridge def --(xs: TraversableOnce[A]): This = --(xs: GenTraversableOnce[A]) } diff --git a/src/library/scala/collection/mutable/SetLike.scala b/src/library/scala/collection/mutable/SetLike.scala index 855ba74f8c..a74f904aa3 100644 --- a/src/library/scala/collection/mutable/SetLike.scala +++ b/src/library/scala/collection/mutable/SetLike.scala @@ -13,7 +13,7 @@ package mutable import generic._ import script._ -import scala.annotation.migration +import annotation.{migration, bridge} import parallel.mutable.ParSet /** A template trait for mutable sets of type `mutable.Set[A]`. @@ -181,6 +181,8 @@ trait SetLike[A, +This <: SetLike[A, This] with Set[A]] ) override def ++(xs: GenTraversableOnce[A]): This = clone() ++= xs.seq + @bridge def ++(xs: TraversableOnce[A]): This = ++(xs: GenTraversableOnce[A]) + /** Creates a new set consisting of all the elements of this set except `elem`. * * @param elem the element to remove. @@ -221,6 +223,8 @@ trait SetLike[A, +This <: SetLike[A, This] with Set[A]] ) override def --(xs: GenTraversableOnce[A]): This = clone() --= xs.seq + @bridge def --(xs: TraversableOnce[A]): This = --(xs: GenTraversableOnce[A]) + /** Send a message to this scriptable object. * * @param cmd the message to send. |