-
Notifications
You must be signed in to change notification settings - Fork 0
/
jgfEdge.js
76 lines (64 loc) · 2.06 KB
/
jgfEdge.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const { Guard } = require('./guard');
/**
* An edge object represents a edge between two nodes in a graph. In graph theory, edges are also called lines or links.
*/
class JgfEdge {
/**
* Constructor
* @param {string} source Source node ID.
* @param {string} target Target node ID.
* @param {string|null} relation Edge relation (aka 'relationship type').
* @param {string|null} label Edge label (the display name of the edge).
* @param {object|null} metadata Custom edge meta data.
* @param {boolean|null} directed Pass true for a directed edge, false for undirected.
*/
constructor(source, target, relation = null, label = null, metadata = null, directed = true) {
this.source = source;
this.target = target;
this.relation = relation;
this.label = label;
this.metadata = metadata;
this.directed = directed;
}
set source(source) {
Guard.assertNonEmptyStringParameter('source', source);
this._source = source;
}
get source() {
return this._source;
}
set target(target) {
Guard.assertNonEmptyStringParameter('target', target);
this._target = target;
}
get target() {
return this._target;
}
set metadata(metadata) {
Guard.assertValidMetadataOrNull(metadata);
this._metadata = metadata;
}
get metadata() {
return this._metadata;
}
set directed(directed) {
Guard.assertValidDirected(directed);
this._directed = directed;
}
get directed() {
return this._directed;
}
/**
* Determines whether this edge is equal to the passed edge.
* @param {JgfEdge} edge The edge to compare to.
* @param {boolean} compareRelation Whether or not to compare the relation as well.
*/
isEqualTo(edge, compareRelation = false) {
return edge.source === this.source
&& edge.target === this.target
&& (compareRelation === false || edge.relation === this.relation);
}
}
module.exports = {
JgfEdge,
};