﻿// Namespace bedrock
var bedrock = {}
bedrock._construct = function () {
}
bedrock._construct();

// Namespace bedrock.collections
bedrock.collections = {}
bedrock.collections._construct = function () {

    // list
    function list() {
        this.items = new Array();
    }
    list.prototype = {
        add: function (value) {
            this.items[this.items.length] = value;
        },
        addRange: function (items) {
            if (items) {
                var col = items.items ? items.items : items;
                for (var i = 0; i < col.length; i++) {
                    this.add(col[i]);
                }
            }
        },
        insertAt: function (value, index) {
            if (index > -1 && index <= this.items.length) {
                this.items.splice(index, 0, value);
            }
        },
        remove: function (value) {
            if (value) {
                var itemsToRemove = new Array();
                var list = this.items;
                for (var i = 0; i < list.length; i++) {
                    if (list[i] == value) {
                        itemsToRemove[itemsToRemove.length] = i;
                    }
                }
                for (var i = 0; i < itemsToRemove.length; i++)
                    list.splice(itemsToRemove[i], 1);
            }
        },
        removeAt: function (index) {
            if (index > -1 && index < this.items.length) {
                this.items.splice(index, 1);
            }
        },
        contains: function (value) {
            if (value) {
                var contains = false;
                var list = this.items;
                for (var i = 0; i < list.length; i++) {
                    if (list[i] == value) {
                        contains = true;
                        break;
                    }
                }
                return contains;
            }
            return false;
        },
        clear: function () {
            this.items = new Array();
        },
        move: function (index, newIndex) {
            var tmp = this.items.splice(index, 1);
            this.items.splice(newIndex, 0, tmp[0]);
        }
    }
    this.list = list;

}
bedrock.collections._construct();
