/*! * 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 { GraphCategoryIdLike } from "./graphCategoryIdLike"; import type { GraphProperty } from "./graphProperty"; import type { GraphPropertyIdLike } from "./graphPropertyIdLike"; import type { GraphNode } from "./graphNode"; import type { GraphNodeIdLike } from "./graphNodeIdLike"; import type { Graph } from "./graph"; import { BaseCollection } from "./baseCollection"; import { EventSubscription } from "./events"; import { GraphLink } from "./graphLink"; /** * A collection of links within a Graph. */ export declare class GraphLinkCollection extends BaseCollection { private _size; private _graph; private _links; private _events?; private constructor(); /** * Gets the graph to which this collection belongs. */ get graph(): Graph; /** * Gets the number of links in the collection. */ get size(): number; /** * Creates a subscription for a set of named events. */ subscribe(events: GraphLinkCollectionEvents): EventSubscription; /** * Determines whether the collection contains the specified link. */ has(link: GraphLink): boolean; /** * Gets the link for the provided source and target. */ get(source: GraphNode | GraphNodeIdLike, target: GraphNode | GraphNodeIdLike, index?: number): GraphLink | undefined; /** * Gets the link for the provided source and target. If one is not found, a new link is created. */ getOrCreate(source: GraphNodeIdLike | GraphNode, target: GraphNodeIdLike | GraphNode, index?: number): GraphLink; /** * Gets the link for the provided source and target. If one is not found, a new link is created. */ getOrCreate(source: GraphNodeIdLike | GraphNode, target: GraphNodeIdLike | GraphNode, category: GraphCategory): GraphLink; /** * Adds a link to the collection. */ add(link: GraphLink): this; /** * Removes a link from the collection. */ delete(link: GraphLink): boolean; /** * Removes the link with the specified source, target, and category from the collection. */ delete(sourceId: GraphNodeIdLike, targetId: GraphNodeIdLike, category: GraphCategory): GraphLink | false; /** * Removes all links from the collection. */ clear(): void; /** * Creates an iterator for the values in the collection. */ values(): IterableIterator; /** * Creates an iterator for the values in the collection. */ [Symbol.iterator](): IterableIterator; /** * Creates an iterator for each link between a source and a target node. */ between(source: GraphNode, target: GraphNode): IterableIterator; /** * Creates an iterator for each incoming link to a node. */ to(node: GraphNodeIdLike | GraphNode, ...linkCategories: (GraphCategory | GraphCategoryIdLike)[]): IterableIterator; /** * Creates an iterator for each outgoing link from a node. */ from(node: GraphNodeIdLike | GraphNode, ...linkCategories: (GraphCategory | GraphCategoryIdLike)[]): IterableIterator; /** * Creates an iterator for each link with the specified property key and value. */ byProperty(key: GraphProperty, value: V): IterableIterator; /** * Creates an iterator for each link with the specified property key and value. */ byProperty(key: GraphPropertyIdLike | GraphProperty, value: any): IterableIterator; /** * Creates an iterator for each link with any of the specified categories. */ byCategory(...linkCategories: (GraphCategory | GraphCategoryIdLike)[]): IterableIterator; private _raiseOnAdded; private _raiseOnDeleted; } export interface GraphLinkCollectionEvents { /** * An event raised when a link is added to the collection. */ onAdded?: (this: void, link: GraphLink) => void; /** * An event raised when a link is removed from the collection. */ onDeleted?: (this: void, link: GraphLink) => void; }