Class List
An ordered iterable collection. It optionally enforces the type of elements that may be added to the List.
An example usage:
var list = new go.List(go.Point); // make a list of Points list.add(new go.Point(0, 0)); list.add(new go.Point(20, 10)); list.add(new go.Point(10, 20)); // now list.length === 3 // and list.elt(1) instanceof go.Point
You can iterate over the items in a List:
var it = aList.iterator; while (it.next()) { window.console.log("#" + it.key + " is " + it.value); }Or:
aList.each(function(val) { window.console.log(val); });The key will range from zero to count-1.
For convenience this GoJS List class has synonyms for the following methods and property:
- get(idx): elt
- set(idx,val): setElt
- has(val): contains
- delete(val): remove
- clear(): clear
- size: count
Constructor Summary Details
Returns | Name | Description |
---|---|---|
List(type)
|
There are three possible constructors:
List(),
List(string) where string is a primitive type ('number', 'string', 'boolean', or 'function'), or
List(func) where func is a class function/constructor, such as GraphObject. More...
Typical usage would be something like: var list = new go.List(go.GraphObject); // keep a list of GraphObjects
|
Properties Summary Details
Returns | Name | Description |
---|---|---|
{number}
|
count
|
This read-only property is the length of the List.
|
{Iterator.
|
iterator
|
Gets an object that you can use for iterating over the List. More...
The key will be an integer from zero to the count-1.
The value will be the item at that index in the list.
Typical usage:
var it = aList.iterator; while (it.next()) { . . . "index: " + it.key + " value: " + it.value . . . } |
{Iterator.
|
iteratorBackwards
|
Gets an object that you can use for iterating over the List in backwards order. More...
The key will be an integer from count-1 to zero.
The value will be the item at that index in the list.
The list is not modified by traversing in reverse order.
Typical usage:
var it = aList.iteratorBackwards; while (it.next()) { . . . 'key: ' + it.key + ' value: ' + it.value . . . } |
{number}
|
length
|
This read-only property is the length of the List, a synonym for the count property.
|
Method Summary Details
Returns | Name | Description |
---|---|---|
add(val)
|
Adds a given value to the end of the List. More...
Be careful not to call this method while iterating over the collection.
|
|
{List.
|
addAll(coll)
|
Adds all of the values of a collection to the end of this List. More...
Be careful not to call this method while iterating over the collection.
|
{boolean}
|
all(pred)
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.
|
{boolean}
|
any(pred)
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()
|
||
{boolean}
|
contains(val)
|
Returns whether the given value is in this List. More...
|
{List.
|
copy()
|
Makes a shallow copy of this List. More...
The values are not copied,
so if they are objects they may continue to be shared with the original List.
|
each(func)
1.4
|
Call the given function on each item in the collection. More...
|
|
{T}
|
elt(i)
|
Returns the element at the given index. More...
|
{?T}
|
first()
|
Returns the first item in the list, or null if there is none.
|
{number}
|
indexOf(val)
|
Returns the index of the given value if it is in this List. More...
|
insertAt(i, val)
|
Insert a value before the index i. More...
Be careful not to call this method while iterating over the collection.
|
|
{?T}
|
last()
1.5
|
Returns the last item in the list, or null if these is none.
|
{?T}
|
pop()
1.5
|
|
{boolean}
|
remove(val)
|
Removes a given value (if found) from the List. More...
Be careful not to call this method while iterating over the collection.
|
removeAt(i)
|
Removes a value at a given index from the List. More...
Be careful not to call this method while iterating over the collection.
|
|
removeRange(to, from)
|
Removes a range of values from the List. More...
Be careful not to call this method while iterating over the collection.
|
|
{List.
|
reverse()
|
Reverse the order of items in this List.
|
setElt(i, val)
|
Set the element at the given index to a given value. More...
|
|
{List.
|
sort(sortfunc)
|
Sort the List according to a comparison function. More...
|
{Array.
|
toArray()
|
Produces a JavaScript Array from the contents of this List.
|
{Set.
|
toSet()
|