Passed
Push — master ( 1e6bfa...39280d )
by Kolja
01:03
created

jgfNode.js ➔ label   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
const check = require('check-types');
2
3
/**
4
 * A node object represents a node in a graph.
5
 */
6
class JGFNode {
7
8
    /**
9
     * Constructor
10
     * @param {string} id Primary key for the node, that is unique for the object type.
11
     * @param {string} label A text display for the node.
12
     * @param {object,null} metadata Metadata about the node.
13
     */
14
    constructor(id, label, metadata = null) {
15
        this._id = id;
16
        this._label = label;
17
        this.metadata = metadata;
18
    }
19
20
    static _guardAgainstInvalidMetaData(metadata) {
21
        if (!check.nonEmptyObject(metadata)) {
22
            throw Error('Metadata on an node has to be an object.');
23
        }
24
    }
25
26
    set id(id) {
27
        this._id = id;
28
    }
29
30
    get id() {
31
        return this._id;
32
    }
33
34
    set label(label) {
35
        this._label = label;
36
    }
37
38
    get label() {
39
        return this._label;
40
    }
41
42
    set metadata(metadata) {
43
        if (check.assigned(metadata)) {
44
            JGFNode._guardAgainstInvalidMetaData(metadata);
45
        }
46
        this._metadata = metadata;
47
    }
48
49
    get metadata() {
50
        return this._metadata;
51
    }
52
}
53
54
module.exports = {
55
    JGFNode,
56
};