summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/immutable/SortedMap.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2009-05-08 16:33:15 +0000
committerMartin Odersky <odersky@gmail.com>2009-05-08 16:33:15 +0000
commit14a631a5fec42d04d0723355a0b93e482b5e4662 (patch)
treef639c2a22e89e193b9abea391993ecfd4d5326ee /src/library/scala/collection/immutable/SortedMap.scala
parent2379eb4ebbd28c8892b50a1d9fa8a687099eea4d (diff)
downloadscala-14a631a5fec42d04d0723355a0b93e482b5e4662.tar.gz
scala-14a631a5fec42d04d0723355a0b93e482b5e4662.tar.bz2
scala-14a631a5fec42d04d0723355a0b93e482b5e4662.zip
massive new collections checkin.
Diffstat (limited to 'src/library/scala/collection/immutable/SortedMap.scala')
-rw-r--r--src/library/scala/collection/immutable/SortedMap.scala94
1 files changed, 48 insertions, 46 deletions
diff --git a/src/library/scala/collection/immutable/SortedMap.scala b/src/library/scala/collection/immutable/SortedMap.scala
index c18d08e3a3..85b01561a7 100644
--- a/src/library/scala/collection/immutable/SortedMap.scala
+++ b/src/library/scala/collection/immutable/SortedMap.scala
@@ -8,53 +8,55 @@
// $Id$
-package scala.collection.immutable
-
-trait SortedMap[A,+B] extends Map[A,B] with collection.SortedMap[A,B] {
-
- override def rangeImpl(from: Option[A], until: Option[A]): SortedMap[A,B]
-
- override def from(from: A) = rangeImpl(Some(from), None)
-
- override def until(until: A) = rangeImpl(None, Some(until))
-
- override def range(from: A, until: A) = rangeImpl(Some(from),Some(until))
-
- override def empty[C]: SortedMap[A, C]
-
- override def update [B1 >: B] (key: A, value: B1): SortedMap[A, B1]
-
- override def + [B1 >: B] (kv: Pair[A, B1]): SortedMap[A, B1] = update(kv._1, kv._2)
- override def + [B1 >: B] (kv1: Pair[A, B1], kv2: Pair[A, B1], kvs: Pair[A, B1]*): SortedMap[A, B1] =
- this + kv1 + kv2 ++ kvs
-
- override def ++ [B1 >: B] (kvs: Iterable[Pair[A, B1]]): SortedMap[A, B1] =
- ((this: SortedMap[A, B1]) /: kvs) ((m, kv) => m + kv)
-
- override def ++ [B1 >: B] (kvs: Iterator[Pair[A, B1]]): SortedMap[A, B1] =
- ((this: SortedMap[A, B1]) /: kvs) ((m, kv) => m + kv)
-
- override def - (key: A): SortedMap[A, B]
-
- override def - (key1: A, key2: A, keys: A*): SortedMap[A, B] =
- this - key1 - key2 -- keys
-
- override def -- (keys: Iterable[A]): SortedMap[A, B] = this -- keys.elements
-
- override def -- (keys: Iterator[A]): SortedMap[A, B] =
- (this /: keys) ((m, key) => m - key)
+/** A map whose keys are sorted.
+ *
+ * @author Sean McDirmid
+ * @author Martin Odersky
+ * @version 2.8
+ */
+package scala.collection.immutable
- override def transform[C](f: (A, B) => C): SortedMap[A, C] = {
- var res = empty[C]
- foreach { case (key, value) => res = res.update(key, f(key, value)) }
- res
- }
- override def filter(p: Pair[A, B] => Boolean): SortedMap[A, B] = {
- var res = this
- foreach {
- case kv @ (key, _) => if (!p(kv)) { res = res - key }
- }
- res
+import generic._
+import annotation.unchecked.uncheckedVariance
+
+trait SortedMap[A, +B] extends Map[A, B]
+ with collection.SortedMap[A, B]
+ with ImmutableMapTemplate[A, B, SortedMap[A, B]]
+ with SortedMapTemplate[A, B, SortedMap[A, B]] {
+
+ /** Needs to be overridden in subclasses. */
+ override def empty: SortedMap[A, B] = throw new UnsupportedOperationException("SortedMap.empty")
+
+ /** Needs to be overridden in subclasses. */
+ override protected[this] def newBuilder : Builder[(A, B), SortedMap[A, B], Any] =
+ throw new UnsupportedOperationException("SortedMap.newBuilder")
+
+ /** Add a key/value pair to this map.
+ * @param key the key
+ * @param value the value
+ * @return A new map with the new binding added to this map
+ */
+ def add [B1 >: B](key: A, value: B1): SortedMap[A, B1]
+
+ /** Add a key/value pair to this map.
+ * @param kv the key/value pair
+ * @return A new map with the new binding added to this map
+ */
+ override def + [B1 >: B] (kv: (A, B1)): SortedMap[A, B1] = add(kv._1, kv._2)
+
+ /** Adds two or more elements to this collection and returns
+ * either the collection itself (if it is mutable), or a new collection
+ * with the added elements.
+ *
+ * @param elem1 the first element to add.
+ * @param elem2 the second element to add.
+ * @param elems the remaining elements to add.
+ */
+ override def + [B1 >: B] (elem1: (A, B1), elem2: (A, B1), elems: (A, B1) *): SortedMap[A, B1] = {
+ var m = this + elem1 + elem2;
+ for (e <- elems) m = m + e
+ m
}
}
+