| 5 | import { GraphNode } from "../phases/graph-phase/graph-node"; |
| 6 | |
| 7 | export class SelectionMap { |
| 8 | selection: Map<string, any>; |
| 9 | stringKey: (obj: any) => string; |
| 10 | originStringKey: (node: GraphNode) => string; |
| 11 | |
| 12 | constructor(stringKeyFnc, originStringKeyFnc?) { |
| 13 | this.selection = new Map<string, any>(); |
| 14 | this.stringKey = stringKeyFnc; |
| 15 | this.originStringKey = originStringKeyFnc; |
| 16 | } |
| 17 | |
| 18 | public isEmpty(): boolean { |
| 19 | return this.selection.size == 0; |
| 20 | } |
| 21 | |
| 22 | public clear(): void { |
| 23 | this.selection = new Map<string, any>(); |
| 24 | } |
| 25 | |
| 26 | public select(items: Iterable<any>, isSelected?: boolean): void { |
| 27 | for (const item of items) { |
| 28 | if (item === undefined) continue; |
| 29 | if (isSelected === undefined) { |
| 30 | isSelected = !this.selection.has(this.stringKey(item)); |
| 31 | } |
| 32 | if (isSelected) { |
| 33 | this.selection.set(this.stringKey(item), item); |
| 34 | } else { |
| 35 | this.selection.delete(this.stringKey(item)); |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | public isSelected(obj: any): boolean { |
| 41 | return this.selection.has(this.stringKey(obj)); |
| 42 | } |
| 43 | |
| 44 | public isKeySelected(key: string): boolean { |
| 45 | return this.selection.has(key); |
| 46 | } |
| 47 | |
| 48 | public selectedKeys(): Set<string> { |
| 49 | const result = new Set<string>(); |
| 50 | for (const key of this.selection.keys()) { |
| 51 | result.add(key); |
| 52 | } |
| 53 | return result; |
| 54 | } |
| 55 | |
| 56 | public selectedKeysAsAbsNumbers(): Set<number> { |
| 57 | const result = new Set<number>(); |
| 58 | for (const key of this.selection.keys()) { |
| 59 | const keyNum = Number(key); |
| 60 | result.add(keyNum < 0 ? Math.abs(keyNum + 1) : keyNum); |
| 61 | } |
| 62 | return result; |
| 63 | } |
| 64 |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…