scala.collection.mutable.Buffer

trait Buffer

trait Buffer[A]

 extends Seq[A] with Scriptable[Message[(Location, A)]] with CloneableCollection


Buffers are used to create sequences of elements incrementally by appending, prepending, or inserting new elements. It is also possible to access and modify elements in a random access fashion via the index of the element in the current sequence.
author
- Matthias Zenger
version
- 1.1, 02/03/2004


Source: Buffer.scala(26)

Direct Known Subclasses

RichStringBuilder, ListBuffer, SynchronizedBuffer, BufferProxy, ObservableBuffer, ArrayBuffer,

 Fields

elements abstract def elements
Creates a new iterator over all elements contained in this object [details]
return
- the new iterator
Iterator[A] Iterable
first def first
Returns the first element of this list [details]
return
- the first element of the list.
throws
Predef.UnsupportedOperationException - if the list is empty.
A Seq
firstOption def firstOption
Returns as an option the first element of this list or None if list is empty [details]
return
- the first element as an option.
Option[A] Seq
hasDefiniteSize def hasDefiniteSize
returns true iff this collection has a bound size [details]
Many APIs in this trait will not work on collections of unbound sizes.
Boolean Iterable
headOption def headOption Option[A] Seq
isEmpty override def isEmpty
Returns true if length == 0
Boolean Seq
last def last
Returns the last element of this list [details]
return
- the last element of the list.
throws
Predef.UnsupportedOperationException - if the list is empty.
A Seq
lastOption def lastOption
Returns as an option the last element of this list or None if list is empty [details]
return
- the last element as an option.
Option[A] Seq
length abstract def length
Returns the length of the sequence [details]
return
- the sequence length.
Int Seq
mkString def mkString
Converts a collection into a flat String by each element's toString method [details]
note
- Will not terminate for infinite-sized collections.
String Iterable
projection override def projection
returns a projection that can be used to call non-strict filter, map, and flatMap methods that build projections of the collection
Projection[A] Seq
readOnly abstract def readOnly
return a read only alias of this buffer
Seq[A]
reverse def reverse
A sequence consisting of all elements of this sequence in reverse order
Seq[A] Seq
size def size
should always be length
Int Seq
stringPrefix protected override def stringPrefix
Defines the prefix of the string representation
String
toList def toList
Returns a list containing all of the elements in this iterable object [details]
note
- Will not terminate for infinite-sized collections.
List[A] Iterable
toSeq override def toSeq
Overridden for efficiency [details]
return
- the sequence itself
Seq[A] Seq
toStream def toStream
Returns a stream containing all of the elements in this iterable object [details]
note
- consider using projection for lazy behavior.
Stream[A] Iterable

 Methods

!= final def !=(arg0 : Any) Boolean Any
!= final def !=(arg0 : Object) Boolean AnyRef
+ def +(elem : A)
Append a single element to this buffer and return the identity of the buffer [details]
param
elem - the element to append.
Buffer[A]
++ override def ++[B >: A](that : Iterable[B])
Appends two iterable objects
Seq[B]
++ def ++(iter : Iterable[A])
Appends a number of elements provided by an iterable object via its elements method [details]
The identity of the buffer is returned.
param
iter - the iterable object.
return
- the updated buffer.
Buffer[A]
++ def ++(iter : Iterator[A])
Appends a number of elements provided by an iterator via its elements method [details]
The identity of the buffer is returned.
param
iter - the iterator
return
- the updated buffer.
Buffer[A]
++: def ++:(iter : Iterable[A])
Prepends a number of elements provided by an iterable object via its elements method [details]
The identity of the buffer is returned.
param
iter - the iterable object.
Buffer[A]
++= def ++=(iter : Iterator[A])
Appends a number of elements provided by an iterator [details]
param
iter - the iterator.
Unit
++= def ++=(src : Array[A], start : Int, len : Int)
Appends a number of elements in an array [details]
param
start - the first element to append
len - the number of elements to append
src - the array
Unit
++= def ++=(iter : Iterable[A])
Appends a number of elements provided by an iterable object via its elements method [details]
param
iter - the iterable object.
Unit
+: abstract def +:(elem : A)
Prepend a single element to this buffer and return the identity of the buffer [details]
param
elem - the element to append.
Buffer[A]
+= abstract def +=(elem : A)
Append a single element to this buffer [details]
param
elem - the element to append.
Unit
-= def -=(x : A)
Removes a single element from this buffer, at its first occurrence [details]
If the list does not contain that element, it is unchanged
param
x - the element to remove.
Unit
/: def /:[B](z : B)(op : (B, A) => B)
Similar to foldLeft but can be used as an operator with the order of list and zero arguments reversed [details]
That is, z /: xs is the same as xs foldLeft z
note
- Will not terminate for infinite-sized collections.
B Iterable
:\ def :\[B](z : B)(op : (A, B) => B)
An alias for foldRight [details]
That is, xs :\ z is the same as xs foldRight z
note
- Will not terminate for infinite-sized collections.
B Iterable
<< def <<(cmd : Message[(Location, A)])
Send a message to this scriptable object [details]
param
cmd - the message to send.
Unit
== final def ==(arg0 : Object) Boolean AnyRef
== final def ==(arg0 : Any) Boolean Any
addString def addString(buf : StringBuilder, sep : String) StringBuilder Iterable
addString def addString(buf : StringBuilder, start : String, sep : String, end : String)
Write all elements of this string into given string builder [details]
note
- Will not terminate for infinite-sized collections.
param
buf - ...
return
- ...
StringBuilder Iterable
andThen override def andThen[C](k : (B) => C)
(f andThen g)(x) == g(f(x))
PartialFunction[A, C] PartialFunction
append def append(elems : A*)
Appends a sequence of elements to this buffer [details]
param
elems - the elements to append.
Unit
appendAll def appendAll(iter : Iterable[A])
Appends a number of elements provided by an iterable object via its elements method [details]
param
iter - the iterable object.
Unit
apply abstract def apply(v1 : T1) R Function1
asInstanceOf final def asInstanceOf[T0] T0 Any
clear abstract def clear
Clears the buffer contents
Unit
clone override def clone
Return a clone of this buffer [details]
return
- a buffer with the same elements.
Buffer[A]
compose def compose[A](g : (A) => T1)
(f compose g)(x) == f(g(x))
(A) => R Function1
concat override def concat[B >: A](that : Iterable[B])
Appends two iterable objects [details]
deprecated
- use ++ instead
return
- the new iterable object
Seq[B] Seq
contains def contains(elem : Any)
Tests if the given value elem is a member of this sequence [details]
param
elem - element whose membership has to be tested.
return
- true iff there is an element of this sequence which is equal (w.r.t. ==) to elem.
Boolean Seq
containsSlice def containsSlice[B](that : Seq[B])
Is that a slice in this?
Boolean Seq
copyToArray def copyToArray[B >: A](xs : Array[B], start : Int)
Fills the given array xs with the elements of this sequence starting at position start [details]
note
- Will not terminate for infinite-sized collections.
param
xs - the array to fill.
start - starting index.
pre
- the array must be large enough to hold all elements.
Unit Iterable
copyToBuffer def copyToBuffer[B >: A](dest : Buffer[B])
Copy all elements to a given buffer [details]
note
- Will not terminate if not finite.
- Will not terminate for infinite-sized collections.
param
dest - The buffer to which elements are copied
Unit Iterable
drop override def drop(n : Int)
Returns this sequence without its n first elements If this sequence has less than n elements, the empty sequence is returned [details]
(non-strict)
param
n - the number of elements to drop
return
- the new sequence
Seq[A] Seq
dropWhile override def dropWhile(p : (A) => Boolean)
Returns the longest suffix of this sequence whose first element does not satisfy the predicate p [details]
param
p - the test predicate.
return
- the longest suffix of the sequence whose first element does not satisfy the predicate p.
Seq[A] Seq
endsWith def endsWith[B](that : Seq[B])
[details]
return
- true if this sequence end with that sequence
see
- String.endsWith
Boolean Seq
eq final def eq(arg0 : Object) Boolean AnyRef
equals def equals(arg0 : Any) Boolean AnyRef
equalsWith def equalsWith[B](that : Seq[B])(f : (A, B) => Boolean) Boolean Seq
exists def exists(p : (A) => Boolean)
Apply a predicate p to all elements of this iterable object and return true, iff there is at least one element for which p yields true [details]
note
- May not terminate for infinite-sized collections.
param
p - the predicate
return
- true, iff the predicate yields true for at least one element.
Boolean Iterable
filter override def filter(p : (A) => Boolean)
Returns all the elements of this sequence that satisfy the predicate p [details]
The order of the elements is preserved.
param
p - the predicate used to filter the list.
return
- the elements of this list satisfying p.
Seq[A] Seq
finalize protected def finalize Unit AnyRef
find def find(p : (A) => Boolean)
Find and return the first element of the iterable object satisfying a predicate, if any [details]
note
- may not terminate for infinite-sized collections.
param
p - the predicate
return
- the first element in the iterable object satisfying p, or None if none exists.
Option[A] Iterable
findIndexOf def findIndexOf(p : (A) => Boolean)
Returns index of the first element satisying a predicate, or -1 [details]
note
- may not terminate for infinite-sized collections.
param
p - the predicate
return
- the index of the first element satisfying p, or -1 if such an element does not exist
Int Iterable
flatMap override def flatMap[B](f : (A) => Iterable[B])
Applies the given function f to each element of this sequence, then concatenates the results [details]
param
f - the function to apply on each element.
return
- f(a0) ::: ... ::: f(an) if this sequence is a0, ..., an.
Seq[B] Seq
foldLeft def foldLeft[B](z : B)(op : (B, A) => B)
Combines the elements of this iterable object together using the binary function f, from left to right, and starting with the value z [details]
note
- Will not terminate for infinite-sized collections.
return
- f(... (f(f(z, a0), a1) ...), an) if the list is [a0, a1, ..., an].
B Iterable
foldRight def foldRight[B](z : B)(op : (A, B) => B)
Combines the elements of this list together using the binary function f, from right to left, and starting with the value z [details]
note
- Will not terminate for infinite-sized collections.
return
- f(a0, f(a1, f(..., f(an, z)...))) if the list is [a0, a1, ..., an].
B Iterable
forall def forall(p : (A) => Boolean)
Apply a predicate p to all elements of this iterable object and return true, iff the predicate yields true for all elements [details]
note
- May not terminate for infinite-sized collections.
param
p - the predicate
return
- true, iff the predicate yields true for all elements.
Boolean Iterable
foreach def foreach(f : (A) => Unit)
Apply a function f to all elements of this iterable object [details]
note
- Will not terminate for infinite-sized collections.
param
f - a function that is applied to every element.
Unit Iterable
getClass final def getClass Class[Any] AnyRef
hashCode override def hashCode
The hashCode method always yields an error, since it is not safe to use buffers as keys in hash tables [details]
return
- never.
Int
indexOf def indexOf[B >: A](elem : B)
Returns the index of the first occurence of the specified object in this iterable object [details]
note
- may not terminate for infinite-sized collections.
param
elem - element to search for.
return
- the index in this sequence of the first occurence of the specified element, or -1 if the sequence does not contain this element.
Int Iterable
indexOf def indexOf[B >: A](that : Seq[B])
[details]
return
- -1 if that not contained in this, otherwise the index where that is contained
see
- String.indexOf
Int Seq
insert def insert(n : Int, elems : A*)
Inserts new elements at the index n [details]
Opposed to method update, this method will not replace an element with a one. Instead, it will insert the new elements at index n.
param
elems - the new elements to insert.
n - the index where a new element will be inserted.
Unit
insertAll abstract def insertAll(n : Int, iter : Iterable[A])
Inserts new elements at the index n [details]
Opposed to method update, this method will not replace an element with a one. Instead, it will insert a new element at index n.
param
iter - the iterable object providing all elements to insert.
n - the index where a new element will be inserted.
Unit
isDefinedAt def isDefinedAt(x : Int)
Is this partial function defined for the index x? [details]
param
x - ..
return
- true, iff x is a legal sequence index.
Boolean Seq
isInstanceOf final def isInstanceOf[T0] Boolean Any
lastIndexOf def lastIndexOf[B >: A](elem : B)
Returns the index of the last occurence of the specified element in this sequence, or -1 if the sequence does not contain this element [details]
param
elem - element to search for.
return
- the index in this sequence of the last occurence of the specified element, or -1 if the sequence does not contain this element.
Int Seq
lengthCompare def lengthCompare(l : Int)
Returns length - l [details]
This method is used by matching streams against right-ignoring (...,_) patterns. Lazy sequences should override this method if length forces evaluation of the stream.
Int Seq
map override def map[B](f : (A) => B)
Returns the sequence resulting from applying the given function f to each element of this sequence [details]
param
f - function to apply to each element.
return
- f(a0), ..., f(an) if this sequence is a0, ..., an.
Seq[B] Seq
mkString def mkString(sep : String)
Returns a string representation of this iterable object [details]
The string representations of elements (w.r.t. the method toString()) are separated by the string sep.
note
- Will not terminate for infinite-sized collections.
param
sep - separator string.
return
- a string representation of this iterable object.
String Iterable
mkString def mkString(start : String, sep : String, end : String)
Returns a string representation of this iterable object [details]
The resulting string begins with the string start and is finished by the string end. Inside, the string representations of elements (w.r.t. the method toString()) are separated by the string sep.
ex
- List(1, 2, 3).mkString("(", "; ", ")") = "(1; 2; 3)"
note
- Will not terminate for infinite-sized collections.
param
sep - separator string.
start - starting string.
end - ending string.
return
- a string representation of this iterable object.
String Iterable
ne final def ne(arg0 : Object) Boolean AnyRef
notify final def notify Unit AnyRef
notifyAll final def notifyAll Unit AnyRef
orElse def orElse[A1 <: A, B1 >: B](that : PartialFunction[A1, B1]) PartialFunction[A1, B1] PartialFunction
partition def partition(p : (A) => Boolean)
Partitions this iterable in two iterables according to a predicate [details]
param
p - the predicate on which to partition
return
- a pair of iterables: the iterable that satisfy the predicate p and the iterable that do not. The relative order of the elements in the resulting iterables is the same as in the original iterable.
(Iterable[A], Iterable[A]) Iterable
prepend def prepend(elems : A*)
Prepend an element to this list [details]
param
elem - the element to prepend.
Unit
prependAll def prependAll(iter : Iterable[A])
Prepends a number of elements provided by an iterable object via its elements method [details]
The identity of the buffer is returned.
param
iter - the iterable object.
Unit
reduceLeft def reduceLeft[B >: A](op : (B, A) => B)
Combines the elements of this iterable object together using the binary operator op, from left to right [details]
note
- Will not terminate for infinite-sized collections.
param
op - The operator to apply
return
- op(... op(a0,a1), ..., an) if the iterable object has elements a0, a1, ..., an.
throws
Predef.UnsupportedOperationException - if the iterable object is empty.
B Iterable
reduceRight def reduceRight[B >: A](op : (A, B) => B)
Combines the elements of this iterable object together using the binary operator op, from right to left [details]
note
- Will not terminate for infinite-sized collections.
param
op - The operator to apply
return
- a0 op (... op (an-1 op an)...) if the iterable object has elements a0, a1, ..., an.
throws
Predef.UnsupportedOperationException - if the iterator is empty.
B Iterable
remove abstract def remove(n : Int)
Removes the element on a given index position [details]
param
n - the index which refers to the element to delete.
A
sameElements def sameElements[B >: A](that : Iterable[B])
Checks if the other iterable object contains the same elements [details]
note
- will not terminate for infinite-sized collections.
param
that - the other iterable object
return
- true, iff both iterable objects contain the same elements.
Boolean Iterable
slice def slice(from : Int)
A sub-sequence starting at index from and extending up to the length of the current sequence (non-strict) [details]
param
from - The index of the first element of the slice
throws
IndexOutOfBoundsException - if from < 0
Seq[A] Seq
slice def slice(from : Int, until : Int)
A sub-sequence starting at index from and ending (non-inclusive) at index until (non-strict) [details]
param
until - The index of the element following the slice
from - The index of the first element of the slice
throws
IndexOutOfBoundsException - if from < 0 or length < from + len
Seq[A] Seq
startsWith def startsWith[B](that : Seq[B])
[details]
return
- true if this sequence start with that sequences
see
- String.startsWith
Boolean Seq
subseq def subseq(from : Int, end : Int)
Returns a subsequence starting from index from consisting of len elements [details]
deprecated
- use slice instead
Seq[A] Seq
synchronized final def synchronized[T0](arg0 : T0) T0 AnyRef
take override def take(n : Int)
Returns a sequence consisting only over the first n elements of this sequence, or else the whole sequence, if it has less than n elements [details]
(non-strict)
param
n - the number of elements to take
return
- a possibly projected sequence
Seq[A] Seq
takeWhile override def takeWhile(p : (A) => Boolean)
Returns the longest prefix of this sequence whose elements satisfy the predicate p [details]
param
p - the test predicate.
return
- the longest prefix of this sequence whose elements satisfy the predicate p.
Seq[A] Seq
toArray override def toArray[B >: A]
Converts this sequence to a fresh Array with length elements
Array[B] Seq
toString override def toString String Collection
trimEnd def trimEnd(n : Int)
Removes the last n elements [details]
param
n - the number of elements to remove from the end of this buffer.
Unit
trimStart def trimStart(n : Int)
Removes the first n elements [details]
param
n - the number of elements to remove from the beginning of this buffer.
Unit
update abstract def update(n : Int, newelem : A)
Replace element at index n with the new element newelem [details]
param
newelem - the new element.
n - the index of the element to replace.
Unit
wait final def wait(arg0 : Long) Unit AnyRef
wait final def wait Unit AnyRef
wait final def wait(arg0 : Long, arg1 : Int) Unit AnyRef
Copyright (c) 2008. All Rights Reserved.