-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathInterval.js
More file actions
35 lines (28 loc) · 847 Bytes
/
Interval.js
File metadata and controls
35 lines (28 loc) · 847 Bytes
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
/* Copyright (c) 2012-2022 The ANTLR Project Contributors. All rights reserved.
* Use is of this file is governed by the BSD 3-clause license that
* can be found in the LICENSE.txt file in the project root.
*/
/* stop is not included! */
export default class Interval {
constructor(start, stop) {
this.start = start;
this.stop = stop;
}
clone() {
return new Interval(this.start, this.stop);
}
contains(item) {
return item >= this.start && item < this.stop;
}
toString() {
if(this.start===this.stop-1) {
return this.start.toString();
} else {
return this.start.toString() + ".." + (this.stop-1).toString();
}
}
get length(){
return this.stop - this.start;
}
}
Interval.INVALID_INTERVAL = new Interval(-1, -2);