summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/mutable/ListBuffer.scala
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2006-10-20 12:32:22 +0000
committermichelou <michelou@epfl.ch>2006-10-20 12:32:22 +0000
commitd1053b01cde71a47dec8038a2bd0d94ba5482819 (patch)
tree87d149aaa52757a8e5a82ddc93949b9f00ce968b /src/library/scala/collection/mutable/ListBuffer.scala
parentf44bc6e0664c93d80673043bbf31ce436f872c94 (diff)
downloadscala-d1053b01cde71a47dec8038a2bd0d94ba5482819.tar.gz
scala-d1053b01cde71a47dec8038a2bd0d94ba5482819.tar.bz2
scala-d1053b01cde71a47dec8038a2bd0d94ba5482819.zip
added FJBG classes to doc/script.js
Diffstat (limited to 'src/library/scala/collection/mutable/ListBuffer.scala')
-rw-r--r--src/library/scala/collection/mutable/ListBuffer.scala84
1 files changed, 56 insertions, 28 deletions
diff --git a/src/library/scala/collection/mutable/ListBuffer.scala b/src/library/scala/collection/mutable/ListBuffer.scala
index 5df2be342a..1f4a975288 100644
--- a/src/library/scala/collection/mutable/ListBuffer.scala
+++ b/src/library/scala/collection/mutable/ListBuffer.scala
@@ -14,16 +14,20 @@ package scala.collection.mutable
import Predef._
-/**
+/** The class <code>ListBuffer</code> ..
+ *
+ * @author Matthias Zenger
+ * @version 1.0, 15/03/2004
*/
final class ListBuffer[A] extends Buffer[A] {
private var start: List[A] = Nil
private var last: ::[A] = _
private var exported: boolean = false
- /** Prepend a single element to this buffer.
+ /** Prepends a single element to this buffer.
*
* @param x the element to prepend.
+ * @return this buffer.
*/
def +: (x: A): Buffer[A] = {
if (exported) copy()
@@ -33,7 +37,7 @@ final class ListBuffer[A] extends Buffer[A] {
this
}
- /** Append a single element to this buffer.
+ /** Appends a single element to this buffer.
*
* @param x the element to append.
*/
@@ -49,10 +53,11 @@ final class ListBuffer[A] extends Buffer[A] {
}
}
- /** Remove a single element from the buffer and return
- * the identity of the buffer. Same as ``this -= x; this''
+ /** Removes a single element from the buffer and return
+ * the identity of the buffer. Same as <code>this -= x; this</code>
*
* @param x the element to remove.
+ * @return this buffer.
*/
def - (x: A): Buffer[A] = { this -= x; this }
@@ -71,7 +76,7 @@ final class ListBuffer[A] extends Buffer[A] {
val z = cursor.asInstanceOf[scala.::[A]]
if(z.tl == last)
last = z
- z.tl = cursor.tail.tail
+ z.tl = cursor.tail.tail
}
}
}
@@ -110,23 +115,31 @@ final class ListBuffer[A] extends Buffer[A] {
}
/** Returns the length of this buffer.
+ *
+ * @return the length of this buffer.
*/
def length: int = start.length
- /** Returns the <code>n</code>th element of this list. This method
+ /** Returns the n-th element of this list. This method
* yields an error if the element does not exist.
+ *
+ * @param n the position of the element to be returned.
+ * @return the n-th element of this buffer.
+ * @throws IndexOutOfBoundsException
*/
def apply(n: Int): A = try {
start(n)
} catch {
- case ex: Exception => throw new IndexOutOfBoundsException(n.toString())
+ case ex: Exception =>
+ throw new IndexOutOfBoundsException(n.toString())
}
- /** Replace element at index <code>n</code> with the new element
+ /** Replaces element at index <code>n</code> with the new element
* <code>newelem</code>. Throws IndexOutOfBoundsException if
* n is out of bounds.
- * @param n the index of the element to replace.
- * @param x the new element.
+ *
+ * @param n the index of the element to replace.
+ * @param x the new element.
*/
def update(n: Int, x: A): unit = try {
if (exported) copy()
@@ -152,16 +165,17 @@ final class ListBuffer[A] extends Buffer[A] {
/** Inserts new elements at the index <code>n</code>. Opposed to method
* <code>update</code>, this method will not replace an element with a new
* one. Instead, it will insert a new element at index <code>n</code>.
- * Throws IndexOutOfBoundsException if n is out of bounds.
- * @param n the index where a new element will be inserted.
- * @param iter the iterable object providing all elements to insert.
+ *
+ * @param n the index where a new element will be inserted.
+ * @param iter the iterable object providing all elements to insert.
+ * @throws IndexOutOfBoundsException if <code>n</code> is out of bounds.
*/
def insertAll(n: Int, iter: Iterable[A]): unit = try {
if (exported) copy()
var elems = iter.elements.toList.reverse
if (n == 0) {
while (!elems.isEmpty) {
- val newElem = new scala.:: (elems.head, start);
+ val newElem = new scala.:: (elems.head, start)
if (start.isEmpty) last = newElem
start = newElem
elems = elems.tail
@@ -174,22 +188,24 @@ final class ListBuffer[A] extends Buffer[A] {
i = i + 1
}
while (!elems.isEmpty) {
- val newElem = new scala.:: (elems.head, cursor.tail);
+ val newElem = new scala.:: (elems.head, cursor.tail)
if (cursor.tail.isEmpty) last = newElem
cursor.asInstanceOf[scala.::[A]].tl = newElem
elems = elems.tail
}
}
} catch {
- case ex: Exception => throw new IndexOutOfBoundsException(n.toString())
+ case ex: Exception =>
+ throw new IndexOutOfBoundsException(n.toString())
}
/** Removes the element on a given index position.
*
- * @param n the index which refers to the element to delete.
- * @return n the element that was formerly at posiition `n'
- * @pre an element exists at position `n'
+ * @param n the index which refers to the element to delete.
+ * @return n the element that was formerly at position <code>n</code>.
+ * @pre an element exists at position <code>n</code>
+ * @throws IndexOutOfBoundsException if <code>n</code> is out of bounds.
*/
def remove(n: Int): A = try {
if (exported) copy()
@@ -209,13 +225,21 @@ final class ListBuffer[A] extends Buffer[A] {
}
old
} catch {
- case ex: Exception => throw new IndexOutOfBoundsException(n.toString())
+ case ex: Exception =>
+ throw new IndexOutOfBoundsException(n.toString())
}
- /** Returns an iterator over all elements of this list.
- * Note: the iterator can be affected by insertions, updates and deletions
- * that are performed afterwards on the buffer. To get iterator an over the current
- * buffer snapshot, use toList.elements
+ /** <p>
+ * Returns an iterator over all elements of this list.
+ * </p>
+ * <blockquote>
+ * Note: the iterator can be affected by insertions, updates and
+ * deletions that are performed afterwards on the buffer. To get
+ * iterator an over the current buffer snapshot, use
+ * <code>toList.elements</code>.
+ * </blockquote>
+ *
+ * @throws NoSuchElementException if buffer is empty
*/
override def elements = new Iterator[A] {
var cursor: List[A] = null
@@ -229,7 +253,7 @@ final class ListBuffer[A] extends Buffer[A] {
}
}
- /** Return a clone of this buffer.
+ /** Returns a clone of this buffer.
*
* @return a <code>ListBuffer</code> with the same elements.
*/
@@ -237,7 +261,8 @@ final class ListBuffer[A] extends Buffer[A] {
/** Checks if two buffers are structurally identical.
*
- * @return true, iff both buffers contain the same sequence of elements.
+ * @return <code>true</code>, iff both buffers contain the same sequence
+ * of elements.
*/
override def equals(obj: Any): Boolean = obj match {
case that: ListBuffer[A] =>
@@ -245,10 +270,13 @@ final class ListBuffer[A] extends Buffer[A] {
elements.zip(that.elements).forall {
case Pair(thiselem, thatelem) => thiselem == thatelem
})
- case _ => false
+ case _ =>
+ false
}
/** Defines the prefix of the string representation.
+ *
+ * @return the string representation of this buffer.
*/
override protected def stringPrefix: String = "ListBuffer"
}