diff options
author | Gilles Dubochet <gilles.dubochet@epfl.ch> | 2005-12-19 13:49:03 +0000 |
---|---|---|
committer | Gilles Dubochet <gilles.dubochet@epfl.ch> | 2005-12-19 13:49:03 +0000 |
commit | ac849228490d5a0e2d3f048d649297d5c59b6ade (patch) | |
tree | 6314f2c06f37e67dec5827c3f94e25cf844a085c /src/library/scala/collection/mutable/DefaultMapModel.scala | |
parent | d6c0efe5b4b89a0337f1cdcdabf8c607d81f4ae1 (diff) | |
download | scala-ac849228490d5a0e2d3f048d649297d5c59b6ade.tar.gz scala-ac849228490d5a0e2d3f048d649297d5c59b6ade.tar.bz2 scala-ac849228490d5a0e2d3f048d649297d5c59b6ade.zip |
Switching to the new build system and to the ne...
Switching to the new build system and to the new build system. This is a
MAJOR commit, so be careful when updating.
Diffstat (limited to 'src/library/scala/collection/mutable/DefaultMapModel.scala')
-rw-r--r-- | src/library/scala/collection/mutable/DefaultMapModel.scala | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/library/scala/collection/mutable/DefaultMapModel.scala b/src/library/scala/collection/mutable/DefaultMapModel.scala new file mode 100644 index 0000000000..6ae089bc3e --- /dev/null +++ b/src/library/scala/collection/mutable/DefaultMapModel.scala @@ -0,0 +1,52 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2004, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +** $Id$ +\* */ + +package scala.collection.mutable; + + +/** This trait is used internally. It implements the mutable <code>Map</code> + * trait in terms of three functions: <code>findEntry</code>, <code>addEntry</code>, + * and <code>entries</code>. + * + * @author Matthias Zenger + * @version 1.0, 08/07/2003 + */ +trait DefaultMapModel[A, B] extends AnyRef with scala.collection.mutable.Map[A, B] { + protected type Entry = DefaultEntry[A,B]; + + protected def findEntry(key: A): Option[Entry]; + + protected def addEntry(e: Entry): Unit; + + protected def entries: Iterator[Entry]; + + def get(key: A) = findEntry(key) match { + case None => None + case Some(e) => Some(e.value); + } + + def update(key: A, value: B) = findEntry(key) match { + case None => addEntry(new Entry(key, value)); + case Some(e) => e.value = value; + } + + def elements = new Iterator[Pair[A, B]] { + val iter = entries; + def hasNext = iter.hasNext; + def next = iter.next.toPair; + } +} + +[serializable] +protected class DefaultEntry[A,B](k: A, v: B) extends AnyRef { + def key = k; + var value = v; + def toPair = Pair(k, value); + override def toString() = k.toString() + " -> " + value; +} |