summaryrefslogtreecommitdiff
path: root/sources/scala/collection/Map.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2005-12-08 15:15:56 +0000
committerMartin Odersky <odersky@gmail.com>2005-12-08 15:15:56 +0000
commit2d91f011f2ba54bb3ac733f3dcf4a518ea56d50e (patch)
tree956f4cf7f0745cf6916ad67354fcb7c42659969d /sources/scala/collection/Map.scala
parente0d7aeaa9d32afce117d366b179e7a8205586f2e (diff)
downloadscala-2d91f011f2ba54bb3ac733f3dcf4a518ea56d50e.tar.gz
scala-2d91f011f2ba54bb3ac733f3dcf4a518ea56d50e.tar.bz2
scala-2d91f011f2ba54bb3ac733f3dcf4a518ea56d50e.zip
*** empty log message ***
Diffstat (limited to 'sources/scala/collection/Map.scala')
-rw-r--r--sources/scala/collection/Map.scala13
1 files changed, 10 insertions, 3 deletions
diff --git a/sources/scala/collection/Map.scala b/sources/scala/collection/Map.scala
index 65ee3a6c3b..91ec361083 100644
--- a/sources/scala/collection/Map.scala
+++ b/sources/scala/collection/Map.scala
@@ -53,7 +53,7 @@ trait Map[A, +B] extends AnyRef with PartialFunction[A, B] with Iterable[Pair[A,
* @return the value associated with the given key.
*/
def apply(key: A): B = get(key) match {
- case None => error("key not found")
+ case None => default
case Some(value) => value
}
@@ -136,7 +136,7 @@ trait Map[A, +B] extends AnyRef with PartialFunction[A, B] with Iterable[Pair[A,
*
* @return true, iff both maps contain exactly the same mappings.
*/
- override def equals(that: Any): Boolean =
+ override def equals(that: Any): Boolean = (
that.isInstanceOf[Map[A, B]] &&
{ val other = that.asInstanceOf[Map[A, B]];
this.size == other.size &&
@@ -145,7 +145,8 @@ trait Map[A, +B] extends AnyRef with PartialFunction[A, B] with Iterable[Pair[A,
case None => false;
case Some(otherval) => value == otherval;
}
- }};
+ }}
+ );
/** Returns the mappings of this map as a list.
*
@@ -170,5 +171,11 @@ trait Map[A, +B] extends AnyRef with PartialFunction[A, B] with Iterable[Pair[A,
res;
} + "}";
+ /** The default value for the map, returned when a key is not found
+ * The method implemented here yields an error,
+ * but it might be overridden in subclasses.
+ */
+ def default: B =
+ error("key not found")
}