import { IMetaElementJSON } from './iMetaElementJSON'; import { IMetaElementModelFormat } from './iMetaElementModelFormat'; import uuid = require('uuid/v4'); /** * A `MetaElement` represents an element of the meta-model. * * MetaElements are **mutable** * * @specfield id (string) : unique identifier of the MetaElement * @specfield name (string): name of the MetaElement */ export abstract class MetaElement { //================================ Representation ================================ private id : string; private name: string; //================================= Constructor ================================== /** * Creates a new `MetaElement` m such that: * * m.id = a randomly generated unique identifier && * * m.name = name */ public constructor(name: string) { this.id = uuid(); this.name = name; } //=================================== Getters ==================================== /** * @willreturn this.id */ public getId(): string { return this.id; } /** * @willreturn this.name */ public getName(): string { return this.name; } /** * @modifies this * @effects this_post.id = id * @param id New ID to assign to this */ public setId(id: string): void { this.id = id; } //============================ Public abstract Methods ============================ /** * @willreturn a JSON so that represents this */ public abstract toJSON(): IMetaElementJSON; /** * @willreturn a JSON that represents this in the export format model */ public abstract toModelFormat(): IMetaElementModelFormat; //=============================== Other Methods ================================ /** * @willreturn true if this contains all required data to be a valid MetaElement * @willreturn false otherwise */ public isValid(): boolean { return this.id != "" && this.id != " " && this.name != "" && this.name != " "; } //================================ Static Methods ================================= /** * @willreturn A Map storing all the [[MetaElement]]s stored in elements, using elements's id as map identifier * @param elements MetaElements to be stored into a map */ public static createMapFromArray(elements: Array): Map { const map: Map = new Map(); for(const elem of elements) map.set(elem.getId(), elem); return map; } };