UNPKG

@andreabiagini5/applicazioni-e-servizi-web-project

Version:
42 lines 1.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MatchmakingQueueFactory = void 0; class MatchmakingQueueFactory { } exports.MatchmakingQueueFactory = MatchmakingQueueFactory; MatchmakingQueueFactory.create = (candidates) => { const queue = new MatchmakingQueueImpl(); if (candidates) { candidates.forEach(candidate => queue.add(candidate)); } return queue; }; class MatchmakingQueueImpl { constructor() { this._candidates = new Map(); } empty() { return this._candidates.size === 0; } add(candidate) { this._candidates.set(candidate.username, candidate); } get(playerId) { return this._candidates.get(playerId); } has(playerId) { return this._candidates.has(playerId); } remove(playerId) { this._candidates.delete(playerId); } get size() { return this._candidates.size; } [Symbol.iterator]() { const array = Array.from(this._candidates.values()); const sorted = array.sort((a, b) => a.requestTime.getTime() - b.requestTime.getTime()); return sorted[Symbol.iterator](); } } //# sourceMappingURL=MatchmakingQueue.js.map