import { ValueCallback, DeleteCallback, MapCallback, CloneCallback, CompareCallback, Comparable, ValidCallback } from "../types"; import { ClassForEach } from "../internal/decorator"; /** * container interface * * @remarks * Describes the methods and properties that all containers have */ export interface Container extends Comparable, Iterable { /** * Returns the current amount of data in the container */ readonly length: number; /** * Returns the current capacity of the container */ readonly capacity: number; /** * Returns true if there is no data in the container */ readonly isEmpty: boolean; /** * Returns true if there is data in the container */ readonly isNotEmpty: boolean; /** * Returns true if the container has reached the container limit */ readonly isFull: boolean; /** * Returns true if the container has not reached the container limit */ readonly isNotFull: boolean; /** * Create a full copy of the container * @param callback How to create a duplicate copy of an element */ clone(callback?: CloneCallback): Container; /** * Empty the data in the container * * @param callback Call callback on the removed element */ clear(callback?: DeleteCallback): void; /** * Returns true if the data depth of the two containers is consistent * @param o */ compareTo(o: Container, callback?: CompareCallback): number; /** * Returns a js iterator * * @param reverse If true, returns an iterator to traverse in reverse */ iterator(reverse?: boolean): Iterator; /** * Returns an object that implements a js Iterable, but it traverses the data in reverse */ get reverse(): Iterable; /** * call callback on each element in the container in turn * @param callback * @param reverse If true, traverse the container in reverse order */ forEach(callback: ValueCallback, reverse?: boolean): void; /** * Traverse the container looking for elements until the callback returns true, then stop looking * @param callback Determine whether it is the element to be found * @param reverse If true, traverse the container in reverse order * @returns whether the element was found */ find(callback: ValidCallback, reverse?: boolean): boolean; /** * Convert container to array * @param callback * @param reverse If true, traverse the container in reverse order */ map(callback: MapCallback, reverse?: boolean): Array; /** * Returns whether the data data exists in the container * @param reverse If true, traverse the container in reverse order */ has(data: T, reverse?: boolean, callback?: CompareCallback): boolean; /** * Adds all the elements of an container into a string, separated by the specified separator string. * @param separator * @param separator A string used to separate one element of the container from the next in the resulting string. If omitted, the array elements are separated with a comma. */ join(separator?: string | undefined): string; } /** * Container Creation Options */ export interface Options { /** * How the container creates a copy of the element, by default it is created with the = sign */ readonly clone?: CloneCallback; /** * How containers compare element , by default using == and < */ readonly compare?: CompareCallback; /** * If this callback function is set, this callback function will be called after the element is removed from the container */ readonly remove?: DeleteCallback; } /** * The base class of the container implements some common methods for the container */ export declare class Basic extends ClassForEach { protected opts_: Options | undefined; protected constructor(opts?: Options); /** * Returns the current capacity of the container * * @virtual */ get capacity(): number; /** * Returns true if there is no data in the container * * @virtual */ get isEmpty(): boolean; /** * Returns true if there is data in the container * * @virtual */ get isNotEmpty(): boolean; /** * Returns true if the container has reached the container limit * * @virtual */ get isFull(): boolean; /** * Returns true if the container has not reached the container limit * * @virtual */ get isNotFull(): boolean; /** * Returns a js iterator * @param reverse If true, returns an iterator to traverse in reverse * * @virtual * */ iterator(reverse?: boolean): Iterator; /** * Returns true if the data depth of the two containers is consistent * * @param o * * @virtual */ compareTo(o: Container, callback?: CompareCallback): number; /** * implements js Iterable * @sealedl */ [Symbol.iterator](): Iterator; /** * Returns an object that implements a js Iterable, but it traverses the data in reverse * @sealed */ get reverse(): Iterable; }