src/collections/Queue.js
function Queue(parameters) {
    parameters = parameters || new composites.Parameters(new Catalog());
    if (!parameters.getParameter('$type')) parameters.setParameter('$type', '/bali/collections/Queue/v1');
    abstractions.Collection.call(this, utilities.types.QUEUE, parameters);

    // the capacity and array are private attributes so methods that use it are
    // defined in the constructor
    var capacity = 1024;  // default capacity
    if (parameters) {
        const value = parameters.getParameter('$capacity', 2);
        if (value) capacity = value.toNumber();
    }
    const array = [];

    this.acceptVisitor = function(visitor) {
        visitor.visitQueue(this);
    };

    this.toArray = function() {
        return array.slice();  // copy the array
    };

    this.getSize = function() {
        return array.length;
    };

    this.addItem = function(item) {
        if (array.length < capacity) {
            item = this.convert(item);
            array.push(item);
            return true;
        }
        throw new utilities.Exception({
            $module: '/bali/collections/Queue',
            $procedure: '$addItem',
            $exception: '$resourceLimit',
            $capacity: capacity,
            $text: '"The queue has reached its maximum capacity."'
        });
    };

    this.removeItem = function() {
        if (array.length > 0) return array.splice(0, 1)[0];  // remove the first item in the array
    };

    this.getHead = function() {
        return array[0];
    };

    this.deleteAll = function() {
        array.splice(0);
    };

    return this;
}
function Queue(parameters) {
    parameters = parameters || new composites.Parameters(new Catalog());
    if (!parameters.getParameter('$type')) parameters.setParameter('$type', '/bali/collections/Queue/v1');
    abstractions.Collection.call(this, utilities.types.QUEUE, parameters);

    // the capacity and array are private attributes so methods that use it are
    // defined in the constructor
    var capacity = 1024;  // default capacity
    if (parameters) {
        const value = parameters.getParameter('$capacity', 2);
        if (value) capacity = value.toNumber();
    }
    const array = [];

    this.acceptVisitor = function(visitor) {
        visitor.visitQueue(this);
    };

    this.toArray = function() {
        return array.slice();  // copy the array
    };

    this.getSize = function() {
        return array.length;
    };

    this.addItem = function(item) {
        if (array.length < capacity) {
            item = this.convert(item);
            array.push(item);
            return true;
        }
        throw new utilities.Exception({
            $module: '/bali/collections/Queue',
            $procedure: '$addItem',
            $exception: '$resourceLimit',
            $capacity: capacity,
            $text: '"The queue has reached its maximum capacity."'
        });
    };

    this.removeItem = function() {
        if (array.length > 0) return array.splice(0, 1)[0];  // remove the first item in the array
    };

    this.getHead = function() {
        return array[0];
    };

    this.deleteAll = function() {
        array.splice(0);
    };

    return this;
}
function Queue ( parameters ) { parameters = parameters || new composites . Parameters ( new Catalog ( ) ) ; if ( ! parameters . getParameter ( '$type' ) ) parameters . setParameter ( '$type' , '/bali/collections/Queue/v1' ) ; abstractions . Collection . call ( this , utilities . types . QUEUE , parameters ) ; // the capacity and array are private attributes so methods that use it are // defined in the constructor var capacity = 1024 ; // default capacity if ( parameters ) { const value = parameters . getParameter ( '$capacity' , 2 ) ; if ( value ) capacity = value . toNumber ( ) ; } const array = [ ] ; this . acceptVisitor = function ( visitor ) { visitor . visitQueue ( this ) ; } ; this . toArray = function ( ) { return array . slice ( ) ; // copy the array } ; this . getSize = function ( ) { return array . length ; } ; this . addItem = function ( item ) { if ( array . length < capacity ) { item = this . convert ( item ) ; array . push ( item ) ; return true ; } throw new utilities . Exception ( { $module : '/bali/collections/Queue' , $procedure : '$addItem' , $exception : '$resourceLimit' , $capacity : capacity , $text : '"The queue has reached its maximum capacity."' } ) ; } ; this . removeItem = function ( ) { if ( array . length > 0 ) return array . splice ( 0 , 1 ) [ 0 ] ; // remove the first item in the array } ; this . getHead = function ( ) { return array [ 0 ] ; } ; this . deleteAll = function ( ) { array . splice ( 0 ) ; } ; return this ; }
PUBLIC CONSTRUCTORS 
This constructor creates a new queue component with optional parameters that are
used to parameterize its type.

@param {Parameters} parameters Optional parameters used to parameterize this collection.
@returns {Queue} The new queue.
PUBLIC CONSTRUCTORS This constructor creates a new queue component with optional parameters that are used to parameterize its type .