~ simplified, but rendered less efficient as toString appears to not use the defined iterator
--- a/src/main/scala/AddOrderedSet.scala Tue Jan 05 11:55:39 2010 -0500
+++ b/src/main/scala/AddOrderedSet.scala Tue Jan 05 12:02:26 2010 -0500
@@ -1,11 +1,20 @@
package w3c.sw.util
import scala.collection.immutable._
+// class AddOrderedSet[A](list:List[A]) extends Set[A] {
+
+// def contains(elem: A): Boolean = list.contains(elem)
+// def iterator: Iterator[A] = list.reverse.iterator
+// def + (elem: A) : AddOrderedSet[A] = if (this contains elem) this else new AddOrderedSet(elem :: list)
+// def - (elem: A) : AddOrderedSet[A] = new AddOrderedSet(list filterNot (_ == elem))
+
+// }
+
class AddOrderedSet[A](list:List[A]) extends Set[A] {
def contains(elem: A): Boolean = list.contains(elem)
- def iterator: Iterator[A] = list.reverse.iterator
- def + (elem: A) : AddOrderedSet[A] = if (this contains elem) this else new AddOrderedSet(elem :: list)
+ def iterator: Iterator[A] = list.iterator
+ def + (elem: A) : AddOrderedSet[A] = if (this contains elem) this else new AddOrderedSet(list ++ List(elem))
def - (elem: A) : AddOrderedSet[A] = new AddOrderedSet(list filterNot (_ == elem))
}