Interface for collections of hierarchical data, such as trees.

Available since

1.0.0

.

Methods

addAt(itemToAdd:T, location:Array<Int>):Void

Adds an item to the collection at the specified location, increasing the the length of the parent branch by one.

var location = [2, 0];
var item = { text: "New Item" };
collection.addAt(item, location);
Available since

1.0.0

.

See also:

contains(item:T):Bool

Determines if the collection contains the specified item.

The following example checks if a collection contains an item:

var item = { text: "New Item" };
collection.addAt(item, [0]);

var contained = collection.contains(item); // true
Available since

1.0.0

.

get(location:Array<Int>):T

Returns the item at the specified location within the collection.

The following example gets an item from a specific location:

var location = [2, 0];
var item = collection.get(location);

The following example iterates over the items at the root of a collection:

for(i in 0...collection.getLength()) {
	var location = [i];
	var item = collection.get(i);
}
Available since

1.0.0

.

getLength(?location:Array<Int>):Int

The number of items at the specified location within the collection. If called without a location, returns the length of the root.

The following example iterates over the items at the root of a collection:

for(i in 0...collection.getLength()) {
	var location = [i];
	var item = collection.get(location);
}
Available since

1.0.0

.

isBranch(item:T):Bool

Determines if an item from the collection is a branch or not.

The following example iterates over the items at the root of a collection and prints the locations of branches to the debug console:

for(i in 0...collection.getLength()) {
	var location = [i];
	var item = collection.get(location);
	if(collection.isBranch(item)) {
		trace("branch: " + location);
	}
}
Available since

1.0.0

.

locationOf(item:T):Array<Int>

Returns the location of the specified item, or null if the item is not in the collection.

The following example gets the location of an item in the collection:

var item = { text: "New Item" };
collection.addAt(item, [0]);

var index = collection.locationOf(item); // [0]
Available since

1.0.0

.

remove(item:T):Void

Removes an item from the collection.

var location = [2, 0];
var item = { text: "New Item" };
collection.addAt(item, location);
collection.remove(item);
Available since

1.0.0

.

See also:

removeAll():Void

Removes all items from the collection, decreasing the length of the root to zero.

The following example removes all items from a collection:

collection.removeAll();
Available since

1.0.0

.

See also:

removeAt(location:Array<Int>):Void

Removes an item from the collection at the specified location, decreasing the length of the parent branch by one.

var location = [2, 0];
var item = { text: "New Item" };
collection.addAt(item, location);
collection.removeAt(location);
Available since

1.0.0

.

See also:

set(location:Array<Int>, value:T):Void

Replaces the item at the specified location in the collection with a new item.

The following example replaces an item in a collection:

var location = [2, 0];
collection.set(location, object);
Available since

1.0.0

.

See also:

updateAll():Void

Notifies components using the collection that all items should be considered changed.

The following example updates all items in the collection:

collection.updateAll();
Available since

1.0.0

.

See also:

updateAt(location:Array<Int>):Void

Notifies components using the collection that an item at the specified location has changed.

The following example updates an item in the collection:

var location = [2, 0];
collection.updateAt(location);
Available since

1.0.0

.

See also: