diff options
author | Martin Odersky <odersky@gmail.com> | 2005-12-08 15:15:56 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2005-12-08 15:15:56 +0000 |
commit | 2d91f011f2ba54bb3ac733f3dcf4a518ea56d50e (patch) | |
tree | 956f4cf7f0745cf6916ad67354fcb7c42659969d /sources/scala/collection | |
parent | e0d7aeaa9d32afce117d366b179e7a8205586f2e (diff) | |
download | scala-2d91f011f2ba54bb3ac733f3dcf4a518ea56d50e.tar.gz scala-2d91f011f2ba54bb3ac733f3dcf4a518ea56d50e.tar.bz2 scala-2d91f011f2ba54bb3ac733f3dcf4a518ea56d50e.zip |
*** empty log message ***
Diffstat (limited to 'sources/scala/collection')
-rw-r--r-- | sources/scala/collection/BitSet.scala | 7 | ||||
-rw-r--r-- | sources/scala/collection/Map.scala | 13 | ||||
-rw-r--r-- | sources/scala/collection/Set.scala | 5 | ||||
-rw-r--r-- | sources/scala/collection/immutable/BitSet.scala | 5 | ||||
-rw-r--r-- | sources/scala/collection/immutable/Queue.scala | 12 | ||||
-rw-r--r-- | sources/scala/collection/mutable/HashMap.scala | 2 | ||||
-rw-r--r-- | sources/scala/collection/mutable/LinkedList.scala | 5 | ||||
-rw-r--r-- | sources/scala/collection/mutable/PriorityQueue.scala | 5 | ||||
-rw-r--r-- | sources/scala/collection/mutable/Queue.scala | 5 | ||||
-rw-r--r-- | sources/scala/collection/mutable/Stack.scala | 5 |
10 files changed, 39 insertions, 25 deletions
diff --git a/sources/scala/collection/BitSet.scala b/sources/scala/collection/BitSet.scala index bd047bcc2c..5f7d325208 100644 --- a/sources/scala/collection/BitSet.scala +++ b/sources/scala/collection/BitSet.scala @@ -51,12 +51,13 @@ package scala.collection; * * @return true, iff both bitsets contain the same sequence of elements. */ - override def equals(that: Any): Boolean = + override def equals(that: Any): Boolean = ( that.isInstanceOf[BitSet] && { val other = that.asInstanceOf[BitSet]; (size == other.size) && - (Iterator.range(0, size) forall { i => apply(i) == other.apply(i)}); - }; + (Iterator.range(0, size) forall { i => apply(i) == other.apply(i)}) + } + ); /** * applies f to any index which is set to true. 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") } diff --git a/sources/scala/collection/Set.scala b/sources/scala/collection/Set.scala index a4cf078543..b222b81648 100644 --- a/sources/scala/collection/Set.scala +++ b/sources/scala/collection/Set.scala @@ -67,11 +67,12 @@ trait Set[A] extends AnyRef with Function1[A, Boolean] with Iterable[A] { * @return true, iff this set and the other set contain the same * elements. */ - override def equals(that: Any): Boolean = + override def equals(that: Any): Boolean = ( that.isInstanceOf[Set[A]] && { val other = that.asInstanceOf[Set[A]]; this.size == other.size && - this.elements.forall(other.contains) }; + this.elements.forall(other.contains) } + ); /** Returns the elements of this set as a list. * diff --git a/sources/scala/collection/immutable/BitSet.scala b/sources/scala/collection/immutable/BitSet.scala index 8835fde146..61299bf069 100644 --- a/sources/scala/collection/immutable/BitSet.scala +++ b/sources/scala/collection/immutable/BitSet.scala @@ -70,7 +70,7 @@ class BitSet(n:Int, ba: Array[Int], copy: Boolean) extends collection.BitSet wit * * @return true, iff both bitsets contain the same sequence of elements. */ - override def equals(that: Any): Boolean = + override def equals(that: Any): Boolean = ( that.isInstanceOf[BitSet] && { val other = that.asInstanceOf[BitSet]; (size == other.size) && ( size == 0 || { @@ -83,7 +83,8 @@ class BitSet(n:Int, ba: Array[Int], copy: Boolean) extends collection.BitSet wit } res }) - } || super.equals(that); + } || super.equals(that) + ); def this(rbs: mutable.BitSet) = { this(rbs.size, rbs.toArray, false); diff --git a/sources/scala/collection/immutable/Queue.scala b/sources/scala/collection/immutable/Queue.scala index 74b9a45cd2..cb005d3b5e 100644 --- a/sources/scala/collection/immutable/Queue.scala +++ b/sources/scala/collection/immutable/Queue.scala @@ -148,18 +148,18 @@ class Queue[+A](elem: A*) extends Seq[A] { the same position in this (queue). If they are equal the next element is compared. */ - def eqe(index: Int): Boolean = { + 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); + 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/mutable/HashMap.scala b/sources/scala/collection/mutable/HashMap.scala index 6388b78f25..dcdde2e40c 100644 --- a/sources/scala/collection/mutable/HashMap.scala +++ b/sources/scala/collection/mutable/HashMap.scala @@ -28,7 +28,7 @@ class HashMap[A, B] extends scala.collection.mutable.Map[A, B] tableSize = 0; } - override def clone(): HashMap[A, B] = { + override def clone(): Map[A, B] = { val res = new HashMap[A, B]; res ++= this; res diff --git a/sources/scala/collection/mutable/LinkedList.scala b/sources/scala/collection/mutable/LinkedList.scala index a8970da2ae..03f6093cc9 100644 --- a/sources/scala/collection/mutable/LinkedList.scala +++ b/sources/scala/collection/mutable/LinkedList.scala @@ -22,9 +22,10 @@ class LinkedList[A](head: A, tail: LinkedList[A]) elem = head; next = tail; - override def equals(obj: Any): Boolean = + override def equals(obj: Any): Boolean = ( obj.isInstanceOf[LinkedList[A]] - && toList.equals((obj.asInstanceOf[LinkedList[A]]).toList); + && toList.equals((obj.asInstanceOf[LinkedList[A]]).toList) + ); override protected def stringPrefix: String = "LinkedList"; } diff --git a/sources/scala/collection/mutable/PriorityQueue.scala b/sources/scala/collection/mutable/PriorityQueue.scala index 82d76ec957..83552417cc 100644 --- a/sources/scala/collection/mutable/PriorityQueue.scala +++ b/sources/scala/collection/mutable/PriorityQueue.scala @@ -135,12 +135,13 @@ class PriorityQueue[A <% Ordered[A]] extends ResizableArray[A] with java.io.Seri * * @return true, iff both queues contain the same sequence of elements. */ - override def equals(that: Any): Boolean = + override def equals(that: Any): Boolean = ( that.isInstanceOf[PriorityQueue[A]] && { val other = that.asInstanceOf[PriorityQueue[A]]; elements.zip(other.elements).forall { case Pair(thiselem, thatelem) => thiselem == thatelem; - }}; + }} + ); /** The hashCode method always yields an error, since it is not * safe to use mutable queues as keys in hash tables. diff --git a/sources/scala/collection/mutable/Queue.scala b/sources/scala/collection/mutable/Queue.scala index 2f22411ede..0d297f5e0d 100644 --- a/sources/scala/collection/mutable/Queue.scala +++ b/sources/scala/collection/mutable/Queue.scala @@ -161,12 +161,13 @@ class Queue[A] extends MutableList[A] { * * @return true, iff both queues contain the same sequence of elements. */ - override def equals(that: Any): Boolean = + override def equals(that: Any): Boolean = ( that.isInstanceOf[Queue[A]] && { val other = that.asInstanceOf[Queue[A]]; elements.zip(other.elements).forall { case Pair(thiselem, thatelem) => thiselem == thatelem; - }}; + }} + ); /** The hashCode method always yields an error, since it is not * safe to use mutable queues as keys in hash tables. diff --git a/sources/scala/collection/mutable/Stack.scala b/sources/scala/collection/mutable/Stack.scala index a5ba0f97f2..0cf269dba7 100644 --- a/sources/scala/collection/mutable/Stack.scala +++ b/sources/scala/collection/mutable/Stack.scala @@ -99,12 +99,13 @@ class Stack[A] extends MutableList[A] { * * @return true, iff both stacks contain the same sequence of elements. */ - override def equals(that: Any): Boolean = + override def equals(that: Any): Boolean = ( that.isInstanceOf[Stack[A]] && { val other = that.asInstanceOf[Stack[A]]; elements.zip(other.elements).forall { case Pair(thiselem, thatelem) => thiselem == thatelem; - }}; + }} + ); /** The hashCode method always yields an error, since it is not * safe to use mutable stacks as keys in hash tables. |