Class Set
An unordered iterable collection that cannot contain two instances of the same kind of value. It optionally enforces the type of elements that may be added to the Set.
An example usage:
var set = new go.Set("string"); // make a set of strings set.add("orange"); set.add("apple"); set.add("orange"); // now set.count === 2 // and set.contains("orange") === true // and set.contains("banana") === false
You can iterate over the items in a Set:
var it = aSet.iterator; while (it.next()) { . . . it.value . . . }Or:
aSet.each(function(val) { . . . val . . . });
Although not precisely implementing the features of the EcmaScript 6 Set class, this GoJS Set class has synonyms for the following methods and property:
The constructor does not take an optional Iterable argument, but you can get the same effect by:new go.Set().addAll(iterable)
Constructor Summary Details
Name | Description |
---|---|
Set(type)
|
There are three possible constructors: Set(), Set(string) where string is a primitive type ('number' or 'string'), or Set(func) where func is a class function/constructor, such as GraphObject.More...
|
Properties Summary Details
Name, Value Type | Description |
---|---|
count
{number}
|
This read-only property is the number of elements in the Set. |
iterator
{Iterator.
|
Gets an object that you can use for iterating over the Set.More...
The value will be a member of the Set.
Typical usage:
|
Method Summary Details
Name, Return Type | Description |
---|---|
add(val)
{boolean}
|
Adds a given value to the Set, if not already present.More... Be careful not to call this method while iterating over the collection.
|
addAll(coll)
{Set.
|
Adds all of the values of a collection to this Set.More... Be careful not to call this method while iterating over the collection.
|
all(pred)
{boolean}
1.4
|
This is true if all invocations of the given predicate on items in the collection are true.More... Call the given predicate on each item in the collection. As soon as a call returns false, this returns false. Otherwise this returns true. For an empty collection this returns true.
|
any(pred)
{boolean}
1.4
|
This is true if any invocation of the given predicate on items in the collection is true.More... Call the given predicate on each item in the collection. As soon as a call returns true, this returns true. Otherwise this returns false. For an empty collection this returns false.
|
clear()
|
|
contains(val)
{boolean}
|
Returns whether the given value is in this Set.More...
|
containsAll(coll)
{boolean}
|
Returns true if all of the values of a given collection are in this Set.More...
|
containsAny(coll)
{boolean}
|
Returns true if any of the values of a given collection are in this Set.More...
|
copy()
{Set.
|
Makes a shallow copy of this Set.More... The values are not copied, so if they are objects they may continue to be shared with the original Set.
|
delete(val)
{boolean}
|
Removes a value (if found) from the Set.More... Be careful not to call this method while iterating over the collection.
|
each(func)
{Set.
|
Call the given function on each item in the collection.More...
|
first()
{T|null}
|
Returns the first item in the collection, or null if there is none.
|
has(val)
{boolean}
|
Returns whether the given value is in this Set.More...
|
remove(val)
{boolean}
|
Removes a value (if found) from the Set.More... Be careful not to call this method while iterating over the collection.
|
removeAll(coll)
{Set.
|
Removes all of the values of a collection from this Set.More... Be careful not to call this method while iterating over the collection.
|
retainAll(coll)
{Set.
|
Removes from this Set all items that are not in the given collection.More... Be careful not to call this method while iterating over the collection.
|
toArray()
{Array.
|
Produces a JavaScript Array from the contents of this Set.
|
toList()
{List.
|