src/collections/Stack.js
function Stack(parameters) {
    parameters = parameters || new composites.Parameters(new Catalog());
    if (!parameters.getParameter('$type')) parameters.setParameter('$type', '/bali/collections/Stack/v1');
    abstractions.Collection.call(this, utilities.types.STACK, 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.visitStack(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/Stack',
            $procedure: '$addItem',
            $exception: '$resourceLimit',
            $capacity: capacity,
            $text: '"The stack has reached its maximum capacity."'
        });
    };
    
    this.removeItem = function() {
        if (array.length > 0) {
            return array.pop();
        }
        throw new utilities.Exception({
            $module: '/bali/collections/Stack',
            $procedure: '$removeItem',
            $exception: '$emptyStack',
            $text: '"Attempted to remove an item from an empty stack."'
        });
    };
    
    this.getTop = function() {
        if (array.length > 0) {
            return array.peek();
        }
        throw new utilities.Exception({
            $module: '/bali/collections/Stack',
            $procedure: '$getTop',
            $exception: '$emptyStack',
            $text: '"Attempted to access an item on an empty stack."'
        });
    };
    
    this.deleteAll = function() {
        array.splice(0);
    };
    
    return this;
}
function Stack(parameters) {
    parameters = parameters || new composites.Parameters(new Catalog());
    if (!parameters.getParameter('$type')) parameters.setParameter('$type', '/bali/collections/Stack/v1');
    abstractions.Collection.call(this, utilities.types.STACK, 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.visitStack(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/Stack',
            $procedure: '$addItem',
            $exception: '$resourceLimit',
            $capacity: capacity,
            $text: '"The stack has reached its maximum capacity."'
        });
    };
    
    this.removeItem = function() {
        if (array.length > 0) {
            return array.pop();
        }
        throw new utilities.Exception({
            $module: '/bali/collections/Stack',
            $procedure: '$removeItem',
            $exception: '$emptyStack',
            $text: '"Attempted to remove an item from an empty stack."'
        });
    };
    
    this.getTop = function() {
        if (array.length > 0) {
            return array.peek();
        }
        throw new utilities.Exception({
            $module: '/bali/collections/Stack',
            $procedure: '$getTop',
            $exception: '$emptyStack',
            $text: '"Attempted to access an item on an empty stack."'
        });
    };
    
    this.deleteAll = function() {
        array.splice(0);
    };
    
    return this;
}
function Stack ( parameters ) { parameters = parameters || new composites . Parameters ( new Catalog ( ) ) ; if ( ! parameters . getParameter ( '$type' ) ) parameters . setParameter ( '$type' , '/bali/collections/Stack/v1' ) ; abstractions . Collection . call ( this , utilities . types . STACK , 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 . visitStack ( 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/Stack' , $procedure : '$addItem' , $exception : '$resourceLimit' , $capacity : capacity , $text : '"The stack has reached its maximum capacity."' } ) ; } ; this . removeItem = function ( ) { if ( array . length > 0 ) { return array . pop ( ) ; } throw new utilities . Exception ( { $module : '/bali/collections/Stack' , $procedure : '$removeItem' , $exception : '$emptyStack' , $text : '"Attempted to remove an item from an empty stack."' } ) ; } ; this . getTop = function ( ) { if ( array . length > 0 ) { return array . peek ( ) ; } throw new utilities . Exception ( { $module : '/bali/collections/Stack' , $procedure : '$getTop' , $exception : '$emptyStack' , $text : '"Attempted to access an item on an empty stack."' } ) ; } ; this . deleteAll = function ( ) { array . splice ( 0 ) ; } ; return this ; }
PUBLIC CONSTRUCTORS 
This constructor creates a new stack component with optional parameters that are
used to parameterize its type.

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