diff options
author | Matthias Zenger <mzenger@gmail.com> | 2003-08-08 13:35:34 +0000 |
---|---|---|
committer | Matthias Zenger <mzenger@gmail.com> | 2003-08-08 13:35:34 +0000 |
commit | 14cf5269961f2c8f3eafdaa16e7c9c4401105472 (patch) | |
tree | e13a67f828acba4ecaa456a10d581cc8d66dcaa4 | |
parent | 912a3dcbea224c5e8492ec9f252d2f1edf70d9f5 (diff) | |
download | scala-14cf5269961f2c8f3eafdaa16e7c9c4401105472.tar.gz scala-14cf5269961f2c8f3eafdaa16e7c9c4401105472.tar.bz2 scala-14cf5269961f2c8f3eafdaa16e7c9c4401105472.zip |
Removed tabs to make the emacs people happy.
-rw-r--r-- | sources/scala/collection/Map.scala | 80 | ||||
-rw-r--r-- | sources/scala/collection/Set.scala | 8 | ||||
-rw-r--r-- | sources/scala/collection/immutable/Queue.scala | 84 | ||||
-rw-r--r-- | sources/scala/collection/immutable/Stack.scala | 4 | ||||
-rw-r--r-- | sources/scala/collection/mutable/Buffer.scala | 13 | ||||
-rw-r--r-- | sources/scala/collection/mutable/DefaultMapModel.scala | 4 | ||||
-rw-r--r-- | sources/scala/collection/mutable/DoubleLinkedList.scala | 46 | ||||
-rw-r--r-- | sources/scala/collection/mutable/LinkedList.scala | 4 | ||||
-rw-r--r-- | sources/scala/collection/mutable/MutableList.scala | 10 | ||||
-rw-r--r-- | sources/scala/collection/mutable/ObservableSet.scala | 14 | ||||
-rw-r--r-- | sources/scala/collection/mutable/Queue.scala | 16 | ||||
-rw-r--r-- | sources/scala/collection/mutable/RevertableHistory.scala | 10 | ||||
-rw-r--r-- | sources/scala/collection/mutable/Stack.scala | 19 | ||||
-rw-r--r-- | sources/scala/collection/mutable/SynchronizedMap.scala | 4 |
14 files changed, 175 insertions, 141 deletions
diff --git a/sources/scala/collection/Map.scala b/sources/scala/collection/Map.scala index 14c2f3ef1a..c06048fd05 100644 --- a/sources/scala/collection/Map.scala +++ b/sources/scala/collection/Map.scala @@ -37,7 +37,7 @@ trait Map[A, +B] with PartialFunction[A, B] /** Check if this map maps <code>key</code> to a value and return the * value if it exists. * - * @param key the key of the mapping of interest + * @param key the key of the mapping of interest * @returns the value of the mapping, if it exists */ def get(key: A): Option[B]; @@ -52,7 +52,7 @@ trait Map[A, +B] with PartialFunction[A, B] * method throws an exception if there is no mapping from the given * key to a value. * - * @param key the key + * @param key the key * @returns the value associated with the given key. */ def apply(key: A): B = get(key) match { @@ -62,7 +62,7 @@ trait Map[A, +B] with PartialFunction[A, B] /** Is the given key mapped to a value by this map? * - * @param key the key + * @param key the key * @returns true, iff there is a mapping for key in this map */ def contains(key: A): Boolean = get(key) match { @@ -72,7 +72,7 @@ trait Map[A, +B] with PartialFunction[A, B] /** Does this map contain a mapping from the given key to a value? * - * @param key the key + * @param key the key * @returns true, iff there is a mapping for key in this map */ def isDefinedAt(key: A) = contains(key); @@ -100,7 +100,7 @@ trait Map[A, +B] with PartialFunction[A, B] /** Executes the given function for all (key, value) pairs * contained in this map. * - * @param f the function to execute. + * @param f the function to execute. */ def foreach(f: (A, B) => Unit) = { val iter = elements; @@ -110,33 +110,33 @@ trait Map[A, +B] with PartialFunction[A, B] } } - /** Applies the given predicate to all (key, value) mappings - * contained in this map and returns true if this predicate - * yields true for all mappings. - * - * @param p the predicate - * @returns true, iff p yields true for all mappings. - */ - def forall(p: (A, B) => Boolean): Boolean = elements.forall { - case Pair(key, value) => p(key, value) - } + /** Applies the given predicate to all (key, value) mappings + * contained in this map and returns true if this predicate + * yields true for all mappings. + * + * @param p the predicate + * @returns true, iff p yields true for all mappings. + */ + def forall(p: (A, B) => Boolean): Boolean = elements.forall { + case Pair(key, value) => p(key, value) + } /** Applies the given predicate to all (key, value) mappings - * contained in this map and returns true if there is at least - * one mapping for which this predicate yields true. - * - * @param p the predicate - * @returns true, iff there is at least one mapping for which - * p yields true. - */ + * contained in this map and returns true if there is at least + * one mapping for which this predicate yields true. + * + * @param p the predicate + * @returns true, iff there is at least one mapping for which + * p yields true. + */ def exists(p: (A, B) => Boolean): Boolean = elements.exists { - case Pair(key, value) => p(key, value) - } + case Pair(key, value) => p(key, value) + } - /** Creates a list of all (key, value) mappings. - * - * @returns the list of all mappings - */ + /** Creates a list of all (key, value) mappings. + * + * @returns the list of all mappings + */ def toList: List[Pair[A, B]] = { var res: List[Pair[A, B]] = Nil; elements.foreach { mapping => res = mapping :: res; }; @@ -147,22 +147,22 @@ trait Map[A, +B] with PartialFunction[A, B] * contained in this map are also contained in the other map, * and vice versa. * - * @returns true, iff both maps contain exactly the same mappings. + * @returns true, iff both maps contain exactly the same mappings. */ - override def ===[C >: Map[A, B]](that: C): Boolean = - that.isInstanceOf[Map[A, B]] && - { val other = that.asInstanceOf[Map[A, B]]; - this.size == other.size && - this.elements.forall { - case Pair(key, value) => other.get(key) match { - case None => false; - case Some(otherval) => value == otherval; - } - }}; + override def ===[C >: Map[A, B]](that: C): Boolean = + that.isInstanceOf[Map[A, B]] && + { val other = that.asInstanceOf[Map[A, B]]; + this.size == other.size && + this.elements.forall { + case Pair(key, value) => other.get(key) match { + case None => false; + case Some(otherval) => value == otherval; + } + }}; /** Creates a string representation for this map. * - * @returns a string showing all mappings + * @returns a string showing all mappings */ override def toString() = if (size == 0) diff --git a/sources/scala/collection/Set.scala b/sources/scala/collection/Set.scala index 76dd891f47..cee20b3241 100644 --- a/sources/scala/collection/Set.scala +++ b/sources/scala/collection/Set.scala @@ -47,10 +47,10 @@ trait Set[A] with Iterable[A] } override def ===[B >: Set[A]](that: B): Boolean = - that.isInstanceOf[Set[A]] && - { val other = that.asInstanceOf[Set[A]]; - this.size == other.size && - this.elements.forall(other.contains) }; + that.isInstanceOf[Set[A]] && + { val other = that.asInstanceOf[Set[A]]; + this.size == other.size && + this.elements.forall(other.contains) }; override def toString(): String = if (size == 0) diff --git a/sources/scala/collection/immutable/Queue.scala b/sources/scala/collection/immutable/Queue.scala index a3291d46e4..2e6dce6367 100644 --- a/sources/scala/collection/immutable/Queue.scala +++ b/sources/scala/collection/immutable/Queue.scala @@ -31,8 +31,8 @@ class Queue[+A](in: List[A], out: List[A]) extends Seq[A] * @throws java.lang.RuntimeException if the list is too short. */ def apply(n: Int): A = - if (n < out.length) out.apply(n) - else in.reverse.apply(n - out.length); + if (n < out.length) out.apply(n) + else in.reverse.apply(n - out.length); /** Returns the elements in the list as an iterator */ @@ -64,14 +64,14 @@ class Queue[+A](in: List[A], out: List[A]) extends Seq[A] * @param iter an iterable object */ def +[B >: A](iter: Iterable[B]) = { - var q:List[B] = in; - iter.elements.foreach(e => q = (e::q)); - new Queue(q,out); + var q:List[B] = in; + iter.elements.foreach(e => q = (e::q)); + new Queue(q,out); } /** Returns a new queue with all elements added. * - * @param elems the elements to add. + * @param elems the elements to add. */ def enqueue [B >: A](elems: B*): Queue[B] = (this + elems); @@ -81,17 +81,17 @@ class Queue[+A](in: List[A], out: List[A]) extends Seq[A] * @returns the first element of the queue. */ def dequeue: Pair[A,Queue[A]] = { - var newOut:List[A]=Nil; - var newIn:List[A]=Nil; - if (out.isEmpty) { - newOut = in.reverse; - newIn = Nil; - } else { - newOut = out; - newIn = in; - } - if (newOut.isEmpty) - error("queue empty"); + var newOut:List[A]=Nil; + var newIn:List[A]=Nil; + if (out.isEmpty) { + newOut = in.reverse; + newIn = Nil; + } else { + newOut = out; + newIn = in; + } + if (newOut.isEmpty) + error("queue empty"); else Pair(newOut.head,new Queue(newIn,newOut.tail)); } @@ -102,10 +102,10 @@ class Queue[+A](in: List[A], out: List[A]) extends Seq[A] * @returns the first element. */ def front: A = - if (out.isEmpty) { - if (in.isEmpty) error("queue empty") else in.last; - } else - out.head; + if (out.isEmpty) { + if (in.isEmpty) error("queue empty") else in.last; + } else + out.head; /** Returns a string representation of this queue. The resulting string * begins with the string <code>start</code> and is finished by the string @@ -120,7 +120,7 @@ class Queue[+A](in: List[A], out: List[A]) extends Seq[A] * @param end ending string. * @return a string representation of this list. */ - def mkString(start: String, sep: String, end: String): String = + def mkString(start: String, sep: String, end: String): String = (out ::: (in.reverse)).mkString(start,sep,end); /** Returns a string representation of this queue. @@ -133,26 +133,26 @@ class Queue[+A](in: List[A], out: List[A]) extends Seq[A] * @returns true, iff the two queues are structurally equal. */ override def equals(o: Any): Boolean = o match { - case q: Queue[Any] => - /* A function that compares the element at - position index in q with the element at - the same position in this (queue). - If they are equal the next element is - compared. */ - def eqe(index: int):Boolean = { - /* If all elements are compared - the queues are equal. */ - index >= this.length || - /* Otherwise: compare the elements */ - (q.apply(index) == this.apply(index) && - /* if they are equal compare the rest. */ - eqe(index+1)) - } - /* If the length of the ques are the same, - compare each element, starting at index 0. */ - (q.length == this.length) && eqe(0); - - case _ => false; /* o is not a queue: not equal to this. */ + case q: Queue[Any] => + /* A function that compares the element at + position index in q with the element at + the same position in this (queue). + If they are equal the next element is + compared. */ + def eqe(index: int):Boolean = { + /* If all elements are compared + the queues are equal. */ + index >= this.length || + /* Otherwise: compare the elements */ + (q.apply(index) == this.apply(index) && + /* if they are equal compare the rest. */ + eqe(index+1)) + } + /* If the length of the ques are the same, + compare each element, starting at index 0. */ + (q.length == this.length) && eqe(0); + + case _ => false; /* o is not a queue: not equal to this. */ } } diff --git a/sources/scala/collection/immutable/Stack.scala b/sources/scala/collection/immutable/Stack.scala index 1c63d3d69d..6f12460b9d 100644 --- a/sources/scala/collection/immutable/Stack.scala +++ b/sources/scala/collection/immutable/Stack.scala @@ -106,9 +106,9 @@ class Stack[+A] with Seq[A] with StructuralEquality[Stack[A]] { */ override def equals(obj: Any): Boolean = if (obj.isInstanceOf[Stack[A]]) - toList.equals((obj.asInstanceOf[Stack[A]]).toList); + toList.equals((obj.asInstanceOf[Stack[A]]).toList); else - false; + false; /** Returns the hash code for this stack. * diff --git a/sources/scala/collection/mutable/Buffer.scala b/sources/scala/collection/mutable/Buffer.scala index 13ec8aa6eb..487c493276 100644 --- a/sources/scala/collection/mutable/Buffer.scala +++ b/sources/scala/collection/mutable/Buffer.scala @@ -18,7 +18,7 @@ package scala.collection.mutable; * @author Matthias Zenger * @version 1.0, 08/07/2003 */ -class Buffer[A] with MutableList[A] { +class Buffer[A] with MutableList[A] with StructuralEquality[Buffer[A]] { def prepend(elem: A) = prependElem(elem); @@ -85,4 +85,15 @@ class Buffer[A] with MutableList[A] { } def clear: Unit = reset; + + /** Checks if two buffers are structurally identical. + * + * @returns true, iff both buffers contain the same sequence of elements. + */ + override def ===[B >: Buffer[A]](that: B) = + that.isInstanceOf[Buffer[A]] && + { val other = that.asInstanceOf[Buffer[A]]; + elements.zip(other.elements).forall { + case Pair(thiselem, thatelem) => thiselem == thatelem; + }}; } diff --git a/sources/scala/collection/mutable/DefaultMapModel.scala b/sources/scala/collection/mutable/DefaultMapModel.scala index 7da241c83f..7b2893a13e 100644 --- a/sources/scala/collection/mutable/DefaultMapModel.scala +++ b/sources/scala/collection/mutable/DefaultMapModel.scala @@ -19,9 +19,9 @@ package scala.collection.mutable; */ trait DefaultMapModel[A, B] extends scala.collection.mutable.Map[A, B] { - protected def findEntry(key: A): Option[Entry]; + protected def findEntry(key: A): Option[Entry]; - protected def addEntry(e: Entry): Unit; + protected def addEntry(e: Entry): Unit; protected def entries: Iterator[Entry]; diff --git a/sources/scala/collection/mutable/DoubleLinkedList.scala b/sources/scala/collection/mutable/DoubleLinkedList.scala index b21b67b560..36fa504afe 100644 --- a/sources/scala/collection/mutable/DoubleLinkedList.scala +++ b/sources/scala/collection/mutable/DoubleLinkedList.scala @@ -18,31 +18,31 @@ package scala.collection.mutable; * @version 1.0, 08/07/2003 */ abstract class DoubleLinkedList[A, This <: DoubleLinkedList[A, This]]: This - extends SingleLinkedList[A, This] { + extends SingleLinkedList[A, This] { - var prev: This = _; + var prev: This = _; - override def append(that: This): Unit = - if (that == null) - () - else if (next == null) { - next = that; - that.prev = this; - } else - next.append(that); + override def append(that: This): Unit = + if (that == null) + () + else if (next == null) { + next = that; + that.prev = this; + } else + next.append(that); - override def insert(that: This): Unit = if (that != null) { - that.append(next); - next = that; - that.prev = this; - } + override def insert(that: This): Unit = if (that != null) { + that.append(next); + next = that; + that.prev = this; + } - def remove: Unit = { - if (next != null) - next.prev = prev; - if (prev != null) - prev.next = next; - prev = null; - next = null; - } + def remove: Unit = { + if (next != null) + next.prev = prev; + if (prev != null) + prev.next = next; + prev = null; + next = null; + } } diff --git a/sources/scala/collection/mutable/LinkedList.scala b/sources/scala/collection/mutable/LinkedList.scala index 1f38d894f6..09d4819576 100644 --- a/sources/scala/collection/mutable/LinkedList.scala +++ b/sources/scala/collection/mutable/LinkedList.scala @@ -17,6 +17,6 @@ package scala.collection.mutable; */ class LinkedList[A](head: A, tail: LinkedList[A]) extends SingleLinkedList[A, LinkedList[A]] { - elem = head; - next = tail; + elem = head; + next = tail; } diff --git a/sources/scala/collection/mutable/MutableList.scala b/sources/scala/collection/mutable/MutableList.scala index cd55e0f7ee..8996da246a 100644 --- a/sources/scala/collection/mutable/MutableList.scala +++ b/sources/scala/collection/mutable/MutableList.scala @@ -33,7 +33,7 @@ class MutableList[A] with Seq[A] with PartialFunction[Int, A] { def get(n: Int): Option[A] = first.get(n); protected def prependElem(elem: A): Unit = { - first = new LinkedList[A](elem, first); + first = new LinkedList[A](elem, first); if (len == 0) last = first; len = len + 1; @@ -50,13 +50,13 @@ class MutableList[A] with Seq[A] with PartialFunction[Int, A] { } protected def reset: Unit = { - first = null; - last = null; - len = 0; + first = null; + last = null; + len = 0; } def elements: Iterator[A] = - if (first == null) Nil.elements else first.elements; + if (first == null) Nil.elements else first.elements; def toList: List[A] = if (first == null) Nil else first.toList; diff --git a/sources/scala/collection/mutable/ObservableSet.scala b/sources/scala/collection/mutable/ObservableSet.scala index 4d49ce0360..7b09759b6e 100644 --- a/sources/scala/collection/mutable/ObservableSet.scala +++ b/sources/scala/collection/mutable/ObservableSet.scala @@ -22,14 +22,14 @@ abstract class ObservableSet[A, This <: ObservableSet[A, This]]: This with Publisher[ObservableUpdate[A] with Undo, This] { override def +=(elem: A): Unit = if (!contains(elem)) { - super.+=(elem); - publish(new Inclusion(elem) with Undo { def undo = -=(elem); }); - } + super.+=(elem); + publish(new Inclusion(elem) with Undo { def undo = -=(elem); }); + } - override def -=(elem: A): Unit = if (contains(elem)) { - super.-=(elem); - publish(new Removal(elem) with Undo { def undo = +=(elem); }); - } + override def -=(elem: A): Unit = if (contains(elem)) { + super.-=(elem); + publish(new Removal(elem) with Undo { def undo = +=(elem); }); + } override def clear: Unit = { super.clear; diff --git a/sources/scala/collection/mutable/Queue.scala b/sources/scala/collection/mutable/Queue.scala index b25b4cdf72..a53faca37c 100644 --- a/sources/scala/collection/mutable/Queue.scala +++ b/sources/scala/collection/mutable/Queue.scala @@ -15,7 +15,7 @@ package scala.collection.mutable; * @author Matthias Zenger * @version 1.0, 08/07/2003 */ -class Queue[A] with MutableList[A] { +class Queue[A] with MutableList[A] with StructuralEquality[Queue[A]] { /** Checks if the queue is empty. * @@ -39,7 +39,7 @@ class Queue[A] with MutableList[A] { /** Adds all elements to the queue. * - * @param elems the elements to add. + * @param elems the elements to add. */ def enqueue(elems: A*): Unit = (this += elems); @@ -69,4 +69,16 @@ class Queue[A] with MutableList[A] { * the queue will be empty. */ def clear: Unit = reset; + + /** Checks if two queues are structurally identical. + * + * @returns true, iff both queues contain the same sequence of elements. + */ + override def ===[B >: Queue[A]](that: B) = + that.isInstanceOf[Queue[A]] && + { val other = that.asInstanceOf[Queue[A]]; + elements.zip(other.elements).forall { + case Pair(thiselem, thatelem) => thiselem == thatelem; + }}; } + diff --git a/sources/scala/collection/mutable/RevertableHistory.scala b/sources/scala/collection/mutable/RevertableHistory.scala index 9358e3f476..8430dfb96c 100644 --- a/sources/scala/collection/mutable/RevertableHistory.scala +++ b/sources/scala/collection/mutable/RevertableHistory.scala @@ -23,10 +23,10 @@ class RevertableHistory[A <: Undo, B] extends History[A, B] with Undo { /** Rollback the full history. */ def undo: Unit = { - val old = log.toList.reverse; - clear; - old.foreach { - case Pair(sub, event) => event.undo; - } + val old = log.toList.reverse; + clear; + old.foreach { + case Pair(sub, event) => event.undo; + } } } diff --git a/sources/scala/collection/mutable/Stack.scala b/sources/scala/collection/mutable/Stack.scala index dca34693ce..258fe1591f 100644 --- a/sources/scala/collection/mutable/Stack.scala +++ b/sources/scala/collection/mutable/Stack.scala @@ -16,7 +16,7 @@ package scala.collection.mutable; * @author Matthias Zenger * @version 1.0, 08/07/2003 */ -class Stack[A] with MutableList[A] { +class Stack[A] with MutableList[A] with StructuralEquality[Stack[A]] { /** Checks if the stack is empty. * @@ -26,7 +26,7 @@ class Stack[A] with MutableList[A] { /** Pushes a single element on top of the stack. * - * @param elem the element to push onto the stack + * @param elem the element to push onto the stack */ def +=(elem: A): Unit = prependElem(elem); @@ -34,14 +34,14 @@ class Stack[A] with MutableList[A] { * on top of the stack. The elements are pushed in the order they * are given out by the iterator. * - * @param iter an iterable object + * @param iter an iterable object */ def +=(iter: Iterable[A]): Unit = iter.elements.foreach(e => prependElem(e)); /** Pushes a sequence of elements on top of the stack. The first element * is pushed first, etc. * - * @param elems a sequence of elements + * @param elems a sequence of elements */ def push(elems: A*): Unit = (this += elems); @@ -77,4 +77,15 @@ class Stack[A] with MutableList[A] { * @returns the created list. */ override def toList: List[A] = super.toList.reverse; + + /** Checks if two stacks are structurally identical. + * + * @returns true, iff both stacks contain the same sequence of elements. + */ + override def ===[B >: Stack[A]](that: B) = + that.isInstanceOf[Stack[A]] && + { val other = that.asInstanceOf[Stack[A]]; + elements.zip(other.elements).forall { + case Pair(thiselem, thatelem) => thiselem == thatelem; + }}; } diff --git a/sources/scala/collection/mutable/SynchronizedMap.scala b/sources/scala/collection/mutable/SynchronizedMap.scala index 0837d95cb0..435caa0526 100644 --- a/sources/scala/collection/mutable/SynchronizedMap.scala +++ b/sources/scala/collection/mutable/SynchronizedMap.scala @@ -75,11 +75,11 @@ trait SynchronizedMap[A, B] extends scala.collection.mutable.Map[A, B] with Moni } override def excl(keys: A*): Unit = synchronized { - super.excl(keys); + super.excl(keys); } override def excl(keys: Iterable[A]): Unit = synchronized { - super.excl(keys); + super.excl(keys); } override def clear: Unit = synchronized { |