summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2008-02-22 17:42:43 +0000
committermichelou <michelou@epfl.ch>2008-02-22 17:42:43 +0000
commitc11c657d05dd1f01436674fcdb7997d0349f6e4b (patch)
treeef09ed70277e8cc7405637c8d4afc60756f799ab
parenta8f9f01d5e2e24c0280f4010a1448e7f758064d2 (diff)
downloadscala-c11c657d05dd1f01436674fcdb7997d0349f6e4b.tar.gz
scala-c11c657d05dd1f01436674fcdb7997d0349f6e4b.tar.bz2
scala-c11c657d05dd1f01436674fcdb7997d0349f6e4b.zip
fixed #529
-rw-r--r--src/library/scala/collection/mutable/Map.scala19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/library/scala/collection/mutable/Map.scala b/src/library/scala/collection/mutable/Map.scala
index c502dd478c..e9b3a24d11 100644
--- a/src/library/scala/collection/mutable/Map.scala
+++ b/src/library/scala/collection/mutable/Map.scala
@@ -136,7 +136,7 @@ trait Map[A, B] extends AnyRef
/** Remove <code>key</code> from this map and return the element
* that the key was previously mapped to (if any).
*/
- def removeKey(key : A) : Option[B] = {
+ def removeKey(key: A): Option[B] = {
val ret = get(key)
this -= key
ret
@@ -145,13 +145,12 @@ trait Map[A, B] extends AnyRef
/** Map <code>key</code> to <code>elem</code> in this map and return the element
* that the key was previously mapped to (if any).
*/
- def put(key : A, elem : B) : Option[B] = {
+ def put(key: A, elem: B): Option[B] = {
val ret = get(key)
this(key) = elem
ret
}
-
/** Remove two or more keys from this map
* @param key1 the first key to be removed
* @param key2 the second key to be removed
@@ -204,8 +203,10 @@ trait Map[A, B] extends AnyRef
* @param p The test predicate
* @deprecated cannot be type inferred because if retain in Iterable.
*/
- def retain(p: (A, B) => Boolean): Unit = toList foreach {
- case (key, value) => if (!p(key, value)) -=(key)
+ def retain(p: (A, B) => Boolean) {
+ toList foreach {
+ case (key, value) => if (!p(key, value)) -=(key)
+ }
}
/** Send a message to this scriptable object.
@@ -227,6 +228,14 @@ trait Map[A, B] extends AnyRef
*/
override def clone(): Map[A, B] = super.clone().asInstanceOf[Map[A, B]]
+ /** Return a read-only projection of this map */
+ def readOnly: scala.collection.Map[A, B] = new scala.collection.Map[A, B] {
+ override def toString = "ro-" + Map.this.toString
+ override def size = Map.this.size
+ override def elements = Map.this.elements
+ override def get(key: A) = Map.this.get(key)
+ }
+
/** This method defines syntactic sugar for adding or modifying
* mappings. It is typically used in the following way:
* <pre>