scala.collection.mutable

trait SetLike

[source: scala/collection/mutable/SetLike.scala]

trait SetLike[A, +This <: SetLike[A, This] with Set[A]]
extends SetLike[A, This] with Scriptable[A] with Builder[A, This] with Shrinkable[A] with Cloneable[Set[A]]

A generic template for mutable sets of elements of type A. To implement a concrete mutable set, you need to provide implementations of the following methods:

    def contains(elem: A): Boolean
    def iterator: Iterator[A]
    def += (elem: A): this.type
    def -= (elem: A): this.type

If you wish that methods like, take, drop, filter return the same kind of map, you should also override:

    def empty: This

It is also good idea to override methods foreach and size for efficiency.

Since
2.8
Direct Known Subclasses:
JavaConversions.JSetWrapper, BitSet, HashSet, LinkedHashSet, Set

Method Summary
override def + (elem1 : A, elem2 : A, elems : A*) : This
Adds two or more elements to this collection and returns the collection itself.
override def + (elem : A) : This
Adds a single element to this collection and returns the collection itself.
override def ++ (iter : Traversable[A]) : This
Adds a number of elements provided by a traversable object and returns either the collection itself.
override def ++ (iter : Iterator[A]) : This
Adds a number of elements provided by an iterator and returns the collection itself.
abstract def += (elem : A) : SetLike[A, This]
Adds a new element to the set.
override def - (elem1 : A, elem2 : A, elems : A*) : This
Removes two or more elements from this collection and returns the collection itself.
override def - (elem : A) : This
Removes a single element from this collection and returns the collection itself.
override def -- (iter : Iterator[A]) : This
Removes a number of elements provided by an iterator and returns the collection itself.
override def -- (iter : Traversable[A]) : This
Removes a number of elements provided by a Traversable object and returns the collection itself.
abstract def -= (elem : A) : SetLike[A, This]
Removes a single element from a set.
def << (cmd : Message[A]) : Unit
Send a message to this scriptable object.
def add (elem : A) : Boolean
Adds a new element to the set.
def clear : Unit
Removes all elements from the set. After this operation is completed, the set will be empty.
override def clone : Set[A]
This method creates and returns a copy of the receiver object.
protected[this] override def newBuilder : Builder[A, This]
A common implementation of newBuilder for all mutable sets in terms of empty. Overrides SetLike implementation for better efficiency.
def remove (elem : A) : Boolean
Removes a single element from a set.
def result : This
Returns collection resulting from this builder. The buffer's contents are undefined afterwards.
def retain (p : (A) => Boolean) : Unit
Removes all elements from the set for which the predicate p yields the value false.
def update (elem : A, included : Boolean) : Unit
This method allows one to add or remove an element elem from this set depending on the value of parameter included. Typically, one would use the following syntax:
set(elem) = true
Methods inherited from Shrinkable
-=, --=, --=
Methods inherited from Builder
sizeHint, mapResult
Methods inherited from Growable
+=, ++=, ++=
Methods inherited from SetLike
empty (abstract), contains (abstract), isEmpty, apply, intersect, &, **, union, |, diff, &~, subsetOf, stringPrefix, toString, hashCode, equals
Methods inherited from IterableLike
iterator (abstract), thisCollection, toCollection, elements, foreach, forall, exists, find, foldRight, reduceRight, toIterable, head, take, slice, takeWhile, takeRight, dropRight, copyToArray, zip, zipAll, zipWithIndex, sameElements, toStream, canEqual, view, view, first, firstOption, projection
Methods inherited from TraversableLike
repr, nonEmpty, size, hasDefiniteSize, ++, ++, map, flatMap, filter, filterNot, partialMap, remove, partition, groupBy, count, foldLeft, /:, :\, reduceLeft, reduceLeftOption, reduceRightOption, sum, product, min, max, headOption, tail, last, lastOption, init, drop, dropWhile, span, splitAt, copyToBuffer, copyToArray, toArray, toList, toSeq, toIndexedSeq, toSet, mkString, mkString, mkString, addString, addString, addString, withFilter
Methods inherited from AnyRef
getClass, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Method Details
protected[this] override def newBuilder : Builder[A, This]
A common implementation of newBuilder for all mutable sets in terms of empty. Overrides SetLike implementation for better efficiency.
Overrides
SetLike.newBuilder

def add(elem : A) : Boolean
Adds a new element to the set.
Parameters
elem - the element to be added
Returns
true if the element was not yet present in the set.

def remove(elem : A) : Boolean
Removes a single element from a set.
Parameters
elem - The element to be removed.
Returns
true if the element was already present in the set.

def update(elem : A, included : Boolean) : Unit
This method allows one to add or remove an element elem from this set depending on the value of parameter included. Typically, one would use the following syntax:
set(elem) = true

abstract def +=(elem : A) : SetLike[A, This]
Adds a new element to the set.
Parameters
elem - the element to be added
Overrides
Builder.+=

abstract def -=(elem : A) : SetLike[A, This]
Removes a single element from a set.
Parameters
elem - The element to be removed.
Overrides
Shrinkable.-=

def retain(p : (A) => Boolean) : Unit
Removes all elements from the set for which the predicate p yields the value false.

def clear : Unit
Removes all elements from the set. After this operation is completed, the set will be empty.
Overrides
Builder.clear

override def clone : Set[A]
This method creates and returns a copy of the receiver object.

The default implementation of the clone method is platform dependent.

Returns
a copy of the receiver object.

Overrides
Cloneable.clone

def result : This
Returns collection resulting from this builder. The buffer's contents are undefined afterwards.
Overrides
Builder.result

@deprecated("Use += instead if you intend to add by side effect to an existing collection.\012".+("Use `clone() +=' if you intend to create a new collection."))

override def +(elem : A) : This
Adds a single element to this collection and returns the collection itself.
Parameters
elem - the element to add.
Overrides
SetLike.+

@deprecated("Use += instead if you intend to add by side effect to an existing collection.\012".+("Use `clone() +=' if you intend to create a new collection."))

override def +(elem1 : A, elem2 : A, elems : A*) : This
Adds two or more elements to this collection and returns the collection itself.
Parameters
elem1 - the first element to add.
elem2 - the second element to add.
elems - the remaining elements to add.

@deprecated("Use ++= instead if you intend to add by side effect to an existing collection.\012".+("Use `clone() ++=' if you intend to create a new collection."))

override def ++(iter : Traversable[A]) : This
Adds a number of elements provided by a traversable object and returns either the collection itself.
Parameters
iter - the iterable object.

@deprecated("Use ++= instead if you intend to add by side effect to an existing collection.\012".+("Use `clone() ++=' if you intend to create a new collection."))

override def ++(iter : Iterator[A]) : This
Adds a number of elements provided by an iterator and returns the collection itself.
Parameters
iter - the iterator

@deprecated("Use -= instead if you intend to remove by side effect from an existing collection.\012".+("Use `clone() -=' if you intend to create a new collection."))

override def -(elem : A) : This
Removes a single element from this collection and returns the collection itself.
Parameters
elem - the element to remove.
Overrides
SetLike.-

@deprecated("Use -= instead if you intend to remove by side effect from an existing collection.\012".+("Use `clone() -=' if you intend to create a new collection."))

override def -(elem1 : A, elem2 : A, elems : A*) : This
Removes two or more elements from this collection and returns the collection itself.
Parameters
elem1 - the first element to remove.
elem2 - the second element to remove.
elems - the remaining elements to remove.

@deprecated("Use --= instead if you intend to remove by side effect from an existing collection.\012".+("Use `clone() --=' if you intend to create a new collection."))

override def --(iter : Traversable[A]) : This
Removes a number of elements provided by a Traversable object and returns the collection itself.
Parameters
iter - the Traversable object.

@deprecated("Use --= instead if you intend to remove by side effect from an existing collection.\012".+("Use `clone() --=' if you intend to create a new collection."))

override def --(iter : Iterator[A]) : This
Removes a number of elements provided by an iterator and returns the collection itself.
Parameters
iter - the iterator

def <<(cmd : Message[A]) : Unit
Send a message to this scriptable object.
Parameters
cmd - the message to send.
Throws
<code>Predef.UnsupportedOperationException</code> - if the message was not understood.
Overrides
Scriptable.<<