scala.collection.generic

trait SetTemplate

[source: scala/collection/generic/SetTemplate.scala]

trait SetTemplate[A, +This <: SetTemplate[A, This] with Set[A]]
extends IterableTemplate[A, This] with Addable[A, This] with Subtractable[A, This]

A generic template for sets of type A.
To implement a concrete set, you need to provide implementations of the following methods (where This is the type of the set in question):

    def contains(key: A): Boolean
    def iterator: Iterator[A]
    def +(elem: A): This
    def -(elem: A): This

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

   def empty: This

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

Author
Martin Odersky
Version
2.8
Direct Known Subclasses:
Enumeration.ValueSet, Set, BitSetTemplate, MutableSetTemplate, SetProxyTemplate, SortedSetTemplate, HashSet, ListSet, Set

Method Summary
def & (that : Set[A]) : This
Returns a new set consisting of all elements that are both in the current set and in the argument set.
def &~ (that : Set[A]) : This
The difference of this set and the given set that.
def ** (that : Set[A]) : This
This method is an alias for intersect. It computes an intersection with set that. It removes all the elements that are not present in that.
abstract def + (elem : A) : This
Creates a new set with an additional element, unless the element is already present.
abstract def - (elem : A) : This
Creates a new set with given element removed from this set, unless the element is not present.
def apply (elem : A) : Boolean
This method allows sets to be interpreted as predicates. It returns true, iff this set contains element elem.
abstract def contains (elem : A) : Boolean
Checks if this set contains element elem.
def diff (that : Set[A]) : This
The difference of this set and the given set that.
abstract def empty : This
override def equals (that : Any) : Boolean
Compares this set with another object and returns true, iff the other object is also a set which contains the same elements as this set.
def intersect (that : Set[A]) : This
Returns a new set consisting of all elements that are both in the current set and in the argument set.
override def isEmpty : Boolean
Checks if this set is empty.
protected[this] override def newBuilder : Builder[A, This]
A common implementation of newBuilder for all sets in terms of empty. Overridden for mutable sets in MutableSetTemplate.
override def stringPrefix : java.lang.String
Defines the prefix of this object's toString representation.
def subsetOf (that : Set[A]) : Boolean
Checks if this set is a subset of set that.
override def toString : java.lang.String
Need to override string, so that it's not the Function1's string that gets mixed in.
def union (that : Set[A]) : This
The union of this set and the given set that.
def | (that : Set[A]) : This
The union of this set and the given set that.
Methods inherited from Subtractable
-, --, --
Methods inherited from Addable
+, ++, ++
Methods inherited from IterableTemplate
iterator (abstract), elements, foreach, foldRight, reduceRight, toIterable, head, takeRight, dropRight, sameElements, toStream, view, view, first, firstOption, toSeq, projection
Methods inherited from TraversableTemplate
thisCollection, nonEmpty, size, hasDefiniteSize, ++, ++, map, flatMap, filter, filterMap, filterNot, remove, partition, groupBy, forall, exists, count, find, foldLeft, /:, :\, reduceLeft, reduceLeftOption, reduceRightOption, headOption, tail, last, lastOption, init, take, drop, slice, takeWhile, dropWhile, span, splitAt, copyToBuffer, copyToArray, copyToArray, toArray, toList, toSequence, toSet, mkString, mkString, mkString, addString, addString, addString
Methods inherited from AnyRef
getClass, hashCode, clone, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Method Details
abstract def empty : This

protected[this] override def newBuilder : Builder[A, This]
A common implementation of newBuilder for all sets in terms of empty. Overridden for mutable sets in MutableSetTemplate.

abstract def contains(elem : A) : Boolean
Checks if this set contains element elem.
Parameters
elem - the element to check for membership.
Returns
true iff elem is contained in this set.

abstract def +(elem : A) : This
Creates a new set with an additional element, unless the element is already present.
Parameters
elem - the element to be added
Overrides
Addable.+

abstract def -(elem : A) : This
Creates a new set with given element removed from this set, unless the element is not present.
Parameters
elem - the element to be removed
Overrides
Subtractable.-

override def isEmpty : Boolean
Checks if this set is empty.
Returns
true iff there is no element in the set.
Overrides
IterableTemplate.isEmpty

def apply(elem : A) : Boolean
This method allows sets to be interpreted as predicates. It returns true, iff this set contains element elem.
Parameters
elem - the element to check for membership.
Returns
true iff elem is contained in this set.

def intersect(that : Set[A]) : This
Returns a new set consisting of all elements that are both in the current set and in the argument set.
Parameters
that - the set to intersect with.

def &(that : Set[A]) : This
Returns a new set consisting of all elements that are both in the current set and in the argument set.
Parameters
that - the set to intersect with.
Notes
same as intersect.

@deprecated("use & instead")

def **(that : Set[A]) : This
This method is an alias for intersect. It computes an intersection with set that. It removes all the elements that are not present in that.
Parameters
that - the set to intersect with

def union(that : Set[A]) : This
The union of this set and the given set that.
Parameters
that - the set of elements to add
Returns
a set containing the elements of this set and those of the given set that.

def |(that : Set[A]) : This
The union of this set and the given set that.
Parameters
that - the set of elements to add
Returns
a set containing the elements of this set and those of the given set that.
Notes
same as union.

def diff(that : Set[A]) : This
The difference of this set and the given set that.
Parameters
that - the set of elements to remove
Returns
a set containing those elements of this set that are not also contained in the given set that.

def &~(that : Set[A]) : This
The difference of this set and the given set that.
Parameters
that - the set of elements to remove
Returns
a set containing those elements of this set that are not also contained in the given set that.
Notes
same as diff.

def subsetOf(that : Set[A]) : Boolean
Checks if this set is a subset of set that.
Parameters
that - another set.
Returns
true iff the other set is a superset of this set. todo: rename to isSubsetOf

override def equals(that : Any) : Boolean
Compares this set with another object and returns true, iff the other object is also a set which contains the same elements as this set.
Parameters
that - the other object
Notes
not necessarily run-time type safe.
Returns
true iff this set and the other set contain the same elements.

override def stringPrefix : java.lang.String
Defines the prefix of this object's toString representation.

override def toString : java.lang.String
Need to override string, so that it's not the Function1's string that gets mixed in.