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 16declare class List<T> { 17 /** 18 * A constructor used to create a List object. 19 * @throws { BusinessError } 10200012 - The List's constructor cannot be directly invoked. 20 * @since 8 21 * @syscap SystemCapability.Utils.Lang 22 */ 23 constructor(); 24 /** 25 * Gets the element number of the List. This is a number one higher than the highest index in the list. 26 * @since 8 27 * @syscap SystemCapability.Utils.Lang 28 */ 29 length: number; 30 /** 31 * Appends the specified element to the end of this list. 32 * @param element to be appended to this list 33 * @returns the boolean type, returns true if the addition is successful, and returns false if it fails. 34 * @throws { BusinessError } 10200011 - The add method cannot be bound. 35 * @since 8 36 * @syscap SystemCapability.Utils.Lang 37 */ 38 add(element: T): boolean; 39 /** 40 * Inserts the specified element at the specified position in this list. 41 * @param index index at which the specified element is to be inserted 42 * @param element element to be inserted 43 * @throws { BusinessError } 10200011 - The insert method cannot be bound. 44 * @throws { BusinessError } 10200001 - The value of index is out of range. 45 * @throws { BusinessError } 401 - The type of parameters are invalid. 46 * @since 8 47 * @syscap SystemCapability.Utils.Lang 48 */ 49 insert(element: T, index: number): void; 50 /** 51 * Returns the element at the specified position in this list, 52 * or returns undefined if this list is empty 53 * @param index specified position 54 * @returns the T type 55 * @throws { BusinessError } 10200011 - The get method cannot be bound. 56 * @throws { BusinessError } 401 - The type of parameters are invalid. 57 * @since 8 58 * @syscap SystemCapability.Utils.Lang 59 */ 60 get(index: number): T; 61 /** 62 * Check if list contains the specified element 63 * @param element element to be contained 64 * @returns the boolean type,if list contains the specified element,return true,else return false 65 * @throws { BusinessError } 10200011 - The has method cannot be bound. 66 * @since 8 67 * @syscap SystemCapability.Utils.Lang 68 */ 69 has(element: T): boolean; 70 /** 71 * Returns the index of the first occurrence of the specified element 72 * in this list, or -1 if this list does not contain the element. 73 * @param element element to be contained 74 * @returns the number type ,returns the lowest index such that or -1 if there is no such index. 75 * @throws { BusinessError } 10200011 - The getIndexOf method cannot be bound. 76 * @since 8 77 * @syscap SystemCapability.Utils.Lang 78 */ 79 getIndexOf(element: T): number; 80 /** 81 * Find the corresponding element according to the index, 82 * @param index the index in the list 83 * @returns the T type ,returns undefined if list is empty,If the index is 84 * out of bounds (greater than or equal to length or less than 0), throw an exception 85 * @throws { BusinessError } 10200011 - The removeByIndex method cannot be bound. 86 * @throws { BusinessError } 10200001 - The value of index is out of range. 87 * @throws { BusinessError } 401 - The type of parameters are invalid. 88 * @since 8 89 * @syscap SystemCapability.Utils.Lang 90 */ 91 removeByIndex(index: number): T; 92 /** 93 * Removes the first occurrence of the specified element from this list, 94 * if it is present. If the list does not contain the element, it is 95 * unchanged. More formally, removes the element with the lowest index 96 * @param element element to remove 97 * @returns the boolean type ,If there is no such element, return false 98 * @throws { BusinessError } 10200011 - The remove method cannot be bound. 99 * @since 8 100 * @syscap SystemCapability.Utils.Lang 101 */ 102 remove(element: T): boolean; 103 /** 104 * Returns in the index of the last occurrence of the specified element in this list , 105 * or -1 if the list does not contain the element. 106 * @param element element to find 107 * @returns the number type 108 * @throws { BusinessError } 10200011 - The getLastIndexOf method cannot be bound. 109 * @since 8 110 * @syscap SystemCapability.Utils.Lang 111 */ 112 getLastIndexOf(element: T): number; 113 /** 114 * Returns the first element (the item at index 0) of this list. 115 * or returns undefined if list is empty 116 * @returns the T type ,returns undefined if list is empty 117 * @throws { BusinessError } 10200011 - The getFirst method cannot be bound. 118 * @since 8 119 * @syscap SystemCapability.Utils.Lang 120 */ 121 getFirst(): T; 122 /** 123 * Returns the Last element (the item at index length-1) of this list. 124 * or returns undefined if list is empty 125 * @returns the T type ,returns undefined if list is empty 126 * @throws { BusinessError } 10200011 - The getLast method cannot be bound. 127 * @since 8 128 * @syscap SystemCapability.Utils.Lang 129 */ 130 getLast(): T; 131 /** 132 * Replaces the element at the specified position in this List with the specified element 133 * @param element replaced element 134 * @param index index to find 135 * @returns the T type 136 * @throws { BusinessError } 10200011 - The set method cannot be bound. 137 * @throws { BusinessError } 10200001 - The value of index is out of range. 138 * @throws { BusinessError } 401 - The type of parameters are invalid. 139 * @since 8 140 * @syscap SystemCapability.Utils.Lang 141 */ 142 set(index: number, element: T): T; 143 /** 144 * Compares the specified object with this list for equality.if the object are the same as this list 145 * return true, otherwise return false. 146 * @param obj Compare objects 147 * @returns the boolean type 148 * @throws { BusinessError } 10200011 - The equal method cannot be bound. 149 * @since 8 150 * @syscap SystemCapability.Utils.Lang 151 */ 152 equal(obj: Object): boolean; 153 /** 154 * Replaces each element of this list with the result of applying the operator to that element. 155 * @param callbackFn (required) A function that accepts up to four arguments. 156 * The function to be called for each element in the list,Returns the result of an operation 157 * @param Value (required) current element 158 * @param Index (Optional) The index value of the current element. 159 * @param List (Optional) The list object to which the current element belongs. 160 * @param thisArg (Optional) The value passed to the function generally uses the "this" value. 161 * If this parameter is empty, "undefined" will be passed to the "this" value 162 * @throws { BusinessError } 10200011 - The forEach method cannot be bound. 163 * @throws { BusinessError } 401 - The type of parameters are invalid. 164 * @since 8 165 * @syscap SystemCapability.Utils.Lang 166 */ 167 forEach(callbackFn: (value: T, index?: number, List?: List<T>) => void, 168 thisArg?: Object): void; 169 /** 170 * Sorts this list according to the order induced by the specified comparator 171 * @param comparator (required) A function that accepts up to two arguments. 172 * Specifies the sort order. Must be a function,return number type,If it returns firstValue 173 * minus secondValue, it returns an list sorted in ascending order;If it returns secondValue 174 * minus firstValue, it returns an list sorted in descending order; 175 * @param firstValue (Optional) previous element 176 * @param secondValue (Optional) next elements 177 * @throws { BusinessError } 401 - The type of parameters are invalid. 178 * @throws { BusinessError } 10200011 - The sort method cannot be bound. 179 * @since 8 180 * @syscap SystemCapability.Utils.Lang 181 */ 182 sort(comparator: (firstValue: T, secondValue: T) => number): void; 183 /** 184 * Removes all of the elements from this list.The list will 185 * be empty after this call returns.length becomes 0 186 * @throws { BusinessError } 10200011 - The clear method cannot be bound. 187 * @since 8 188 * @syscap SystemCapability.Utils.Lang 189 */ 190 clear(): void; 191 /** 192 * Returns a view of the portion of this list between the specified fromIndex,inclusive,and toIndex,exclusive 193 * @param fromIndex The starting position of the index, containing the value at that index position 194 * @param toIndex the end of the index, excluding the value at that index 195 * @throws { BusinessError } 10200011 - The getSubList method cannot be bound. 196 * @throws { BusinessError } 10200001 - The value of fromIndex or toIndex is out of range. 197 * @throws { BusinessError } 401 - The type of parameters are invalid. 198 * @since 8 199 * @syscap SystemCapability.Utils.Lang 200 */ 201 getSubList(fromIndex: number, toIndex: number): List<T>; 202 /** 203 * Replaces each element of this list with the result of applying the operator to that element. 204 * @param callbackFn (required) A function that accepts up to four arguments. 205 * The function to be called for each element in the list,Returns the result of an operation 206 * @param Value (required) current element 207 * @param Index (Optional) The index value of the current element. 208 * @param list (Optional) The list object to which the current element belongs. 209 * @param thisArg (Optional) The value passed to the function generally uses the "this" value. 210 * If this parameter is empty, "undefined" will be passed to the "this" value 211 * @throws { BusinessError } 10200011 - The replaceAllElements method cannot be bound. 212 * @throws { BusinessError } 401 - The type of parameters are invalid. 213 * @since 8 214 * @syscap SystemCapability.Utils.Lang 215 */ 216 replaceAllElements(callbackFn: (value: T, index?: number, list?: List<T>) => T, 217 thisArg?: Object): void; 218 /** 219 * convert list to array 220 * @returns the Array type 221 * @throws { BusinessError } 10200011 - The convertToArray method cannot be bound. 222 * @since 8 223 * @syscap SystemCapability.Utils.Lang 224 */ 225 convertToArray(): Array<T>; 226 /** 227 * Determine whether list is empty and whether there is an element 228 * @returns the boolean type 229 * @throws { BusinessError } 10200011 - The isEmpty method cannot be bound. 230 * @since 8 231 * @syscap SystemCapability.Utils.Lang 232 */ 233 isEmpty(): boolean; 234 /** 235 * returns an iterator.Each item of the iterator is a Javascript Object 236 * @throws { BusinessError } 10200011 - The Symbol.iterator method cannot be bound. 237 * @since 8 238 * @syscap SystemCapability.Utils.Lang 239 */ 240 [Symbol.iterator](): IterableIterator<T>; 241} 242 243export default List; 244