• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/**
17 * List is implemented based on the singly linked list. Each node has a reference pointing to the next element.
18 * When querying an element, the system traverses the list from the beginning.
19 *
20 * @syscap SystemCapability.Utils.Lang
21 * @since 8
22 */
23/**
24 * List is implemented based on the singly linked list. Each node has a reference pointing to the next element.
25 * When querying an element, the system traverses the list from the beginning.
26 *
27 * @syscap SystemCapability.Utils.Lang
28 * @crossplatform
29 * @since 10
30 */
31declare class List<T> {
32  /**
33   * A constructor used to create a List object.
34   *
35   * @throws { BusinessError } 10200012 - The List's constructor cannot be directly invoked.
36   * @syscap SystemCapability.Utils.Lang
37   * @since 8
38   */
39  /**
40   * A constructor used to create a List object.
41   *
42   * @throws { BusinessError } 10200012 - The List's constructor cannot be directly invoked.
43   * @syscap SystemCapability.Utils.Lang
44   * @crossplatform
45   * @since 10
46   */
47  constructor();
48  /**
49   * Gets the element number of the List. This is a number one higher than the highest index in the list.
50   *
51   * @syscap SystemCapability.Utils.Lang
52   * @since 8
53   */
54  /**
55   * Gets the element number of the List. This is a number one higher than the highest index in the list.
56   *
57   * @syscap SystemCapability.Utils.Lang
58   * @crossplatform
59   * @since 10
60   */
61  length: number;
62  /**
63   * Appends the specified element to the end of this list.
64   *
65   * @param { T } element - element element to be appended to this list
66   * @returns { boolean } the boolean type, returns true if the addition is successful, and returns false if it fails.
67   * @throws { BusinessError } 10200011 - The add method cannot be bound.
68   * @syscap SystemCapability.Utils.Lang
69   * @since 8
70   */
71  /**
72   * Appends the specified element to the end of this list.
73   *
74   * @param { T } element - element element to be appended to this list
75   * @returns { boolean } the boolean type, returns true if the addition is successful, and returns false if it fails.
76   * @throws { BusinessError } 10200011 - The add method cannot be bound.
77   * @syscap SystemCapability.Utils.Lang
78   * @crossplatform
79   * @since 10
80   */
81  add(element: T): boolean;
82  /**
83   * Inserts the specified element at the specified position in this list.
84   *
85   * @param { T } element - element element element to be inserted
86   * @param { number } index - index index index at which the specified element is to be inserted
87   * @throws { BusinessError } 10200011 - The insert method cannot be bound.
88   * @throws { BusinessError } 10200001 - The value of index is out of range.
89   * @throws { BusinessError } 401 - The type of parameters are invalid.
90   * @syscap SystemCapability.Utils.Lang
91   * @since 8
92   */
93  /**
94   * Inserts the specified element at the specified position in this list.
95   *
96   * @param { T } element - element element element to be inserted
97   * @param { number } index - index index index at which the specified element is to be inserted
98   * @throws { BusinessError } 10200011 - The insert method cannot be bound.
99   * @throws { BusinessError } 10200001 - The value of index is out of range.
100   * @throws { BusinessError } 401 - The type of parameters are invalid.
101   * @syscap SystemCapability.Utils.Lang
102   * @crossplatform
103   * @since 10
104   */
105  insert(element: T, index: number): void;
106  /**
107   * Returns the element at the specified position in this list,
108   * or returns undefined if this list is empty
109   *
110   * @param { number } index - index index specified position
111   * @returns { T } the T type
112   * @throws { BusinessError } 10200011 - The get method cannot be bound.
113   * @throws { BusinessError } 401 - The type of parameters are invalid.
114   * @syscap SystemCapability.Utils.Lang
115   * @since 8
116   */
117  /**
118   * Returns the element at the specified position in this list,
119   * or returns undefined if this list is empty
120   *
121   * @param { number } index - index index specified position
122   * @returns { T } the T type
123   * @throws { BusinessError } 10200011 - The get method cannot be bound.
124   * @throws { BusinessError } 401 - The type of parameters are invalid.
125   * @syscap SystemCapability.Utils.Lang
126   * @crossplatform
127   * @since 10
128   */
129  get(index: number): T;
130  /**
131   * Check if list contains the specified element
132   *
133   * @param { T } element - element element element to be contained
134   * @returns { boolean } the boolean type,if list contains the specified element,return true,else return false
135   * @throws { BusinessError } 10200011 - The has method cannot be bound.
136   * @syscap SystemCapability.Utils.Lang
137   * @since 8
138   */
139  /**
140   * Check if list contains the specified element
141   *
142   * @param { T } element - element element element to be contained
143   * @returns { boolean } the boolean type,if list contains the specified element,return true,else return false
144   * @throws { BusinessError } 10200011 - The has method cannot be bound.
145   * @syscap SystemCapability.Utils.Lang
146   * @crossplatform
147   * @since 10
148   */
149  has(element: T): boolean;
150  /**
151   * Returns the index of the first occurrence of the specified element
152   * in this list, or -1 if this list does not contain the element.
153   *
154   * @param { T } element - element element element to be contained
155   * @returns { number } the number type ,returns the lowest index such that or -1 if there is no such index.
156   * @throws { BusinessError } 10200011 - The getIndexOf method cannot be bound.
157   * @syscap SystemCapability.Utils.Lang
158   * @since 8
159   */
160  /**
161   * Returns the index of the first occurrence of the specified element
162   * in this list, or -1 if this list does not contain the element.
163   *
164   * @param { T } element - element element element to be contained
165   * @returns { number } the number type ,returns the lowest index such that or -1 if there is no such index.
166   * @throws { BusinessError } 10200011 - The getIndexOf method cannot be bound.
167   * @syscap SystemCapability.Utils.Lang
168   * @crossplatform
169   * @since 10
170   */
171  getIndexOf(element: T): number;
172  /**
173   * Find the corresponding element according to the index,
174   *
175   * @param { number } index - index index the index in the list
176   * @returns { T } the T type ,returns undefined if list is empty,If the index is
177   * out of bounds (greater than or equal to length or less than 0), throw an exception
178   * @throws { BusinessError } 10200011 - The removeByIndex method cannot be bound.
179   * @throws { BusinessError } 10200001 - The value of index is out of range.
180   * @throws { BusinessError } 401 - The type of parameters are invalid.
181   * @syscap SystemCapability.Utils.Lang
182   * @since 8
183   */
184  /**
185   * Find the corresponding element according to the index,
186   *
187   * @param { number } index - index index the index in the list
188   * @returns { T } the T type ,returns undefined if list is empty,If the index is
189   * out of bounds (greater than or equal to length or less than 0), throw an exception
190   * @throws { BusinessError } 10200011 - The removeByIndex method cannot be bound.
191   * @throws { BusinessError } 10200001 - The value of index is out of range.
192   * @throws { BusinessError } 401 - The type of parameters are invalid.
193   * @syscap SystemCapability.Utils.Lang
194   * @crossplatform
195   * @since 10
196   */
197  removeByIndex(index: number): T;
198  /**
199   * Removes the first occurrence of the specified element from this list,
200   * if it is present.  If the list does not contain the element, it is
201   * unchanged.  More formally, removes the element with the lowest index
202   *
203   * @param { T } element - element element element to remove
204   * @returns { boolean } the boolean type ,If there is no such element, return false
205   * @throws { BusinessError } 10200011 - The remove method cannot be bound.
206   * @syscap SystemCapability.Utils.Lang
207   * @since 8
208   */
209  /**
210   * Removes the first occurrence of the specified element from this list,
211   * if it is present.  If the list does not contain the element, it is
212   * unchanged.  More formally, removes the element with the lowest index
213   *
214   * @param { T } element - element element element to remove
215   * @returns { boolean } the boolean type ,If there is no such element, return false
216   * @throws { BusinessError } 10200011 - The remove method cannot be bound.
217   * @syscap SystemCapability.Utils.Lang
218   * @crossplatform
219   * @since 10
220   */
221  remove(element: T): boolean;
222  /**
223   * Returns in the index of the last occurrence of the specified element in this list ,
224   * or -1 if the list does not contain the element.
225   *
226   * @param { T } element - element element element to find
227   * @returns { number } the number type
228   * @throws { BusinessError } 10200011 - The getLastIndexOf method cannot be bound.
229   * @syscap SystemCapability.Utils.Lang
230   * @since 8
231   */
232  /**
233   * Returns in the index of the last occurrence of the specified element in this list ,
234   * or -1 if the list does not contain the element.
235   *
236   * @param { T } element - element element element to find
237   * @returns { number } the number type
238   * @throws { BusinessError } 10200011 - The getLastIndexOf method cannot be bound.
239   * @syscap SystemCapability.Utils.Lang
240   * @crossplatform
241   * @since 10
242   */
243  getLastIndexOf(element: T): number;
244  /**
245   * Returns the first element (the item at index 0) of this list.
246   * or returns undefined if list is empty
247   *
248   * @returns { T } the T type ,returns undefined if list is empty
249   * @throws { BusinessError } 10200011 - The getFirst method cannot be bound.
250   * @syscap SystemCapability.Utils.Lang
251   * @since 8
252   */
253  /**
254   * Returns the first element (the item at index 0) of this list.
255   * or returns undefined if list is empty
256   *
257   * @returns { T } the T type ,returns undefined if list is empty
258   * @throws { BusinessError } 10200011 - The getFirst method cannot be bound.
259   * @syscap SystemCapability.Utils.Lang
260   * @crossplatform
261   * @since 10
262   */
263  getFirst(): T;
264  /**
265   * Returns the Last element (the item at index length-1) of this list.
266   * or returns undefined if list is empty
267   *
268   * @returns { T } the T type ,returns undefined if list is empty
269   * @throws { BusinessError } 10200011 - The getLast method cannot be bound.
270   * @syscap SystemCapability.Utils.Lang
271   * @since 8
272   */
273  /**
274   * Returns the Last element (the item at index length-1) of this list.
275   * or returns undefined if list is empty
276   *
277   * @returns { T } the T type ,returns undefined if list is empty
278   * @throws { BusinessError } 10200011 - The getLast method cannot be bound.
279   * @syscap SystemCapability.Utils.Lang
280   * @crossplatform
281   * @since 10
282   */
283  getLast(): T;
284  /**
285   * Replaces the element at the specified position in this List with the specified element
286   *
287   * @param { number } index - index index index to find
288   * @param { T } element - element element replaced element
289   * @returns { T } the T type
290   * @throws { BusinessError } 10200011 - The set method cannot be bound.
291   * @throws { BusinessError } 10200001 - The value of index is out of range.
292   * @throws { BusinessError } 401 - The type of parameters are invalid.
293   * @syscap SystemCapability.Utils.Lang
294   * @since 8
295   */
296  /**
297   * Replaces the element at the specified position in this List with the specified element
298   *
299   * @param { number } index - index index index to find
300   * @param { T } element - element element replaced element
301   * @returns { T } the T type
302   * @throws { BusinessError } 10200011 - The set method cannot be bound.
303   * @throws { BusinessError } 10200001 - The value of index is out of range.
304   * @throws { BusinessError } 401 - The type of parameters are invalid.
305   * @syscap SystemCapability.Utils.Lang
306   * @crossplatform
307   * @since 10
308   */
309  set(index: number, element: T): T;
310  /**
311   * Compares the specified object with this list for equality.if the object are the same as this list
312   * return true, otherwise return false.
313   *
314   * @param { Object } obj - obj obj Compare objects
315   * @returns { boolean } the boolean type
316   * @throws { BusinessError } 10200011 - The equal method cannot be bound.
317   * @syscap SystemCapability.Utils.Lang
318   * @since 8
319   */
320  /**
321   * Compares the specified object with this list for equality.if the object are the same as this list
322   * return true, otherwise return false.
323   *
324   * @param { Object } obj - obj obj Compare objects
325   * @returns { boolean } the boolean type
326   * @throws { BusinessError } 10200011 - The equal method cannot be bound.
327   * @syscap SystemCapability.Utils.Lang
328   * @crossplatform
329   * @since 10
330   */
331  equal(obj: Object): boolean;
332  /**
333   * Replaces each element of this list with the result of applying the operator to that element.
334   *
335   * @param { function } callbackFn - callbackFn
336   * callbackFn (required) A function that accepts up to four arguments.
337   * The function to be called for each element in the list,Returns the result of an operation
338   * @param { Object } thisArg - thisArg thisArg (Optional) The value passed to the function generally uses the "this" value.
339   * If this parameter is empty, "undefined" will be passed to the "this" value
340   * @throws { BusinessError } 10200011 - The forEach method cannot be bound.
341   * @throws { BusinessError } 401 - The type of parameters are invalid.
342   * @syscap SystemCapability.Utils.Lang
343   * @since 8
344   */
345  /**
346   * Replaces each element of this list with the result of applying the operator to that element.
347   *
348   * @param { function } callbackFn - callbackFn
349   * callbackFn (required) A function that accepts up to four arguments.
350   * The function to be called for each element in the list,Returns the result of an operation
351   * @param { Object } thisArg - thisArg thisArg (Optional) The value passed to the function generally uses the "this" value.
352   * If this parameter is empty, "undefined" will be passed to the "this" value
353   * @throws { BusinessError } 10200011 - The forEach method cannot be bound.
354   * @throws { BusinessError } 401 - The type of parameters are invalid.
355   * @syscap SystemCapability.Utils.Lang
356   * @crossplatform
357   * @since 10
358   */
359  forEach(callbackFn: (value: T, index?: number, List?: List<T>) => void, thisArg?: Object): void;
360  /**
361   * Sorts this list according to the order induced by the specified comparator
362   *
363   * @param { function } comparator - comparator
364   * comparator (required) A function that accepts up to two arguments.
365   * Specifies the sort order. Must be a function,return number type,If it returns firstValue
366   * minus secondValue, it returns an list sorted in ascending order;If it returns secondValue
367   * minus firstValue, it returns an list sorted in descending order;
368   * @throws { BusinessError } 401 - The type of parameters are invalid.
369   * @throws { BusinessError } 10200011 - The sort method cannot be bound.
370   * @syscap SystemCapability.Utils.Lang
371   * @since 8
372   */
373  /**
374   * Sorts this list according to the order induced by the specified comparator
375   *
376   * @param { function } comparator - comparator
377   * comparator (required) A function that accepts up to two arguments.
378   * Specifies the sort order. Must be a function,return number type,If it returns firstValue
379   * minus secondValue, it returns an list sorted in ascending order;If it returns secondValue
380   * minus firstValue, it returns an list sorted in descending order;
381   * @throws { BusinessError } 401 - The type of parameters are invalid.
382   * @throws { BusinessError } 10200011 - The sort method cannot be bound.
383   * @syscap SystemCapability.Utils.Lang
384   * @crossplatform
385   * @since 10
386   */
387  sort(comparator: (firstValue: T, secondValue: T) => number): void;
388  /**
389   * Removes all of the elements from this list.The list will
390   * be empty after this call returns.length becomes 0
391   *
392   * @throws { BusinessError } 10200011 - The clear method cannot be bound.
393   * @syscap SystemCapability.Utils.Lang
394   * @since 8
395   */
396  /**
397   * Removes all of the elements from this list.The list will
398   * be empty after this call returns.length becomes 0
399   *
400   * @throws { BusinessError } 10200011 - The clear method cannot be bound.
401   * @syscap SystemCapability.Utils.Lang
402   * @crossplatform
403   * @since 10
404   */
405  clear(): void;
406  /**
407   * Returns a view of the portion of this list between the specified fromIndex,inclusive,and toIndex,exclusive
408   *
409   * @param { number } fromIndex - fromIndex fromIndex The starting position of the index, containing the value at that index position
410   * @param { number } toIndex - toIndex toIndex the end of the index, excluding the value at that index
411   * @returns { List<T> }
412   * @throws { BusinessError } 10200011 - The getSubList method cannot be bound.
413   * @throws { BusinessError } 10200001 - The value of fromIndex or toIndex is out of range.
414   * @throws { BusinessError } 401 - The type of parameters are invalid.
415   * @syscap SystemCapability.Utils.Lang
416   * @since 8
417   */
418  /**
419   * Returns a view of the portion of this list between the specified fromIndex,inclusive,and toIndex,exclusive
420   *
421   * @param { number } fromIndex - fromIndex fromIndex The starting position of the index, containing the value at that index position
422   * @param { number } toIndex - toIndex toIndex the end of the index, excluding the value at that index
423   * @returns { List<T> }
424   * @throws { BusinessError } 10200011 - The getSubList method cannot be bound.
425   * @throws { BusinessError } 10200001 - The value of fromIndex or toIndex is out of range.
426   * @throws { BusinessError } 401 - The type of parameters are invalid.
427   * @syscap SystemCapability.Utils.Lang
428   * @crossplatform
429   * @since 10
430   */
431  getSubList(fromIndex: number, toIndex: number): List<T>;
432  /**
433   * Replaces each element of this list with the result of applying the operator to that element.
434   *
435   * @param { function } callbackFn - callbackFn
436   * callbackFn (required) A function that accepts up to four arguments.
437   * The function to be called for each element in the list,Returns the result of an operation
438   * @param { Object } thisArg - thisArg thisArg (Optional) The value passed to the function generally uses the "this" value.
439   * If this parameter is empty, "undefined" will be passed to the "this" value
440   * @throws { BusinessError } 10200011 - The replaceAllElements method cannot be bound.
441   * @throws { BusinessError } 401 - The type of parameters are invalid.
442   * @syscap SystemCapability.Utils.Lang
443   * @since 8
444   */
445  /**
446   * Replaces each element of this list with the result of applying the operator to that element.
447   *
448   * @param { function } callbackFn - callbackFn
449   * callbackFn (required) A function that accepts up to four arguments.
450   * The function to be called for each element in the list,Returns the result of an operation
451   * @param { Object } thisArg - thisArg thisArg (Optional) The value passed to the function generally uses the "this" value.
452   * If this parameter is empty, "undefined" will be passed to the "this" value
453   * @throws { BusinessError } 10200011 - The replaceAllElements method cannot be bound.
454   * @throws { BusinessError } 401 - The type of parameters are invalid.
455   * @syscap SystemCapability.Utils.Lang
456   * @crossplatform
457   * @since 10
458   */
459  replaceAllElements(callbackFn: (value: T, index?: number, list?: List<T>) => T, thisArg?: Object): void;
460  /**
461   * convert list to array
462   *
463   * @returns { Array<T> } the Array type
464   * @throws { BusinessError } 10200011 - The convertToArray method cannot be bound.
465   * @syscap SystemCapability.Utils.Lang
466   * @since 8
467   */
468  /**
469   * convert list to array
470   *
471   * @returns { Array<T> } the Array type
472   * @throws { BusinessError } 10200011 - The convertToArray method cannot be bound.
473   * @syscap SystemCapability.Utils.Lang
474   * @crossplatform
475   * @since 10
476   */
477  convertToArray(): Array<T>;
478  /**
479   * Determine whether list is empty and whether there is an element
480   *
481   * @returns { boolean } the boolean type
482   * @throws { BusinessError } 10200011 - The isEmpty method cannot be bound.
483   * @syscap SystemCapability.Utils.Lang
484   * @since 8
485   */
486  /**
487   * Determine whether list is empty and whether there is an element
488   *
489   * @returns { boolean } the boolean type
490   * @throws { BusinessError } 10200011 - The isEmpty method cannot be bound.
491   * @syscap SystemCapability.Utils.Lang
492   * @crossplatform
493   * @since 10
494   */
495  isEmpty(): boolean;
496  /**
497   * returns an iterator.Each item of the iterator is a Javascript Object
498   *
499   * @returns { IterableIterator<T> }
500   * @throws { BusinessError } 10200011 - The Symbol.iterator method cannot be bound.
501   * @syscap SystemCapability.Utils.Lang
502   * @since 8
503   */
504  /**
505   * returns an iterator.Each item of the iterator is a Javascript Object
506   *
507   * @returns { IterableIterator<T> }
508   * @throws { BusinessError } 10200011 - The Symbol.iterator method cannot be bound.
509   * @syscap SystemCapability.Utils.Lang
510   * @crossplatform
511   * @since 10
512   */
513  [Symbol.iterator](): IterableIterator<T>;
514}
515
516export default List;
517