-
Notifications
You must be signed in to change notification settings - Fork 8
/
OnmsServiceType.ts
44 lines (37 loc) · 1.07 KB
/
OnmsServiceType.ts
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
import {IHasUrlValue} from '../api/IHasUrlValue';
import {log} from '../api/Log';
/** @hidden */
export const ServiceTypes = {
} as {[key: number]: OnmsServiceType};
/**
* Represents an OpenNMS service.
* @category Model
*/
export class OnmsServiceType implements IHasUrlValue {
/** Get a singleton service type object for the given service. */
public static for(id: number, name: string) {
if (ServiceTypes[id]) {
if (ServiceTypes[id].name === name) {
return ServiceTypes[id];
} else {
log.warn('Service type ID ' + id + ' is already cached, but names do not match!'
+ ' (' + ServiceTypes[id].name + ' != ' + name + ')');
}
}
ServiceTypes[id] = new OnmsServiceType(id, name);
return ServiceTypes[id];
}
/** The service ID. */
public id: number;
/** The service name. */
public name: string;
/** Given an ID and name, construct a service type. */
constructor(id: number, name: string) {
this.id = id;
this.name = name;
}
/** @inheritdoc */
public get urlValue() {
return this.name;
}
}