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