Search API

- Preparing search index...
- The search index is not available

Show Summaries
GoJS® Diagramming Components
version 1.8.33 for JavaScript/HTML
by Northwoods Software®

## 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:

- add(val): add
- delete(val): remove
- has(val): contains
- clear(): clear
- size: count

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... Parameters: {Function|string|null=} type Optional class type (constructor) or a string describing a primitive type, either 'string' or 'number'.

## 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:
      var it = aSet.iterator;
      while (it.next()) {
        . . . " value: " + it.value . . .
      }

## 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. Parameters: {T} val The value to add to the Set; must not be null. Returns: {boolean} true if the value was not already present in the Set; false if it was.
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. Parameters: {Iterable.|Array.<*>} coll the collection of items to add. Returns: {Set.} this Set.
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. Parameters: {function(T):boolean} pred This function must not have any side-effects. Returns: {boolean} True if all predicate calls are true; false otherwise.
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. Parameters: {function(T):boolean} pred This function must not have any side-effects. Returns: {boolean} True if any predicate call is true; false otherwise.
clear() | Clears the Set.More... This sets the count to zero. Be careful not to call this method while iterating over the collection.
contains(val) {boolean} | Returns whether the given value is in this Set.More... Parameters: {T} val The value to check. Returns: {boolean} Whether or not the value is contained within the Set.
containsAll(coll) {boolean} | Returns true if all of the values of a given collection are in this Set.More... Parameters: {Iterable.} coll the collection of items to check for. Returns: {boolean}
containsAny(coll) {boolean} | Returns true if any of the values of a given collection are in this Set.More... Parameters: {Iterable.} coll the collection of items to check for. Returns: {boolean}
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. Returns: {Set.} The new Set.
each(func) {Set.} 1.4 | Call the given function on each item in the collection.More... Parameters: {function(T)} func This function must not modify the collection. Returns: {Set.} this set itself
first() {T|null} | Returns the first item in the collection, or null if there is none. Returns: {T|null} This returns null if there are no items in the collection.
has(val) {boolean} | Returns whether the given value is in this Set.More... Parameters: {T} val The value to check. Returns: {boolean} Whether or not the value is contained within the Set.
remove(val) {boolean} | Removes a value (if found) from the Set.More... Be careful not to call this method while iterating over the collection. Parameters: {T} val The value to insert. Returns: {boolean} true if the value was found and removed, false otherwise.
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. Parameters: {Iterable.|Array.<*>} coll the collection of items to remove. Returns: {Set.} this Set.
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. Parameters: {Iterable.} coll the collection of items that should be kept in this Set. Returns: {Set.} this Set.
toArray() {Array.} | Produces a JavaScript Array from the contents of this Set. Returns: {Array.} A copy of the Set in Array form.
toList() {List.} | Converts the Set to a List.More... Because there is no ordering within a Set, the values in the List may be in any order. Returns: {List.} A copy of the contents of this Set in List form.