• 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 * @file
18 * @kit ArkTS
19 */
20
21/**
22 * Stack is implemented based on the array data structure.
23 * It follows the principle Last Out First In (LOFI) and supports data insertion and removal at one end.
24 *
25 * @syscap SystemCapability.Utils.Lang
26 * @since 8
27 */
28/**
29 * Stack is implemented based on the array data structure.
30 * It follows the principle Last Out First In (LOFI) and supports data insertion and removal at one end.
31 *
32 * @syscap SystemCapability.Utils.Lang
33 * @crossplatform
34 * @since 10
35 */
36/**
37 * Stack is implemented based on the array data structure.
38 * It follows the principle Last Out First In (LOFI) and supports data insertion and removal at one end.
39 *
40 * @syscap SystemCapability.Utils.Lang
41 * @crossplatform
42 * @atomicservice
43 * @since arkts {'1.1':'12', '1.2':'20'}
44 * @arkts 1.1&1.2
45 */
46declare class Stack<T> {
47  /**
48   * A constructor used to create a Stack object.
49   *
50   * @throws { BusinessError } 10200012 - The Stack's constructor cannot be directly invoked.
51   * @syscap SystemCapability.Utils.Lang
52   * @since 8
53   */
54  /**
55   * A constructor used to create a Stack object.
56   *
57   * @throws { BusinessError } 10200012 - The Stack's constructor cannot be directly invoked.
58   * @syscap SystemCapability.Utils.Lang
59   * @crossplatform
60   * @since 10
61   */
62  /**
63   * A constructor used to create a Stack object.
64   *
65   * @throws { BusinessError } 10200012 - The Stack's constructor cannot be directly invoked.
66   * @syscap SystemCapability.Utils.Lang
67   * @crossplatform
68   * @atomicservice
69   * @since arkts {'1.1':'12', '1.2':'20'}
70   * @arkts 1.1&1.2
71   */
72  constructor();
73  /**
74   * Gets the element number of the Stack. This is a number one higher than the highest index in the Stack.
75   *
76   * @type { number }
77   * @syscap SystemCapability.Utils.Lang
78   * @since 8
79   */
80  /**
81   * Gets the element number of the Stack. This is a number one higher than the highest index in the Stack.
82   *
83   * @type { number }
84   * @syscap SystemCapability.Utils.Lang
85   * @crossplatform
86   * @since 10
87   */
88  /**
89   * Gets the element number of the Stack. This is a number one higher than the highest index in the Stack.
90   *
91   * @type { number }
92   * @syscap SystemCapability.Utils.Lang
93   * @crossplatform
94   * @atomicservice
95   * @since 12
96   */
97  length: number;
98
99  /**
100   * Gets the element number of the Stack.
101   *
102   * @type { number }
103   * @syscap SystemCapability.Utils.Lang
104   * @crossplatform
105   * @atomicservice
106   * @since 20
107   * @arkts 1.2
108   */
109  get length(): number;
110
111  /**
112   * Tests if this stack is empty
113   *
114   * @returns { boolean } the boolean type
115   * @throws { BusinessError } 10200011 - The isEmpty method cannot be bound.
116   * @syscap SystemCapability.Utils.Lang
117   * @since 8
118   */
119  /**
120   * Tests if this stack is empty
121   *
122   * @returns { boolean } the boolean type
123   * @throws { BusinessError } 10200011 - The isEmpty method cannot be bound.
124   * @syscap SystemCapability.Utils.Lang
125   * @crossplatform
126   * @since 10
127   */
128  /**
129   * Tests if this stack is empty
130   *
131   * @returns { boolean } the boolean type
132   * @throws { BusinessError } 10200011 - The isEmpty method cannot be bound.
133   * @syscap SystemCapability.Utils.Lang
134   * @crossplatform
135   * @atomicservice
136   * @since arkts {'1.1':'12', '1.2':'20'}
137   * @arkts 1.1&1.2
138   */
139  isEmpty(): boolean;
140  /**
141   * Looks at the object at the top of this stack without removing it from the stack
142   * Return undefined if this stack is empty
143   *
144   * @returns { T } the top value or undefined
145   * @throws { BusinessError } 10200011 - The peek method cannot be bound.
146   * @syscap SystemCapability.Utils.Lang
147   * @since 8
148   */
149  /**
150   * Looks at the object at the top of this stack without removing it from the stack
151   * Return undefined if this stack is empty
152   *
153   * @returns { T } the top value or undefined
154   * @throws { BusinessError } 10200011 - The peek method cannot be bound.
155   * @syscap SystemCapability.Utils.Lang
156   * @crossplatform
157   * @since 10
158   */
159  /**
160   * Looks at the object at the top of this stack without removing it from the stack
161   * Return undefined if this stack is empty
162   *
163   * @returns { T } the top value or undefined
164   * @throws { BusinessError } 10200011 - The peek method cannot be bound.
165   * @syscap SystemCapability.Utils.Lang
166   * @crossplatform
167   * @atomicservice
168   * @since 12
169   */
170  peek(): T;
171
172  /**
173   * Looks at the object at the top of this stack without removing it from the stack
174   * Return undefined if this stack is empty
175   *
176   * @returns { T | undefined } the top value, or undefined if container is empty
177   * @syscap SystemCapability.Utils.Lang
178   * @crossplatform
179   * @atomicservice
180   * @since 20
181   * @arkts 1.2
182   */
183  peek(): T | undefined;
184
185  /**
186   * Removes the object at the top of this stack and returns that object as the value of this function
187   * an exception if the stack is empty
188   *
189   * @returns { T } Stack top value or undefined
190   * @throws { BusinessError } 10200011 - The pop method cannot be bound.
191   * @syscap SystemCapability.Utils.Lang
192   * @since 8
193   */
194  /**
195   * Removes the object at the top of this stack and returns that object as the value of this function
196   * an exception if the stack is empty
197   *
198   * @returns { T } Stack top value or undefined
199   * @throws { BusinessError } 10200011 - The pop method cannot be bound.
200   * @syscap SystemCapability.Utils.Lang
201   * @crossplatform
202   * @since 10
203   */
204  /**
205   * Removes the object at the top of this stack and returns that object as the value of this function
206   * an exception if the stack is empty
207   *
208   * @returns { T } Stack top value or undefined
209   * @throws { BusinessError } 10200011 - The pop method cannot be bound.
210   * @syscap SystemCapability.Utils.Lang
211   * @crossplatform
212   * @atomicservice
213   * @since 12
214   */
215  pop(): T;
216
217  /**
218   * Removes the object at the top of this stack and returns that object as the value of this function
219   * an exception if the stack is empty
220   *
221   * @returns { T | undefined } Stack top value, or undefined if container is empty
222   * @syscap SystemCapability.Utils.Lang
223   * @crossplatform
224   * @atomicservice
225   * @since 20
226   * @arkts 1.2
227   */
228  pop(): T | undefined;
229
230  /**
231   * Pushes an item onto the top of this stack
232   *
233   * @param { T } item - item item to be appended to this Stack
234   * @returns { T } the T type
235   * @throws { BusinessError } 10200011 - The push method cannot be bound.
236   * @syscap SystemCapability.Utils.Lang
237   * @since 8
238   */
239  /**
240   * Pushes an item onto the top of this stack
241   *
242   * @param { T } item - item item to be appended to this Stack
243   * @returns { T } the T type
244   * @throws { BusinessError } 10200011 - The push method cannot be bound.
245   * @syscap SystemCapability.Utils.Lang
246   * @crossplatform
247   * @since 10
248   */
249  /**
250   * Pushes an item onto the top of this stack
251   *
252   * @param { T } item - item item to be appended to this Stack
253   * @returns { T } the T type
254   * @throws { BusinessError } 10200011 - The push method cannot be bound.
255   * @syscap SystemCapability.Utils.Lang
256   * @crossplatform
257   * @atomicservice
258   * @since arkts {'1.1':'12', '1.2':'20'}
259   * @arkts 1.1&1.2
260   */
261  push(item: T): T;
262  /**
263   * Returns the 1-based position where an object is on this stack
264   *
265   * @param { T } element - element element Target to be deleted
266   * @returns { number } the T type,If there is no such element, return -1
267   * @throws { BusinessError } 10200011 - The locate method cannot be bound.
268   * @syscap SystemCapability.Utils.Lang
269   * @since 8
270   */
271  /**
272   * Returns the 1-based position where an object is on this stack
273   *
274   * @param { T } element - element element Target to be deleted
275   * @returns { number } the T type,If there is no such element, return -1
276   * @throws { BusinessError } 10200011 - The locate method cannot be bound.
277   * @syscap SystemCapability.Utils.Lang
278   * @crossplatform
279   * @since 10
280   */
281  /**
282   * Returns the 1-based position where an object is on this stack
283   *
284   * @param { T } element - element element Target to be deleted
285   * @returns { number } the T type,If there is no such element, return -1
286   * @throws { BusinessError } 10200011 - The locate method cannot be bound.
287   * @syscap SystemCapability.Utils.Lang
288   * @crossplatform
289   * @atomicservice
290   * @since arkts {'1.1':'12', '1.2':'20'}
291   * @arkts 1.1&1.2
292   */
293  locate(element: T): number;
294  /**
295   * Executes a provided function once for each value in the Stack object.
296   *
297   * @param { function } callbackFn - callbackFn
298   * callbackFn (required) A function that accepts up to three arguments.
299   * The function to be called for each element.
300   * @param { Object } [thisArg] - thisArg
301   * thisArg (Optional) The value to be used as this value for when callbackFn is called.
302   * If thisArg is omitted, undefined is used as the this value.
303   * @throws { BusinessError } 10200011 - The forEach method cannot be bound.
304   * @throws { BusinessError } 401 - Parameter error. Possible causes:
305   * 1.Mandatory parameters are left unspecified;
306   * 2.Incorrect parameter types.
307   * @syscap SystemCapability.Utils.Lang
308   * @since 8
309   */
310  /**
311   * Executes a provided function once for each value in the Stack object.
312   *
313   * @param { function } callbackFn - callbackFn
314   * callbackFn (required) A function that accepts up to three arguments.
315   * The function to be called for each element.
316   * @param { Object } [thisArg] - thisArg
317   * thisArg (Optional) The value to be used as this value for when callbackFn is called.
318   * If thisArg is omitted, undefined is used as the this value.
319   * @throws { BusinessError } 10200011 - The forEach method cannot be bound.
320   * @throws { BusinessError } 401 - Parameter error. Possible causes:
321   * 1.Mandatory parameters are left unspecified;
322   * 2.Incorrect parameter types.
323   * @syscap SystemCapability.Utils.Lang
324   * @crossplatform
325   * @since 10
326   */
327  /**
328   * Executes a provided function once for each value in the Stack object.
329   *
330   * @param { function } callbackFn - callbackFn
331   * callbackFn (required) A function that accepts up to three arguments.
332   * The function to be called for each element.
333   * @param { Object } [thisArg] - thisArg
334   * thisArg (Optional) The value to be used as this value for when callbackFn is called.
335   * If thisArg is omitted, undefined is used as the this value.
336   * @throws { BusinessError } 10200011 - The forEach method cannot be bound.
337   * @throws { BusinessError } 401 - Parameter error. Possible causes:
338   * 1.Mandatory parameters are left unspecified;
339   * 2.Incorrect parameter types.
340   * @syscap SystemCapability.Utils.Lang
341   * @crossplatform
342   * @atomicservice
343   * @since 12
344   */
345  forEach(callbackFn: (value: T, index?: number, stack?: Stack<T>) => void, thisArg?: Object): void;
346
347  /**
348   * Executes a provided function once for each value in the Stack object.
349   *
350   * @param { StackForEachCb } callbackFn - callbackFn
351   * @syscap SystemCapability.Utils.Lang
352   * @crossplatform
353   * @atomicservice
354   * @since 20
355   * @arkts 1.2
356   */
357  forEach(callbackfn: StackForEachCb<T>): void;
358
359  /**
360   * returns an ES6 iterator.Each item of the iterator is a Javascript Object
361   *
362   * @returns { IterableIterator<T> }
363   * @throws { BusinessError } 10200011 - The Symbol.iterator method cannot be bound.
364   * @syscap SystemCapability.Utils.Lang
365   * @since 8
366   */
367  /**
368   * returns an ES6 iterator.Each item of the iterator is a Javascript Object
369   *
370   * @returns { IterableIterator<T> }
371   * @throws { BusinessError } 10200011 - The Symbol.iterator method cannot be bound.
372   * @syscap SystemCapability.Utils.Lang
373   * @crossplatform
374   * @since 10
375   */
376  /**
377   * returns an ES6 iterator.Each item of the iterator is a Javascript Object
378   *
379   * @returns { IterableIterator<T> }
380   * @throws { BusinessError } 10200011 - The Symbol.iterator method cannot be bound.
381   * @syscap SystemCapability.Utils.Lang
382   * @crossplatform
383   * @atomicservice
384   * @since 12
385   */
386  [Symbol.iterator](): IterableIterator<T>;
387
388  /**
389   * returns an iterator. Each item of the iterator is a ArkTS Object
390   *
391   * @returns { IterableIterator<T> }
392   * @syscap SystemCapability.Utils.Lang
393   * @crossplatform
394   * @atomicservice
395   * @since 20
396   * @arkts 1.2
397   */
398  $_iterator(): IterableIterator<T>;
399
400}
401
402/**
403 * The type of Stack callback function.
404 *
405 * @typedef { function } StackForEachCb
406 * @param { T } value - The value of current element
407 * @param { number } index - The key of current element
408 * @param { Stack<T> } stack - The Stack instance being traversed
409 * @returns { void } This callback does not return a value
410 * @syscap SystemCapability.Utils.Lang
411 * @atomicservice
412 * @since 20
413 * @arkts 1.2
414 */
415type StackForEachCb<T> = (value: T, index: number, stack: Stack<T>) => void
416
417export default Stack;
418