UNPKG

opennms

Version:

Client API for the OpenNMS network monitoring platform

48 lines (39 loc) 1.14 kB
import {IHasUrlValue} from '../api/IHasUrlValue'; import {log, catModel} from '../api/Log'; import {Category} from 'typescript-logging'; /** @hidden */ const cat = new Category('category', catModel); /** @hidden */ export const Categories = { }; /** * Represents an OpenNMS category. * @module OnmsCategory */ export class OnmsCategory implements IHasUrlValue { /** Get a singleton category object for the given category. */ public static for(id: number, name: string) { if (Categories[id]) { if (Categories[id].name === name) { return Categories[id]; } else { log.warn('Category ID ' + id + ' is already cached, but names do not match!' + ' (' + Categories[id].name + ' != ' + name + ')', cat); } } Categories[id] = new OnmsCategory(id, name); return Categories[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; } public get urlValue() { return this.name; } }