diff options
author | Burak Emir <emir@epfl.ch> | 2006-09-06 15:33:54 +0000 |
---|---|---|
committer | Burak Emir <emir@epfl.ch> | 2006-09-06 15:33:54 +0000 |
commit | 643711f83a1b5897002c4592ea463d0fc198e986 (patch) | |
tree | 876c981e56e5578adb52a1d299760077511ec264 | |
parent | 75df1caebc4735dcfac8b7e29ce059692449ddd6 (diff) | |
download | scala-643711f83a1b5897002c4592ea463d0fc198e986.tar.gz scala-643711f83a1b5897002c4592ea463d0fc198e986.tar.bz2 scala-643711f83a1b5897002c4592ea463d0fc198e986.zip |
added Seq.isEmpty and changed XML representation
-rw-r--r-- | src/library/scala/List.scala | 6 | ||||
-rw-r--r-- | src/library/scala/Seq.scala | 6 | ||||
-rw-r--r-- | src/library/scala/Stream.scala | 6 | ||||
-rw-r--r-- | src/library/scala/collection/immutable/Queue.scala | 2 | ||||
-rw-r--r-- | src/library/scala/collection/immutable/Stack.scala | 2 | ||||
-rw-r--r-- | src/library/scala/collection/mutable/PriorityQueue.scala | 2 | ||||
-rw-r--r-- | src/library/scala/collection/mutable/Queue.scala | 2 | ||||
-rw-r--r-- | src/library/scala/collection/mutable/Stack.scala | 2 | ||||
-rw-r--r-- | src/library/scala/xml/NodeBuffer.scala | 7 | ||||
-rw-r--r-- | src/library/scala/xml/Utility.scala | 23 |
10 files changed, 40 insertions, 18 deletions
diff --git a/src/library/scala/List.scala b/src/library/scala/List.scala index 1802a4b479..708fadc4a0 100644 --- a/src/library/scala/List.scala +++ b/src/library/scala/List.scala @@ -370,7 +370,7 @@ sealed abstract class List[+a] extends Seq[a] with CaseClass { /** Returns true if the list does not contain any elements. * @return true, iff the list is empty. */ - def isEmpty: Boolean; + override def isEmpty: Boolean; /** Returns this first element of the list. * @return the first element of this list. @@ -1079,7 +1079,7 @@ sealed abstract class List[+a] extends Seq[a] with CaseClass { */ [SerialVersionUID(0 - 8256821097970055419L)] case object Nil extends List[Nothing] { - def isEmpty = true; + override def isEmpty = true; def head: All = error("head of empty list"); def tail: List[Nothing] = error("tail of empty list"); } @@ -1093,5 +1093,5 @@ case object Nil extends List[Nothing] { final case class ::[b](hd: b, private[scala] var tl: List[b]) extends List[b] { def head = hd; def tail = tl; - def isEmpty: boolean = false; + override def isEmpty: boolean = false; } diff --git a/src/library/scala/Seq.scala b/src/library/scala/Seq.scala index 7eec547b36..f36288bc06 100644 --- a/src/library/scala/Seq.scala +++ b/src/library/scala/Seq.scala @@ -60,6 +60,12 @@ trait Seq[+A] extends AnyRef with PartialFunction[Int, A] with Iterable[A] { */ def length: Int + /** Returns true is length == 0 + * + * @return the sequence length. + */ + def isEmpty: Boolean = { length == 0 } + /** Returns the concatenation of two sequences. * * @return concatenation of this sequence with argument diff --git a/src/library/scala/Stream.scala b/src/library/scala/Stream.scala index 0f2662cf5b..07954ed08c 100644 --- a/src/library/scala/Stream.scala +++ b/src/library/scala/Stream.scala @@ -23,14 +23,14 @@ import scala.runtime.compat.StringBuilder object Stream { val empty: Stream[Nothing] = new Stream[Nothing] { - def isEmpty = true + override def isEmpty = true def head: Nothing = error("head of empty stream") def tail: Stream[Nothing] = error("tail of empty stream") def printElems(buf: StringBuilder, prefix: String): StringBuilder = buf } def cons[a](hd: a, tl: => Stream[a]) = new Stream[a] { - def isEmpty = false + override def isEmpty = false def head = hd private var tlVal: Stream[a] = _ private var tlDefined = false @@ -146,7 +146,7 @@ object Stream { */ trait Stream[+a] extends Seq[a] { - def isEmpty: Boolean + override def isEmpty: Boolean def head: a def tail: Stream[a] diff --git a/src/library/scala/collection/immutable/Queue.scala b/src/library/scala/collection/immutable/Queue.scala index 49b34634e9..1329a44e03 100644 --- a/src/library/scala/collection/immutable/Queue.scala +++ b/src/library/scala/collection/immutable/Queue.scala @@ -52,7 +52,7 @@ class Queue[+A](elem: A*) extends Seq[A] { * * @return true, iff there is no element in the queue. */ - def isEmpty: Boolean = in.isEmpty && out.isEmpty + override def isEmpty: Boolean = in.isEmpty && out.isEmpty /** Returns the length of the queue. */ diff --git a/src/library/scala/collection/immutable/Stack.scala b/src/library/scala/collection/immutable/Stack.scala index c2305e156a..cb53a74d2e 100644 --- a/src/library/scala/collection/immutable/Stack.scala +++ b/src/library/scala/collection/immutable/Stack.scala @@ -31,7 +31,7 @@ class Stack[+A] extends Seq[A] { * * @return true, iff there is no element on the stack. */ - def isEmpty: Boolean = true + override def isEmpty: Boolean = true /** Returns the size of this stack. * diff --git a/src/library/scala/collection/mutable/PriorityQueue.scala b/src/library/scala/collection/mutable/PriorityQueue.scala index 6bf8791c25..caa7033e8d 100644 --- a/src/library/scala/collection/mutable/PriorityQueue.scala +++ b/src/library/scala/collection/mutable/PriorityQueue.scala @@ -54,7 +54,7 @@ class PriorityQueue[A <% Ordered[A]] extends ResizableArray[A] { * * @return true, iff there is no element in the queue. */ - def isEmpty: Boolean = size < 2; + override def isEmpty: Boolean = size < 2; /** Inserts a single element into the priority queue. * diff --git a/src/library/scala/collection/mutable/Queue.scala b/src/library/scala/collection/mutable/Queue.scala index a7a633dc4b..3434041344 100644 --- a/src/library/scala/collection/mutable/Queue.scala +++ b/src/library/scala/collection/mutable/Queue.scala @@ -25,7 +25,7 @@ class Queue[A] extends MutableList[A] { * * @return true, iff there is no element in the queue. */ - def isEmpty: Boolean = (first == null); + override def isEmpty: Boolean = (first == null); /** Inserts a single element at the end of the queue. * diff --git a/src/library/scala/collection/mutable/Stack.scala b/src/library/scala/collection/mutable/Stack.scala index 90806e0ba3..99e425bda4 100644 --- a/src/library/scala/collection/mutable/Stack.scala +++ b/src/library/scala/collection/mutable/Stack.scala @@ -24,7 +24,7 @@ class Stack[A] extends MutableList[A] { * * @return true, iff there is no element on the stack */ - def isEmpty: Boolean = (first == null); + override def isEmpty: Boolean = (first == null); /** Pushes a single element on top of the stack. * diff --git a/src/library/scala/xml/NodeBuffer.scala b/src/library/scala/xml/NodeBuffer.scala index 98ac60f77f..a4128e0421 100644 --- a/src/library/scala/xml/NodeBuffer.scala +++ b/src/library/scala/xml/NodeBuffer.scala @@ -42,10 +42,11 @@ class NodeBuffer extends scala.collection.mutable.ArrayBuffer[Node] { val it = ns.elements; while(it.hasNext) { this &+ it.next; - if (it.hasNext) - this &+ " "; + //if (it.hasNext) + // this &+ " "; } - case _ => super.+(Text(o.toString())); + //case s:String => super.+(Text(o.toString())); + case d => super.+(new Atom(d)); } this } diff --git a/src/library/scala/xml/Utility.scala b/src/library/scala/xml/Utility.scala index 4bdb480483..ba34954362 100644 --- a/src/library/scala/xml/Utility.scala +++ b/src/library/scala/xml/Utility.scala @@ -118,15 +118,30 @@ object Utility extends AnyRef with parsing.TokenTests { } x.scope.toString(sb, pscope) sb.append('>') - for (val c <- x.child) { - toXML(c, x.scope, sb, stripComment) - } + sequenceToXML(x.child, pscope, sb, stripComment) sb.append("</") x.nameToString(sb) sb.append('>') } } + def sequenceToXML(children: Seq[Node], pscope: NamespaceBinding, sb: StringBuilder, stripComment: Boolean): Unit = { + if(children.isEmpty) + return + else if(children exists { y => y.isInstanceOf[Atom[Any]] }) { + val it = children.elements + val f = it.next + toXML(f, f.scope, sb, stripComment) + while(it.hasNext) { + val x = it.next + sb.append(' ') + toXML(x, x.scope, sb, stripComment) + } + } else for (val c <- children) { + toXML(c, c.scope, sb, stripComment) + } + } + /** returns prefix of qualified name if any */ final def prefix(name: String): Option[String] = { @@ -316,7 +331,7 @@ object Utility extends AnyRef with parsing.TokenTests { } nextch(); } - new String(Array(i.asInstanceOf[char])) + String.valueOf(i.asInstanceOf[char]) } } |