• 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
16declare class TreeMap<K, V> {
17
18  /**
19   * A constructor used to create a TreeMap object.
20   * @param comparator (Optional) User-defined comparison functions
21   * @param firstValue (Optional) previous element
22   * @param secondValue (Optional) next element
23   * @throws { BusinessError } 10200012 - The TreeMap's constructor cannot be directly invoked.
24   * @throws { BusinessError } 401 - The type of parameters are invalid.
25   * @since 8
26   * @syscap SystemCapability.Utils.Lang
27   */
28  constructor(comparator?: (firstValue: K, secondValue: K) => boolean);
29  /**
30   * Gets the element number of the hashmap.
31   * @since 8
32   * @syscap SystemCapability.Utils.Lang
33   */
34  length: number;
35  /**
36   * Returns whether the Map object contains elements
37   * @returns the boolean type
38   * @throws { BusinessError } 10200011 - The isEmpty method cannot be bound.
39   * @since 8
40   * @syscap SystemCapability.Utils.Lang
41   */
42  isEmpty(): boolean;
43  /**
44   * Returns whether a key is contained in this map
45   * @param key need to determine whether to include the key
46   * @returns the boolean type
47   * @throws { BusinessError } 10200011 - The hasKey method cannot be bound.
48   * @since 8
49   * @syscap SystemCapability.Utils.Lang
50   */
51  hasKey(key: K): boolean;
52  /**
53   * Returns whether a value is contained in this map
54   * @param value need to determine whether to include the value
55   * @returns the boolean type
56   * @throws { BusinessError } 10200011 - The hasValue method cannot be bound.
57   * @since 8
58   * @syscap SystemCapability.Utils.Lang
59   */
60  hasValue(value: V): boolean;
61  /**
62   * Returns a specified element in a Map object, or null if there is no corresponding element
63   * @param key the index in TreeMap
64   * @returns value or null
65   * @throws { BusinessError } 10200011 - The get method cannot be bound.
66   * @since 8
67   * @syscap SystemCapability.Utils.Lang
68   */
69  get(key: K): V;
70  /**
71   * Obtains the first sorted key in the treemap.
72   * Or returns undefined if tree map is empty
73   * @returns value or undefined
74   * @throws { BusinessError } 10200011 - The getFirstKey method cannot be bound.
75   * @since 8
76   * @syscap SystemCapability.Utils.Lang
77   */
78  getFirstKey(): K;
79  /**
80   * Obtains the last sorted key in the treemap.
81   * Or returns undefined if tree map is empty
82   * @returns value or undefined
83   * @throws { BusinessError } 10200011 - The getLastKey method cannot be bound.
84   * @since 8
85   * @syscap SystemCapability.Utils.Lang
86   */
87  getLastKey(): K;
88  /**
89   * Adds all element groups in one map to another map
90   * @param map the Map object to add members
91   * @throws { BusinessError } 10200011 - The setAll method cannot be bound.
92   * @throws { BusinessError } 401 - The type of parameters are invalid.
93   * @since 8
94   * @syscap SystemCapability.Utils.Lang
95   */
96  setAll(map: TreeMap<K, V>): void;
97  /**
98   * Adds or updates a(new) key-value pair with a key and value specified for the Map object
99   * @param key Added or updated targets
100   * @param value Added or updated value
101   * @returns the map object after set
102   * @throws { BusinessError } 10200011 - The set method cannot be bound.
103   * @throws { BusinessError } 401 - The type of parameters are invalid.
104   * @since 8
105   * @syscap SystemCapability.Utils.Lang
106   */
107  set(key: K, value: V): Object;
108  /**
109   * Remove a specified element from a Map object
110   * @param key  Target to be deleted
111   * @throws { BusinessError } 10200011 - The remove method cannot be bound.
112   * @returns Target mapped value
113   * @since 8
114   * @syscap SystemCapability.Utils.Lang
115   */
116  remove(key: K): V;
117  /**
118   * Clear all element groups in the map
119   * @throws { BusinessError } 10200011 - The clear method cannot be bound.
120   * @since 8
121   * @syscap SystemCapability.Utils.Lang
122   */
123  clear(): void;
124  /**
125   * Returns the greatest element smaller than or equal to the specified key
126   * if the key does not exist, undefined is returned
127   * @param key Objective of comparison
128   * @throws { BusinessError } 10200011 - The getLowerKey method cannot be bound.
129   * @returns key or undefined
130   * @since 8
131   * @syscap SystemCapability.Utils.Lang
132   */
133  getLowerKey(key: K): K;
134  /**
135   * Returns the least element greater than or equal to the specified key
136   * if the key does not exist, undefined is returned
137   * @param key Objective of comparison
138   * @returns key or undefined
139   * @throws { BusinessError } 10200011 - The getHigherKey method cannot be bound.
140   * @since 8
141   * @syscap SystemCapability.Utils.Lang
142   */
143  getHigherKey(key: K): K;
144  /**
145   * Returns a new Iterator object that contains the keys contained in this map
146   * @throws { BusinessError } 10200011 - The keys method cannot be bound.
147   * @since 8
148   * @syscap SystemCapability.Utils.Lang
149   */
150  keys(): IterableIterator<K>;
151  /**
152   * Returns a new Iterator object that contains the values contained in this map
153   * @throws { BusinessError } 10200011 - The values method cannot be bound.
154   * @since 8
155   * @syscap SystemCapability.Utils.Lang
156   */
157  values(): IterableIterator<V>;
158  /**
159   * Replace the old value by new value corresponding to the specified key
160   * @param key Updated targets
161   * @param value Updated the target mapped value
162   * @returns the boolean type(Is there a target pointed to by the key)
163   * @throws { BusinessError } 10200011 - The replace method cannot be bound.
164   * @since 8
165   * @syscap SystemCapability.Utils.Lang
166   */
167  replace(key: K, newValue: V): boolean;
168  /**
169   * Executes the given callback function once for each real key in the map.
170   * It does not perform functions on deleted keys
171   * @throws { BusinessError } 10200011 - The forEach method cannot be bound.
172   * @throws { BusinessError } 401 - The type of parameters are invalid.
173   * @since 8
174   * @syscap SystemCapability.Utils.Lang
175   */
176  forEach(callbackFn: (value?: V, key?: K, map?: TreeMap<K, V>) => void,
177  thisArg?: Object): void;
178  /**
179   * Returns a new Iterator object that contains the [key, value] pairs for each element in the Map object in insertion order
180   * @throws { BusinessError } 10200011 - The entries method cannot be bound.
181   * @since 8
182   * @syscap SystemCapability.Utils.Lang
183   */
184  entries(): IterableIterator<[K, V]>;
185  /**
186   * returns an ES6 iterator.Each item of the iterator is a Javascript Object
187   * @throws { BusinessError } 10200011 - The Symbol.iterator method cannot be bound.
188   * @since 8
189   * @syscap SystemCapability.Utils.Lang
190   */
191  [Symbol.iterator](): IterableIterator<[K, V]>;
192}
193
194export default TreeMap;