Initializer
SingletonSet(Element element)
Attributes
elementSource Codeshared Element element
hashSource Codeshared actual Integer hash

The hash value of the value, which allows the value to be an element of a hash-based set or key of a hash-based map. Implementations must respect the constraint that:

  • if x==y then x.hash==y.hash.

Therefore, a class which refines equals must also refine hash.

In general, hash values vary between platforms and between executions of the same program.

Note that when executing on a Java Virtual Machine, the 64-bit Integer value returned by an implementation of hash is truncated to a 32-bit integer value by taking the exclusive disjunction of the 32 lowest-order bits with the 32 highest-order bits, before returning the value to the caller.

Refines Set.hash ultimately refines Object.hash
Inherited Attributes
Attributes inherited from: Object
Attributes inherited from: Collection<Element>
Attributes inherited from: Iterable<Element,Absent>
Attributes inherited from: Set<Element>
Methods
cloneSource Codeshared actual SingletonSet<Element> clone()

A shallow copy of this collection, that is, a collection with identical elements which does not change if this collection changes. If this collection is immutable, it is acceptable to return a reference to this collection. If this collection is mutable, a newly instantiated collection must be returned.

Refines Set.clone ultimately refines Collection.clone
complementSource Codeshared actual Set<Element> complement<Other>(Set<Other> set)
given Other satisfies Object

Returns a new Set containing all the elements in this set that are not contained in the given Set.

For example:

set { "hello", "world" } ~ set { 1, 2, "hello" }

Produces the set { "world" } of type Set<String>.

containsSource Codeshared actual Boolean contains(Object element)

Returns true if the given value belongs to this Category, that is, if it is an element of this Category, or false otherwise.

For any instance c of Category, c.contains(element) may be written using the in operator:

element in c

For most Categorys, the following relationship is satisfied by every pair of elements x and y:

  • if x==y, then x in category == y in category

However, it is possible to form a useful Category consistent with some other equivalence relation, for example ===. Therefore implementations of contains() which do not satisfy this relationship are tolerated.

Refines Set.contains ultimately refines Category.contains
eachSource Codeshared actual void each(void step(Element element))

Call the given function (step) for each element of this stream, passing the elements in the order they occur in this stream.

For example:

words.each((word) {
    print(word.lowercased);
    print(word.uppercased);
});

Has the same effect as the following for loop:

for (word in words) {
    print(word.lowercased);
    print(word.uppercased);
}

For certain streams this method is highly efficient, surpassing the performance of for loops on the JVM. Thus, each() is sometimes preferred in highly performance-critical low-level code.

equalsSource Codeshared actual Boolean equals(Object that)

Determine if two values are equal.

For any two non-null objects x and y, x.equals(y) may be written as:

x == y 

Implementations should respect the constraints that:

  • if x===y then x==y (reflexivity),
  • if x==y then y==x (symmetry),
  • if x==y and y==z then x==z (transitivity).

Furthermore it is recommended that implementations ensure that if x==y then x and y have the same concrete class.

A class which explicitly refines equals() is said to support value equality, and the equality operator == is considered much more meaningful for such classes than for a class which simply inherits the default implementation of identity equality from Identifiable.

Note that an implementation of equals() that always returns false does satisfy the constraints given above, as long as the class does not inherit Identifiable. Therefore, in very rare cases where there is no reasonable definition of value equality for a class, for example, function references (Callable), it is acceptable for equals() to be defined to return false for every argument.

Refines Set.equals ultimately refines Object.equals
exclusiveUnionSource Codeshared actual Set<Element|Other> exclusiveUnion<Other>(Set<Other> set)
given Other satisfies Object

Returns a new Set containing only the elements contained in either this set or the given Set, but no element contained in both sets.

intersectionSource Codeshared actual Set<Element&Other> intersection<Other>(Set<Other> set)
given Other satisfies Object

Returns a new Set containing only the elements that are present in both this set and the given Set and that are instances of the intersection Element&Other of the element types of the two sets.

For example:

set { "hello", "world" } & set { 1, 2, "hello" }

Produces the set { "hello" } of type Set<String>.

Note that, according to this definition, and even though 1==1.0 evaluates to true (Integer.equals), the expression

set { 1 } & set { 1.0 }

produces the empty set {}.

iteratorSource Codeshared actual Iterator<Element> iterator()

An iterator for the elements belonging to this stream.

If this is a nonempty stream with type {Element+}, the iterator must produce at least one element.

unionSource Codeshared actual Set<Element|Other> union<Other>(Set<Other> set)
given Other satisfies Object

Returns a new Set containing all the elements of this set and all the elements of the given Set.

For example:

set { "hello", "world" } | set { 1, 2, "hello" }

Produces the set { "hello", "world", 1, 2 } of type Set<String|Integer>.

Note that it is possible for two sets of disjoint element type to be considered to have elements in common. For example, since 1==1.0 evaluates to true (Integer.equals), the expression

set { 1 } | set { 1.0 }

produces the set { 1 }.

Refines Set.union
Inherited Methods
Methods inherited from: Object
Methods inherited from: Category<Element>
Methods inherited from: Collection<Element>
Methods inherited from: Iterable<Element,Absent>
Methods inherited from: Set<Element>