import { IListable } from '../interfaces/listable-interface';

export abstract class DefaultListable<T> implements IListable<T> {

    private isSearch: boolean;
    private elements: Array<T>;

    constructor(
    ) {
        this.isSearch = false;
        this.elements = [];
    }

    /**
     *
     */
    add(T: any): void {
        this.elements.push(T);
    }

    /**
     *
     */
    remove(T: any): void {
        let index = this.elements.indexOf(T);
        this.elements.slice(index, 1);
    }

    /**
     *
     */
    get(T: any): T {
        let index = this.elements.indexOf(T);
        return this.elements[index];
    }

    /**
     *
     */
    list(): Array<T> {
        return this.elements;
    }

    /**
     *
     */
    search(by: string): Array<T> {
        return null;
    }

    /**
     *
     */
    toggleSearch(): void {
        this.isSearch = !this.isSearch;
    }

    /**
     *
     */
    isSearching(): boolean {
        return this.isSearch;
    }
}
