/********************************************************************
 * @author:      Kaven
 * @email:       kaven@wuwenkai.com
 * @website:     http://kavenblog.com
 * @file:        [Kaven-Basic] /src/libs/data_structures/KavenStack.ts
 * @create:      2019-03-21 16:20:59.274
 * @modify:      2019-03-24 22:21:33.173
 * @version:     1.1.19
 * @times:       8
 * @lines:       113
 * @copyright:   Copyright © 2019 Kaven. All Rights Reserved.
 * @description: [description]
 * @license:
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 ********************************************************************/
/**
 * Represents a variable size last-in-first-out (LIFO) collection of instances of the same specified type.
 * @since 1.1.19
 * @version 2019-03-21
 */
var KavenStack = /** @class */ (function () {
    function KavenStack() {
        this.array = [];
    }
    Object.defineProperty(KavenStack.prototype, "Count", {
        /**
         * Gets the number of elements contained in the KavenStack.
         * @returns The number of elements contained in the KavenStack.
         */
        get: function () {
            return this.array.length;
        },
        enumerable: true,
        configurable: true
    });
    /**
     * Removes all objects from the KavenStack.
     */
    KavenStack.prototype.Clear = function () {
        // set to a new empty array,
        // we shouldn't have references to the original array.
        this.array = [];
    };
    /**
     * Determines whether an element is in the KavenStack.
     * @param item The object to locate in the KavenStack. The value can be undefined.
     */
    KavenStack.prototype.Contains = function (item) {
        return this.array.includes(item);
    };
    /**
     * Returns the object at the top of the KavenStack without removing it.
     * @returns The object at the top of the KavenStack.
     */
    KavenStack.prototype.Peek = function () {
        return this.array.Last();
    };
    /**
     * Removes and returns the object at the top of the KavenStack.
     * @returns The object removed from the top of the KavenStack.
     */
    KavenStack.prototype.Pop = function () {
        return this.array.pop();
    };
    /**
     * Inserts an object at the top of the KavenStack.
     * @param item The object to push onto the KavenStack. The value can be undefined.
     */
    KavenStack.prototype.Push = function (item) {
        this.array.push(item);
        if (this.MaxLength) {
            while (this.Count > this.MaxLength) {
                this.array.shift();
            }
        }
    };
    /**
     * Copies the KavenStack to a new array.
     * @returns A new array containing copies of the elements of the KavenStack.
     */
    KavenStack.prototype.ToArray = function () {
        return this.array.slice(0);
    };
    return KavenStack;
}());
export { KavenStack };
//# sourceMappingURL=KavenStack.js.map