summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2008-02-26 17:50:12 +0000
committermichelou <michelou@epfl.ch>2008-02-26 17:50:12 +0000
commit6b1bf0c0c9579c7dda0169bc5fb8a1322407d7a7 (patch)
treeeaecd2496d5f9b30c85760b8a0cb9267a1e972a9
parente2d790348afa914fba28bc71775b818ef71ed1f5 (diff)
downloadscala-6b1bf0c0c9579c7dda0169bc5fb8a1322407d7a7.tar.gz
scala-6b1bf0c0c9579c7dda0169bc5fb8a1322407d7a7.tar.bz2
scala-6b1bf0c0c9579c7dda0169bc5fb8a1322407d7a7.zip
fixed #551 and #566
-rw-r--r--src/library/scala/collection/mutable/LinkedHashMap.scala21
-rw-r--r--src/library/scala/collection/mutable/LinkedHashSet.scala14
-rw-r--r--src/library/scala/collection/mutable/LinkedList.scala15
-rw-r--r--src/library/scala/runtime/RichString.scala25
4 files changed, 51 insertions, 24 deletions
diff --git a/src/library/scala/collection/mutable/LinkedHashMap.scala b/src/library/scala/collection/mutable/LinkedHashMap.scala
index b51cdb08ab..7ab4b11376 100644
--- a/src/library/scala/collection/mutable/LinkedHashMap.scala
+++ b/src/library/scala/collection/mutable/LinkedHashMap.scala
@@ -33,14 +33,16 @@ object LinkedHashMap {
class LinkedHashMap[A, B] extends Map[A,B] with HashTable[A] with DefaultMapModel[A,B] {
private var ordered = List[Entry]()
- def remove(key : A) : Option[B] = removeEntry(key) match {
- case None => None
- case Some(e) =>
- ordered = ordered.filter(_ ne e)
- Some(e.value)
- }
+ def remove(key: A): Option[B] = removeEntry(key) match {
+ case None => None
+ case Some(e) =>
+ ordered = ordered.filter(_ ne e)
+ Some(e.value)
+ }
+
def -= (key: A) { remove(key) }
- override def put(key : A, value : B) : Option[B] = {
+
+ override def put(key: A, value: B): Option[B] = {
val e = findEntry(key)
if (e == null) {
val e = new Entry(key, value)
@@ -54,10 +56,13 @@ class LinkedHashMap[A, B] extends Map[A,B] with HashTable[A] with DefaultMapMode
}
}
override def update(key: A, value: B) { put(key, value) }
- override def clear() = {
+
+ override def clear() {
ordered = Nil
super.clear()
}
+
override def clone(): Map[A, B] = new LinkedHashMap[A, B] ++ this
+
override def elements = ordered.reverse.elements map {e => (e.key, e.value)}
}
diff --git a/src/library/scala/collection/mutable/LinkedHashSet.scala b/src/library/scala/collection/mutable/LinkedHashSet.scala
index b86bccd173..7fad429eaf 100644
--- a/src/library/scala/collection/mutable/LinkedHashSet.scala
+++ b/src/library/scala/collection/mutable/LinkedHashSet.scala
@@ -1,7 +1,7 @@
/* __ *\
** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2005-2006, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | **
+** / __/ __// _ | / / / _ | (c) 2005-2008, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
@@ -28,19 +28,19 @@ class LinkedHashSet[A] extends Set[A] with FlatHashTable[A] {
def +=(elem: A) { add(elem) }
- def add(elem : A) : Boolean = {
+ def add(elem: A): Boolean = {
if (addEntry(elem)) {
ordered = elem :: ordered
true
} else false
}
def -=(elem: A) { remove(elem) }
- def remove(elem : A) : Boolean = removeEntry(elem) match {
- case None => false
- case Some(elem) => ordered = ordered.filter(e => e != elem); true
+ def remove(elem: A) : Boolean = removeEntry(elem) match {
+ case None => false
+ case Some(elem) => ordered = ordered.filter(_ != elem); true
}
- override def clear() = {
+ override def clear() {
ordered = Nil
super.clear()
}
diff --git a/src/library/scala/collection/mutable/LinkedList.scala b/src/library/scala/collection/mutable/LinkedList.scala
index 0ed1a02889..6b9cef7234 100644
--- a/src/library/scala/collection/mutable/LinkedList.scala
+++ b/src/library/scala/collection/mutable/LinkedList.scala
@@ -1,6 +1,6 @@
/* __ *\
** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2007, LAMP/EPFL **
+** / __/ __// _ | / / / _ | (c) 2003-2008, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
@@ -22,11 +22,24 @@ class LinkedList[A](var elem: A, var next: LinkedList[A])
extends SingleLinkedList[A, LinkedList[A]]
{
+ /** Compares two lists structurally; i.e. checks if all elements
+ * contained in this list are also contained in the other list,
+ * and vice versa.
+ *
+ * @param that the other list
+ * @return <code>true</code> iff both lists contain exactly the
+ * same mappings.
+ */
override def equals(obj: Any): Boolean = obj match {
case that: LinkedList[_] => this.toList equals that.toList
case _ => false
}
+ /** A hash method compatible with <code>equals</code>
+ */
+ override def hashCode(): Int =
+ (0 /: elements) ((hash, kv) => hash + kv.hashCode)
+
override protected def stringPrefix: String = "LinkedList"
}
diff --git a/src/library/scala/runtime/RichString.scala b/src/library/scala/runtime/RichString.scala
index f562702405..435422bb64 100644
--- a/src/library/scala/runtime/RichString.scala
+++ b/src/library/scala/runtime/RichString.scala
@@ -1,6 +1,6 @@
/* __ *\
** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2002-2007, LAMP/EPFL **
+** / __/ __// _ | / / / _ | (c) 2002-2008, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
@@ -189,12 +189,13 @@ final class RichString(val self: String) extends Proxy with RandomAccessSeq[Char
self.split(re)
}
- def toByte: Byte = java.lang.Byte.parseByte(self)
- def toShort: Short = java.lang.Short.parseShort(self)
- def toInt: Int = java.lang.Integer.parseInt(self)
- def toLong: Long = java.lang.Long.parseLong(self)
- def toFloat: Float = java.lang.Float.parseFloat(self)
- def toDouble: Double = java.lang.Double.parseDouble(self)
+ def toBoolean: Boolean = parseBoolean(self)
+ def toByte: Byte = java.lang.Byte.parseByte(self)
+ def toShort: Short = java.lang.Short.parseShort(self)
+ def toInt: Int = java.lang.Integer.parseInt(self)
+ def toLong: Long = java.lang.Long.parseLong(self)
+ def toFloat: Float = java.lang.Float.parseFloat(self)
+ def toDouble: Double = java.lang.Double.parseDouble(self)
}
object RichString {
@@ -203,5 +204,13 @@ object RichString {
private final val FF: Char = 0x0C
private final val CR: Char = 0x0D
private final val SU: Char = 0x1A
-}
+ private def parseBoolean(s: String): Boolean =
+ if (s != null) s.toLowerCase match {
+ case "true" => true
+ case "false" => false
+ case _ => throw new NumberFormatException("For input string: \""+s+"\"")
+ }
+ else
+ throw new NumberFormatException("For input string: \"null\"")
+}