@cute-dw/core
Version:
This TypeScript library is the main part of a more powerfull package designed for the fast WEB software development. The cornerstone of the library is the **DataStore** class, which might be useful when you need a full control of the data, but do not need
187 lines (186 loc) • 6.19 kB
TypeScript
import { AbstractList } from './AbstractList';
import { Collection, Element } from './Collection';
import { Deque } from './Deque';
import { List } from './List';
import { Cloneable } from '../util/interface/Cloneable';
/**
* Doubly-linked list implementation of the List and Deque interfaces.
* Implements all optional list operations, and permits all elements (including null).
*/
export declare class LinkedList<T> extends AbstractList<T> implements Deque<T>, Cloneable {
private head;
private tail;
private compare;
private _size;
/**
* @constructor
*/
constructor(collection?: Collection<T> | Array<T>);
/**
* Inserts node to the specified position in the list
* @param index Ordered number of the node before which we want to insert a new node. To add node to the end of the list set `index` to the `Infinity` or to the value that great or equal to the list's `size` property.
* @param newNode Inserted node
* @returns _true_ if the node was inserted, else _false_
* @protected
*/
protected insertNode(index: number, newNode: LinkedListNode<T>): boolean;
protected removeNode(node: LinkedListNode<T> | null): boolean;
/**
* @override
*/
[Symbol.iterator](): IterableIterator<Element<T>>;
/**
* @override
*/
[Symbol.toStringTag]: string;
/**
* @override
*/
get size(): number;
/**
* @override
*/
append(value: Element<T>): boolean;
/**
* Clones the current collection
* @returns New cloned collection
*/
clone(): LinkedList<T>;
/**
* Retrieves, but does not remove, the head of this queue, or returns _undefined_ if this queue is empty
*/
element(): Element<T> | undefined;
/**
* @override
*/
getParent(): LinkedList<T> | null;
/**
* Loads an array of the collection items
* @param values - Array of values that need to be converted to linked list.
*/
loadArray<E extends T>(values: Array<Element<T>>): void;
/**
* @override
*/
get(index: number): Element<T> | undefined;
/**
* @override
* @throws IllegalArgumentException
*/
set(index: number, value: Element<T>): Element<T> | undefined;
/**
* @override
*/
clear(): void;
/**
* @override
*/
contains(value: Element<T>): boolean;
/**
* Gets the index of the first item in the collection
* @param value Searched value
* @param fromIndex Started index to search. Default is 0.
* @returns Index number if found, else -1
*/
indexOf(value: Element<T>, fromIndex?: number): number;
/**
* @override
*/
insert(index: number, value: Element<T>): boolean;
/**
* Gets the index of the last item in the collection
* @param value Searched value
* @param fromIndex The index to search starting from the end. Default is 0.
* @returns Index number if found, else -1
*/
lastIndexOf(value: Element<T>, fromIndex?: number): number;
/**
* Inserts the specified element into this queue if it is possible
*/
offer(value: Element<T>): boolean;
/**
* Retrieves, but does not remove, the head of this queue, or returns `undefined` if this queue is empty
*/
peek(): Element<T> | undefined;
/**
* Retrieves and removes the head of this queue, or returns `undefined` if this queue is empty
*/
poll(): Element<T> | undefined;
/**
* Inserts the specified element at the front of this deque
* @param value
* @returns
*/
offerFirst(value: Element<T>): boolean;
/**
* Inserts the specified element at the end of this deque
* @param value
* @returns
*/
offerLast(value: Element<T>): boolean;
/**
* Retrieves and removes the first element of this deque, or returns `undefined` if this deque is empty
* @returns
*/
pollFirst(): Element<T> | undefined;
/**
* Retrieves and removes the last element of this deque, or returns `undefined` if this deque is empty
* @returns
*/
pollLast(): Element<T> | undefined;
/**
* Removes a single instance of the specified element from this collection, if it is present
* @param {T} value
* @return {boolean}
*/
remove(value: Element<T>): boolean;
/**
* @override
*/
removeAt(index: number): Element<T> | undefined;
/**
* Retrieves and removes the head of this list, or returns `undefined` if this list object is empty
*/
removeFirst(): Element<T> | undefined;
/**
* Retrieves and removes the tail of this list, or returns `undefined` if this list object is empty
*/
removeLast(): Element<T> | undefined;
/**
* @override
*/
removeRange(fromIndex: number, toIndex?: number): boolean;
/**
* Retrieves, but does not remove, the first element of this list, or returns _undefined_ if this collection is empty
* @returns
*/
peekFirst(): Element<T> | undefined;
/**
* Retrieves, but does not remove, the last element of this list, or returns _undefined_ if this collection is empty
* @returns
*/
peekLast(): Element<T> | undefined;
/**
* @override
*/
subList(fromIndex: number, toIndex: number): List<T>;
getHead(): Readonly<LinkedListNode<T>> | null;
getTail(): Readonly<LinkedListNode<T>> | null;
getNode(index: number): Readonly<LinkedListNode<T>> | null;
/**
* @returns {LinkedListNode[]}
*/
toArray(): Array<Element<T>>;
}
/**
* Linked List's Node
*/
export declare class LinkedListNode<T> {
value: Element<T>;
next: LinkedListNode<T> | null;
prev: LinkedListNode<T> | null;
constructor(value: Element<T>, next?: LinkedListNode<T> | null, prev?: LinkedListNode<T> | null);
setValue(value: Element<T>): void;
toString(callback: (v: any) => string): string;
toJSON(): Element<T>;
}