/** * Licensed Materials - Property of IBM IBM Cognos Products: Modeling UI (C) * Copyright IBM Corp. 2016, 2018 US Government Users Restricted Rights - Use, * duplication or disclosure restricted by GSA ADP Schedule Contract with IBM * Corp. */ define([ 'bi/commons/ui/core/Class' ], function(Class) { var Queue = Class.extend({ init: function() { this._nextOut = 0; this._lastIn = 0; this._q = {}; }, /** * Place a new item in the queue * @param {Object} Object to be placed in the queue */ enqueue: function(data) { this._q[this._lastIn] = data; this._lastIn++; }, /** * Remove the next element from the queue, if one exists * @returns {Object} Object at the head of the queue */ dequeue: function() { var data; if (this.size() > 0) { data = this._q[this._nextOut]; delete this._q[this._nextOut]; this._nextOut++; } return data; }, /** * Get the number of elements in the queue * @returns {Number} Size of the queue */ size: function() { return this._lastIn - this._nextOut; }, /** * Returns true if the queue is empty (size === 0) * @returns {Boolean} True if queue is empty */ isEmpty: function() { return this.size() <= 0; } }); return Queue; });