• 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 * @syscap SystemCapability.Utils.Lang
18 * @since 8
19 * @deprecated since 9
20 * @useinstead ohos.util.ArrayList
21 */
22declare class Vector<T> {
23  /**
24   * A constructor used to create a Vector object.
25   * @since 8
26   * @syscap SystemCapability.Utils.Lang
27   */
28  constructor();
29  /**
30   * Gets the element number of the Vector. This is a number one higher than the highest index in the vector.
31   * @since 8
32   * @syscap SystemCapability.Utils.Lang
33   */
34  length: number;
35  /**
36   * Appends the specified element to the end of this vector.
37   * @param element to be appended to this vector
38   * @returns the boolean type, returns true if the addition is successful, and returns false if it fails.
39   * @since 8
40   * @syscap SystemCapability.Utils.Lang
41   */
42  add(element: T): boolean;
43  /**
44   * Inserts the specified element at the specified position in this
45   * vector. Shifts the element currently at that position (if any) and
46   * any subsequent elements to the right (adds one to their index).
47   * @param index index at which the specified element is to be inserted
48   * @param element element to be inserted
49   * @throws If index is greater than or equal to length, or less than 0, an exception is thrown and cannot be inserted
50   * @since 8
51   * @syscap SystemCapability.Utils.Lang
52   */
53  insert(element: T, index: number): void;
54  /**
55   * Check if vector contains the specified element
56   * @param element element to be contained
57   * @returns the boolean type,if vector contains the specified element,return true,else return false
58   * @since 8
59   * @syscap SystemCapability.Utils.Lang
60   */
61  has(element: T): boolean;
62  /**
63   * Returns the element at the specified position in this Vector,or returns undefined if vector is empty
64   * @param element element to be contained
65   * @returns the number type ,returns the lowest index such that or -1 if there is no such index.
66   * @since 8
67   * @syscap SystemCapability.Utils.Lang
68   */
69  get(index: number): T;
70  /**
71   * Returns the index of the first occurrence of the specified element
72   * in this vector, or -1 if this vector does not contain the element.
73   * @param element current index
74   * @returns the number type
75   * @since 8
76   * @syscap SystemCapability.Utils.Lang
77   */
78  getIndexOf(element: T): number;
79  /**
80   * Returns the first component (the item at index 0) of this vector.
81   * or returns undefined if vector is empty
82   * @returns the T type ,returns undefined if vector is empty
83   * @since 8
84   * @syscap SystemCapability.Utils.Lang
85   */
86  getFirstElement(): T;
87  /**
88   * Returns the Last component (the item at index length-1) of this vector.
89   * or returns undefined if vector is empty
90   * @returns the T type ,returns undefined if vector is empty
91   * @since 8
92   * @syscap SystemCapability.Utils.Lang
93   */
94  getLastElement(): T;
95  /**
96   * Find the corresponding element according to the index,
97   * delete the element, and move the index of all elements to the right of the element forward by one.
98   * @param index the index in the vector
99   * @returns the T type ,returns undefined if vector is empty,If the index is
100   * out of bounds (greater than or equal to length or less than 0), throw an exception
101   * @since 8
102   * @syscap SystemCapability.Utils.Lang
103   */
104  removeByIndex(index: number): T;
105  /**
106   * Removes the first occurrence of the specified element from this vector,
107   * if it is present.  If the vector does not contain the element, it is
108   * unchanged.  More formally, removes the element with the lowest index
109   * @param element element to remove
110   * @returns the boolean type ,If there is no such element, return false
111   * @since 8
112   * @syscap SystemCapability.Utils.Lang
113   */
114  remove(element: T): boolean;
115  /**
116   * Replaces the element at the specified position in this Vector with the specified element
117   * @param element replaced element
118   * @param index index to find
119   * @returns the T type
120   * @since 8
121   * @syscap SystemCapability.Utils.Lang
122   */
123  set(index: number, element: T): T;
124  /**
125   * Returns in the index of the last occurrence of the specified element in this vector ,
126   * or -1 if the vector does not contain the element.
127   * @param element element to find
128   * @returns the number type
129   * @since 8
130   * @syscap SystemCapability.Utils.Lang
131   */
132  getLastIndexOf(element: T): number;
133  /**
134   * Returns the index of the last occurrence of the specified element in this vector ,searching backwards from index,
135   * or returns -1 if the element is not found,or -1 if there is no such index
136   * @param element element to find
137   * @param index start index
138   * @returns the number type
139   * @since 8
140   * @syscap SystemCapability.Utils.Lang
141   */
142  getLastIndexFrom(element: T, index: number): number;
143  /**
144   * Returns the index of the first occurrence of the specified element in this vector ,searching forwards from index,
145   * or returns -1 if the element is not found,or -1 if there is no such index
146   * @param element element to find
147   * @param index start index
148   * @returns the number type
149   * @since 8
150   * @syscap SystemCapability.Utils.Lang
151   */
152  getIndexFrom(element: T, index: number): number;
153  /**
154   * Removes from this vector all of the elements whose index is between fromIndex,inclusive,and toIndex ,exclusive.
155   * @param fromIndex The starting position of the index, containing the value at that index position
156   * @param toIndex the end of the index, excluding the value at that index
157   * @throws If the fromIndex is out of range (greater than or equal to length or less than 0),
158   *  or if toIndex is less than fromIndex, an IndexOutOfBoundException is thrown
159   * @since 8
160   * @syscap SystemCapability.Utils.Lang
161   */
162  removeByRange(fromIndex: number, toIndex: number): void;
163  /**
164   * Replaces each element of this vector with the result of applying the operator to that element.
165   * @param callbackFn (required) A function that accepts up to four arguments.The function to be called
166   * for each element in the vector,Returns the result of an operation
167   * @param Value (required) current element
168   * @param Index (Optional) The index value of the current element.
169   * @param vector (Optional) The vector object to which the current element belongs.
170   * @param thisArg (Optional) The value passed to the function generally uses the "this" value.
171   * If this parameter is empty, "undefined" will be passed to the "this" value
172   * @since 8
173   * @syscap SystemCapability.Utils.Lang
174   */
175  replaceAllElements(callbackFn: (value: T, index?: number, vector?: Vector<T>) => T,
176  thisArg?: Object): void;
177  /**
178   * Executes a provided function once for each value in the vector object.
179   * @param callbackFn (required) A function that accepts up to four arguments.The function to be
180   * called for each element in the vector
181   * @param Value (required) current element
182   * @param Index (Optional) The index value of the current element.
183   * @param vector (Optional) The vector object to which the current element belongs.
184   * @param thisArg (Optional) The value passed to the function generally uses the "this" value.
185   * If this parameter is empty, "undefined" will be passed to the "this" value
186   * @since 8
187   * @syscap SystemCapability.Utils.Lang
188   */
189  forEach(callbackFn: (value: T, index?: number, vector?: Vector<T>) => void,
190  thisArg?: Object): void;
191  /**
192   * Sorts this vector according to the order induced by the specified comparator,without comparator
193   * this parameter, it will default to ASCII sorting
194   * @param comparator (Optional) A function that accepts up to two arguments.Specifies the sort order.
195   * Must be a function,return number type,If it returns firstValue minus secondValue, it returns an vector sorted
196   * in ascending order;If it returns secondValue minus firstValue, it returns an vector sorted in descending order;
197   * @param firstValue (Optional) previous element
198   * @param secondValue (Optional) next elements
199   * If this parameter is empty, it will default to ASCII sorting
200   * @since 8
201   * @syscap SystemCapability.Utils.Lang
202   */
203  sort(comparator?: (firstValue: T, secondValue: T) => number): void;
204  /**
205   * Returns a view of the portion of this vector between the specified fromIndex,inclusive,and toIndex,exclusive
206   * @param fromIndex The starting position of the index, containing the value at that index position
207   * @param toIndex the end of the index, excluding the value at that index
208   * @throws If the fromIndex or toIndex index is out of range (greater than or equal to length or less than 0),
209   * or if toIndex is less than fromIndex, an IndexOutOfBoundException is thrown
210   * @since 8
211   * @syscap SystemCapability.Utils.Lang
212   */
213  subVector(fromIndex: number, toIndex: number): Vector<T>;
214  /**
215   * Removes all of the elements from this vector.The vector will
216   * be empty after this call returns.length becomes 0
217   * @since 8
218   * @syscap SystemCapability.Utils.Lang
219   */
220  clear(): void;
221  /**
222   * Returns a shallow copy of this instance. (The elements themselves are not copied.)
223   * @returns this vector instance
224   * @since 8
225   * @syscap SystemCapability.Utils.Lang
226   */
227  clone(): Vector<T>;
228  /**
229   * Sets the length of this vector
230   * @since 8
231   * @syscap SystemCapability.Utils.Lang
232   */
233  setLength(newSize: number): void;
234  /**
235   * returns the capacity of this vector
236   * @returns the number type
237   * @since 8
238   * @syscap SystemCapability.Utils.Lang
239   */
240  getCapacity(): number;
241  /**
242   * convert vector to array
243   * @returns the Array type
244   * @since 8
245   * @syscap SystemCapability.Utils.Lang
246   */
247  convertToArray(): Array<T>;
248  /**
249   * Determine whether vector is empty and whether there is an element
250   * @returns the boolean type
251   * @since 8
252   * @syscap SystemCapability.Utils.Lang
253   */
254  isEmpty(): boolean;
255  /**
256   * If the newCapacity provided by the user is greater than or equal to length,
257   * change the capacity of the vector to newCapacity, otherwise the capacity will not be changed
258   * @since 8
259   * @syscap SystemCapability.Utils.Lang
260   */
261  increaseCapacityTo(newCapacity: number): void;
262  /**
263   * Returns a string representation of this Vector,
264   * containing the String representation of each element
265   * @since 8
266   * @syscap SystemCapability.Utils.Lang
267   */
268  toString(): string;
269  /**
270   * Limit the capacity to the current length
271   * @since 8
272   * @syscap SystemCapability.Utils.Lang
273   */
274  trimToCurrentLength(): void;
275  /**
276   * Copies the components of this vector into the specified array,
277   * to overwrite elements of the same index
278   * @param Array replaced array
279   * @since 8
280   * @syscap SystemCapability.Utils.Lang
281   */
282  copyToArray(array: Array<T>): void;
283  /**
284   * returns an ES6 iterator.Each item of the iterator is a Javascript Object
285   * @since 8
286   * @syscap SystemCapability.Utils.Lang
287   */
288  [Symbol.iterator](): IterableIterator<T>;
289}
290
291export default Vector;
292