main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
967 bytes
|
Line | |
---|
1 | /**
|
---|
2 | * @fileoverview A class of identifiers generator for code path segments.
|
---|
3 | *
|
---|
4 | * Each rule uses the identifier of code path segments to store additional
|
---|
5 | * information of the code path.
|
---|
6 | *
|
---|
7 | * @author Toru Nagashima
|
---|
8 | */
|
---|
9 |
|
---|
10 | "use strict";
|
---|
11 |
|
---|
12 | //------------------------------------------------------------------------------
|
---|
13 | // Public Interface
|
---|
14 | //------------------------------------------------------------------------------
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * A generator for unique ids.
|
---|
18 | */
|
---|
19 | class IdGenerator {
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * @param {string} prefix Optional. A prefix of generated ids.
|
---|
23 | */
|
---|
24 | constructor(prefix) {
|
---|
25 | this.prefix = String(prefix);
|
---|
26 | this.n = 0;
|
---|
27 | }
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Generates id.
|
---|
31 | * @returns {string} A generated id.
|
---|
32 | */
|
---|
33 | next() {
|
---|
34 | this.n = 1 + this.n | 0;
|
---|
35 |
|
---|
36 | /* c8 ignore start */
|
---|
37 | if (this.n < 0) {
|
---|
38 | this.n = 1;
|
---|
39 | }/* c8 ignore stop */
|
---|
40 |
|
---|
41 | return this.prefix + this.n;
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | module.exports = IdGenerator;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.