UNPKG

marga

Version:
66 lines (65 loc) 1.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const InnerError_1 = require("../../../error/InnerError"); /** * Bead road. This is the most basic road and have no streaks. It is implemented with a set which can guarantee that there are no repeated entities. */ class BeadRoad { _set = new Set(); _firstEntity; _lastEntity; _shoeIndex; _entityIndex = -1; _setLastEntity(entity) { this._lastEntity = entity; } _setFirstEntity(entity) { this._firstEntity = entity; } constructor(index) { this._shoeIndex = index; } print() { throw new InnerError_1.default('[BigRoad][getFirstEntity]: not implemented'); } getFirstEntity() { return this._firstEntity; } getLastEntity() { return this._lastEntity; } getShoeIndex() { return this._shoeIndex; } /** * Add entity to the bead road. * @param {Entity} entity * @return {boolean} True if the entity was added, false if it was not */ addEntity(entity) { if (this._set.has(entity)) { return false; } this._entityIndex++; entity.setIndex(this._entityIndex); this._set.add(entity); if (!this.getFirstEntity()) { this._setFirstEntity(entity); this._setLastEntity(entity); return true; } if (this.getLastEntity()) { entity.setPreviousEntity(this.getLastEntity()); } this._setLastEntity(entity); return true; } /** * The number of entities in the road. * @return {number} The number of entities in the road */ getSize() { return this._set.size; } } exports.default = BeadRoad;