summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Zenger <mzenger@gmail.com>2003-07-18 23:40:35 +0000
committerMatthias Zenger <mzenger@gmail.com>2003-07-18 23:40:35 +0000
commitbb9cfcedf14ed2589f4f6f807b89effbbb59c84e (patch)
tree466269599d79b071147161aa32071ab5ba9dcb7e
parentc1bcad868c80dd4fabdb03af70539cb21ecb187f (diff)
downloadscala-bb9cfcedf14ed2589f4f6f807b89effbbb59c84e.tar.gz
scala-bb9cfcedf14ed2589f4f6f807b89effbbb59c84e.tar.bz2
scala-bb9cfcedf14ed2589f4f6f807b89effbbb59c84e.zip
More refactoring.
-rw-r--r--sources/scala/collection/Map.scala4
-rw-r--r--sources/scala/collection/mutable/HashMap.scala2
-rw-r--r--sources/scala/collection/mutable/HashSet.scala4
-rw-r--r--sources/scala/collection/mutable/HashTable.scala2
-rw-r--r--sources/scala/collection/mutable/Map.scala25
-rw-r--r--sources/scala/collection/mutable/MultiMap.scala14
-rw-r--r--sources/scala/collection/mutable/MutableList.scala2
-rw-r--r--sources/scala/collection/mutable/ObservableMap.scala6
-rw-r--r--sources/scala/collection/mutable/ObservableSet.scala16
-rw-r--r--sources/scala/collection/mutable/Publisher.scala6
-rw-r--r--sources/scala/collection/mutable/Set.scala20
-rw-r--r--sources/scala/collection/mutable/SynchronizedMap.scala24
-rw-r--r--sources/scala/collection/mutable/SynchronizedSet.scala24
13 files changed, 79 insertions, 70 deletions
diff --git a/sources/scala/collection/Map.scala b/sources/scala/collection/Map.scala
index f0b4788161..f478146190 100644
--- a/sources/scala/collection/Map.scala
+++ b/sources/scala/collection/Map.scala
@@ -46,13 +46,13 @@ trait Map[A, +B] with PartialFunction[A, B]
def isDefinedAt(key: A) = contains(key);
def keys: Iterator[A] = new Iterator[A] {
- val iter = elements;
+ val iter = Map.this.elements;
def hasNext = iter.hasNext;
def next = iter.next._1;
}
def values: Iterator[B] = new Iterator[B] {
- val iter = elements;
+ val iter = Map.this.elements;
def hasNext = iter.hasNext;
def next = iter.next._2;
}
diff --git a/sources/scala/collection/mutable/HashMap.scala b/sources/scala/collection/mutable/HashMap.scala
index e25d94be2f..1394c21f48 100644
--- a/sources/scala/collection/mutable/HashMap.scala
+++ b/sources/scala/collection/mutable/HashMap.scala
@@ -18,6 +18,8 @@ class HashMap[A, B] extends scala.collection.mutable.Map[A, B]
with HashTable[A]
with DefaultMapModel[A, B] {
+ def -=(key: A): Unit = removeEntry(key);
+
protected def entryKey(e: Entry) = e.key;
override def clear = {
diff --git a/sources/scala/collection/mutable/HashSet.scala b/sources/scala/collection/mutable/HashSet.scala
index 8b68a9aa9d..1c27ea6c18 100644
--- a/sources/scala/collection/mutable/HashSet.scala
+++ b/sources/scala/collection/mutable/HashSet.scala
@@ -22,11 +22,13 @@ class HashSet[A] extends scala.collection.mutable.Set[A] with HashTable[A] {
case Some(_) => true
}
- def add(elem: A): Unit = findEntry(elem) match {
+ def +=(elem: A): Unit = findEntry(elem) match {
case None => addEntry(elem);
case Some(_) =>
}
+ def -=(elem: A): Unit = removeEntry(elem);
+
def elements = entries;
override def clear = {
diff --git a/sources/scala/collection/mutable/HashTable.scala b/sources/scala/collection/mutable/HashTable.scala
index a9f306161d..34d863ceea 100644
--- a/sources/scala/collection/mutable/HashTable.scala
+++ b/sources/scala/collection/mutable/HashTable.scala
@@ -69,7 +69,7 @@ abstract class HashTable[A] {
resize(2 * table.length);
}
- def remove(key: A): Unit = {
+ protected def removeEntry(key: A): Unit = {
val old = findEntry(key);
old match {
case None =>
diff --git a/sources/scala/collection/mutable/Map.scala b/sources/scala/collection/mutable/Map.scala
index c9ae318b3b..9d74ff675e 100644
--- a/sources/scala/collection/mutable/Map.scala
+++ b/sources/scala/collection/mutable/Map.scala
@@ -22,30 +22,31 @@ trait Map[A, B] with scala.collection.Map[A, B] {
def update(key: A, value: B): Unit;
- def remove(key: A): Unit;
+ def -=(key: A): Unit;
- def clear: Unit = {
- val iter = keys;
- while (iter.hasNext) {
- remove(iter.next);
- }
- }
+ def +=(key: A): MapTo = new MapTo(key);
- def put(mappings: Pair[A, B]*): Unit = {
+ def incl(mappings: Pair[A, B]*): Unit = {
val ys = mappings as List[Pair[A, B]];
ys foreach { case Pair(key, value) => update(key, value); };
}
- def putMap(map: Iterable[Pair[A, B]]): Unit = map.elements foreach {
+ def incl(map: Iterable[Pair[A, B]]): Unit = map.elements foreach {
case Pair(key, value) => update(key, value);
}
+ def excl(keys: A*): Unit = excl(keys);
+
+ def excl(keys: Iterable[A]): Unit = keys.elements foreach -=;
+
+ def clear: Unit = keys foreach -=;
+
def map(f: (A, B) => B): Unit = elements foreach {
case Pair(key, value) => update(key, f(key, value));
}
def filter(p: (A, B) => Boolean): Unit = toList foreach {
- case Pair(key, value) => if (p(key, value)) remove(key);
+ case Pair(key, value) => if (p(key, value)) -=(key);
}
override def toString() =
@@ -62,4 +63,8 @@ trait Map[A, B] with scala.collection.Map[A, B] {
} + "}";
def mappingToString(p: Pair[A, B]) = p._1.toString() + " -> " + p._2;
+
+ class MapTo(key: A) {
+ def ->(value: B): Unit = update(key, value);
+ }
}
diff --git a/sources/scala/collection/mutable/MultiMap.scala b/sources/scala/collection/mutable/MultiMap.scala
index 130fd64442..7f16fd14ee 100644
--- a/sources/scala/collection/mutable/MultiMap.scala
+++ b/sources/scala/collection/mutable/MultiMap.scala
@@ -21,20 +21,18 @@ trait MultiMap[A, B] extends scala.collection.mutable.Map[A, scala.collection.mu
def add(key: A, value: B): Unit = get(key) match {
case None => val set = makeSet;
- set.add(value);
- update(key, set);
- case Some(set) => set.add(value);
+ set += value;
+ this(key) = set;
+ case Some(set) => set += value;
}
- override def remove(key: A) = super.remove(key);
-
- override def remove(key: A, value: B) = get(key) match {
+ def remove(key: A, value: B) = get(key) match {
case None =>
- case Some(set) => set.remove(value);
+ case Some(set) => set -= value;
}
def exists(key: A, p: B => Boolean): Boolean = get(key) match {
case None => false
- case Some(set) => set.exists(p);
+ case Some(set) => set exists p;
}
}
diff --git a/sources/scala/collection/mutable/MutableList.scala b/sources/scala/collection/mutable/MutableList.scala
index 4c4333a1cb..cd55e0f7ee 100644
--- a/sources/scala/collection/mutable/MutableList.scala
+++ b/sources/scala/collection/mutable/MutableList.scala
@@ -25,8 +25,6 @@ class MutableList[A] with Seq[A] with PartialFunction[Int, A] {
def length: Int = len;
- def isDefinedAt(n: Int) = (n >= 0) && (n < len);
-
def apply(n: Int): A = get(n) match {
case None => error("element not found")
case Some(value) => value
diff --git a/sources/scala/collection/mutable/ObservableMap.scala b/sources/scala/collection/mutable/ObservableMap.scala
index d28284a9b9..0739a53062 100644
--- a/sources/scala/collection/mutable/ObservableMap.scala
+++ b/sources/scala/collection/mutable/ObservableMap.scala
@@ -25,7 +25,7 @@ abstract class ObservableMap[A, B, This <: ObservableMap[A, B, This]]: This
override def update(key: A, value: B): Unit = get(key) match {
case None => super.update(key, value);
publish(new Inclusion(Pair(key, value)) with Undo {
- def undo = remove(key);
+ def undo = -=(key);
});
case Some(old) => super.update(key, value);
publish(new Modification(Pair(key, old), Pair(key, value)) with Undo {
@@ -33,9 +33,9 @@ abstract class ObservableMap[A, B, This <: ObservableMap[A, B, This]]: This
});
}
- override def remove(key: A): Unit = get(key) match {
+ override def -=(key: A): Unit = get(key) match {
case None =>
- case Some(old) => super.remove(key);
+ case Some(old) => super.-=(key);
publish(new Removal(Pair(key, old)) with Undo {
def undo = update(key, old);
});
diff --git a/sources/scala/collection/mutable/ObservableSet.scala b/sources/scala/collection/mutable/ObservableSet.scala
index 4741087962..4d49ce0360 100644
--- a/sources/scala/collection/mutable/ObservableSet.scala
+++ b/sources/scala/collection/mutable/ObservableSet.scala
@@ -21,18 +21,14 @@ abstract class ObservableSet[A, This <: ObservableSet[A, This]]: This
extends scala.collection.mutable.Set[A]
with Publisher[ObservableUpdate[A] with Undo, This] {
- override def add(elem: A): Unit = if (!contains(elem)) {
- super.add(elem);
- publish(new Inclusion(elem) with Undo {
- def undo = remove(elem);
- });
+ override def +=(elem: A): Unit = if (!contains(elem)) {
+ super.+=(elem);
+ publish(new Inclusion(elem) with Undo { def undo = -=(elem); });
}
- override def remove(elem: A): Unit = if (contains(elem)) {
- super.remove(elem);
- publish(new Removal(elem) with Undo {
- def undo = add(elem);
- });
+ override def -=(elem: A): Unit = if (contains(elem)) {
+ super.-=(elem);
+ publish(new Removal(elem) with Undo { def undo = +=(elem); });
}
override def clear: Unit = {
diff --git a/sources/scala/collection/mutable/Publisher.scala b/sources/scala/collection/mutable/Publisher.scala
index 6e2e371e32..d42082b145 100644
--- a/sources/scala/collection/mutable/Publisher.scala
+++ b/sources/scala/collection/mutable/Publisher.scala
@@ -31,11 +31,11 @@ class Publisher[A, This <: Publisher[A, This]]: This {
def subscribe(sub: Subscriber[A, This], filter: A => Boolean): Unit =
filters.add(sub, filter);
- def suspendSubscription(sub: Subscriber[A, This]): Unit = suspended.add(sub);
+ def suspendSubscription(sub: Subscriber[A, This]): Unit = suspended += sub;
- def activateSubscription(sub: Subscriber[A, This]): Unit = suspended.remove(sub);
+ def activateSubscription(sub: Subscriber[A, This]): Unit = suspended -= sub;
- def removeSubscription(sub: Subscriber[A, This]): Unit = filters.remove(sub);
+ def removeSubscription(sub: Subscriber[A, This]): Unit = filters -= sub;
def removeSubscriptions: Unit = filters.clear;
diff --git a/sources/scala/collection/mutable/Set.scala b/sources/scala/collection/mutable/Set.scala
index 5c0e1bb6da..158963db40 100644
--- a/sources/scala/collection/mutable/Set.scala
+++ b/sources/scala/collection/mutable/Set.scala
@@ -20,28 +20,28 @@ package scala.collection.mutable;
*/
trait Set[A] with scala.collection.Set[A] {
- def add(elem: A): Unit;
+ def +=(elem: A): Unit;
- def addAll(elems: A*): Unit = {
+ def incl(elems: A*): Unit = {
val ys = elems as List[A];
- ys foreach { y => add(y); };
+ ys foreach { y => +=(y); };
}
- def addSet(that: Iterable[A]): Unit =
- that.elements.foreach(elem => add(elem));
+ def incl(that: Iterable[A]): Unit =
+ that.elements.foreach(elem => +=(elem));
- def remove(elem: A): Unit;
+ def -=(elem: A): Unit;
- def removeAll(elems: A*): Unit = removeSet(elems);
+ def excl(elems: A*): Unit = excl(elems);
- def removeSet(that: Iterable[A]): Unit =
- that.elements.foreach(elem => remove(elem));
+ def excl(that: Iterable[A]): Unit =
+ that.elements.foreach(elem => -=(elem));
def intersect(that: Set[A]): Unit = filter(that.contains);
def clear: Unit;
def filter(p: A => Boolean): Unit = toList foreach {
- elem => if (p(elem)) remove(elem);
+ elem => if (p(elem)) -=(elem);
}
}
diff --git a/sources/scala/collection/mutable/SynchronizedMap.scala b/sources/scala/collection/mutable/SynchronizedMap.scala
index 40a1e4e959..0837d95cb0 100644
--- a/sources/scala/collection/mutable/SynchronizedMap.scala
+++ b/sources/scala/collection/mutable/SynchronizedMap.scala
@@ -62,20 +62,28 @@ trait SynchronizedMap[A, B] extends scala.collection.mutable.Map[A, B] with Moni
super.update(key, value);
}
- override def remove(key: A): Unit = synchronized {
- super.remove(key);
+ override def -=(key: A): Unit = synchronized {
+ super.-=(key);
}
- override def clear: Unit = synchronized {
- super.clear;
+ override def incl(mappings: Pair[A, B]*): Unit = synchronized {
+ super.incl(mappings);
+ }
+
+ override def incl(map: Iterable[Pair[A, B]]): Unit = synchronized {
+ super.incl(map);
}
- override def put(mappings: Pair[A, B]*) = synchronized {
- super.putMap(mappings);
+ override def excl(keys: A*): Unit = synchronized {
+ super.excl(keys);
}
- override def putMap(map: Iterable[Pair[A, B]]): Unit = synchronized {
- super.putMap(map);
+ override def excl(keys: Iterable[A]): Unit = synchronized {
+ super.excl(keys);
+ }
+
+ override def clear: Unit = synchronized {
+ super.clear;
}
override def map(f: (A, B) => B): Unit = synchronized {
diff --git a/sources/scala/collection/mutable/SynchronizedSet.scala b/sources/scala/collection/mutable/SynchronizedSet.scala
index ce38dcc38d..37344a2020 100644
--- a/sources/scala/collection/mutable/SynchronizedSet.scala
+++ b/sources/scala/collection/mutable/SynchronizedSet.scala
@@ -30,28 +30,28 @@ trait SynchronizedSet[A] extends scala.collection.mutable.Set[A] with Monitor {
super.contains(elem);
}
- override def add(elem: A): Unit = synchronized {
- super.add(elem);
+ override def +=(elem: A): Unit = synchronized {
+ super.+=(elem);
}
- override def addAll(elems: A*): Unit = synchronized {
- super.addSet(elems);
+ override def incl(elems: A*): Unit = synchronized {
+ super.incl(elems);
}
- override def addSet(that: Iterable[A]) = synchronized {
- super.addSet(that);
+ override def incl(that: Iterable[A]) = synchronized {
+ super.incl(that);
}
- override def remove(elem: A): Unit = synchronized {
- super.remove(elem);
+ override def -=(elem: A): Unit = synchronized {
+ super.-=(elem);
}
- override def removeAll(elems: A*): Unit = synchronized {
- super.removeSet(elems);
+ override def excl(elems: A*): Unit = synchronized {
+ super.excl(elems);
}
- override def removeSet(that: Iterable[A]) = synchronized {
- super.removeSet(that);
+ override def excl(that: Iterable[A]) = synchronized {
+ super.excl(that);
}
override def intersect(that: Set[A]) = synchronized {