/*! * Copyright 2020 Ron Buckton * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import type { GraphCategory } from "./graphCategory"; import type { GraphProperty } from "./graphProperty"; import type { Graph } from "./graph"; import type { GraphPropertyIdLike } from "./graphPropertyIdLike"; import type { GraphCategoryIdLike } from "./graphCategoryIdLike"; import { GraphNode } from "./graphNode"; import { BaseCollection } from "./baseCollection"; import { EventSubscription } from "./events"; import { GraphNodeIdLike } from "./graphNodeIdLike"; /** * A collection of nodes within a Graph. */ export declare class GraphNodeCollection extends BaseCollection { private _graph; private _nodes; private _events?; private constructor(); /** * Gets the graph to which this collection belongs. */ get graph(): Graph; /** * Gets the number of nodes in the collection. */ get size(): number; /** * Creates a subscription for a set of named events. */ subscribe(events: GraphNodeCollectionEvents): EventSubscription; /** * Determines whether the collection contains the specified npde. */ has(node: GraphNode | GraphNodeIdLike): boolean; /** * Gets the node with the provided id. */ get(id: GraphNodeIdLike): GraphNode | undefined; /** * Gets the node with the provided id. If it does not exist, a new node is created. */ getOrCreate(id: GraphNodeIdLike, category?: GraphCategory): GraphNode; /** * Adds a node to the collection. */ add(node: GraphNode): this; /** * Removes a node from the collection. */ delete(node: GraphNode): boolean; /** * Removes the node with the specified id from the collection. */ delete(node: GraphNodeIdLike): GraphNode | false; delete(node: GraphNode | GraphNodeIdLike): GraphNode | boolean; /** * Removes all nodes from the collection. */ clear(): void; /** * Yields each node in the graph that has no incoming links. */ rootNodes(): IterableIterator; /** * Yields each node in the graph that has no outgoing links. */ leafNodes(): IterableIterator; /** * Creates an iterator for the node ids in the collection. */ keys(): IterableIterator; /** * Creates an iterator for the values in the collection. */ values(): IterableIterator; /** * Creates an iterator for the values in the collection. */ entries(): IterableIterator<[GraphNodeIdLike, GraphNode]>; /** * Creates an iterator for the values in the collection. */ [Symbol.iterator](): IterableIterator; /** * Creates an iterator for each node with the specified property key and value. */ byProperty(key: GraphProperty, value: V | undefined): IterableIterator; /** * Creates an iterator for each node with the specified property key and value. */ byProperty(key: GraphPropertyIdLike | GraphProperty, value: any): IterableIterator; /** * Creates an iterator for each node with any of the specified categories. */ byCategory(...categories: (GraphCategoryIdLike | GraphCategory)[]): IterableIterator; private _raiseOnAdded; private _raiseOnDeleted; } export interface GraphNodeCollectionEvents { /** * An event raised when a node is added to the collection. */ onAdded?: (node: GraphNode) => void; /** * An event raised when a node is removed from the collection. */ onDeleted?: (node: GraphNode) => void; }