• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.util (util工具函数)
2
3该模块主要提供常用的工具函数,实现字符串编解码([TextEncoder](#textencoder),[TextDecoder](#textdecoder))、有理数运算([RationalNumber<sup>8+</sup>](#rationalnumber8))、缓冲区管理([LRUCache<sup>9+</sup>](#lrucache9))、范围判断([ScopeHelper<sup>9+</sup>](#scopehelper9))、Base64编解码([Base64Helper<sup>9+</sup>](#base64helper9))、内置对象类型检查([types<sup>8+</sup>](#types8))等功能。
4
5> **说明:**
6>
7> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8
9
10## 导入模块
11
12```ts
13import util from '@ohos.util';
14```
15
16## util.format<sup>9+</sup>
17
18format(format: string,  ...args: Object[]): string
19
20通过式样化字符串对输入的内容按特定格式输出。
21
22**系统能力:** SystemCapability.Utils.Lang
23
24**参数:**
25
26| 参数名  | 类型     | 必填 | 说明           |
27| ------- | -------- | ---- | -------------- |
28| format  | string   | 是   | 式样化字符串。 |
29| ...args | Object[] | 否   | 替换式样化字符串通配符的数据,此参数缺失时,默认返回第一个参数。 |
30
31**返回值:**
32
33| 类型   | 说明                         |
34| ------ | ---------------------------- |
35| string | 按特定格式式样化后的字符串。 |
36
37**示例:**
38
39  ```ts
40  let res = util.format("This is : %s", "hello world!");
41  console.log(res);
42  ```
43
44## util.errnoToString<sup>9+</sup>
45
46errnoToString(errno: number): string
47
48获取系统错误码对应的详细信息。
49
50**系统能力:** SystemCapability.Utils.Lang
51
52**参数:**
53
54| 参数名 | 类型   | 必填 | 说明                       |
55| ------ | ------ | ---- | -------------------------- |
56| errno  | number | 是   | 系统发生错误产生的错误码。 |
57
58**返回值:**
59
60| 类型   | 说明                   |
61| ------ | ---------------------- |
62| string | 错误码对应的详细信息。 |
63
64**示例:**
65
66```ts
67  let errnum = -1; // -1 : a system error number
68  let result = util.errnoToString(errnum);
69  console.log("result = " + result);
70```
71
72**部分错误码及信息示例:**
73
74| 错误码 | 信息                              |
75| ------ | -------------------------------- |
76| -1     | operation not permitted          |
77| -2     | no such file or directory        |
78| -3     | no such process                  |
79| -4     | interrupted system call          |
80| -5     | i/o error                        |
81| -11    | resource temporarily unavailable |
82| -12    | not enough memory                |
83| -13    | permission denied                |
84| -100   | network is down                  |
85
86## util.callbackWrapper
87
88callbackWrapper(original: Function): (err: Object, value: Object )=&gt;void
89
90对异步函数进行回调化处理,回调中第一个参数将是拒绝原因(如果 Promise 已解决,则为 null),第二个参数将是已解决的值。
91
92**系统能力:** SystemCapability.Utils.Lang
93
94**参数:**
95
96| 参数名 | 类型 | 必填 | 说明 |
97| -------- | -------- | -------- | -------- |
98| original | Function | 是 | 异步函数。 |
99
100**返回值:**
101
102| 类型 | 说明 |
103| -------- | -------- |
104| Function | 返回一个第一个参数是拒绝原因(如果&nbsp;Promise&nbsp;已解决,则为&nbsp;null),第二个参数是已解决的回调函数。 |
105
106**示例:**
107
108  ```ts
109  async function fn() {
110    return 'hello world';
111  }
112  let cb = util.callbackWrapper(fn);
113  cb(1, (err : Object, ret : string) => {
114    if (err) throw new Error;
115    console.log(ret);
116  });
117  ```
118
119## util.promisify<sup>9+</sup>
120
121promisify(original: (err: Object, value: Object) =&gt; void): Function
122
123对异步函数处理并返回一个promise的函数。
124
125**系统能力:** SystemCapability.Utils.Lang
126
127**参数:**
128
129| 参数名 | 类型 | 必填 | 说明 |
130| -------- | -------- | -------- | -------- |
131| original | Function | 是 | 异步函数。 |
132
133**返回值:**
134
135| 类型 | 说明 |
136| -------- | -------- |
137| Function | 采用遵循常见的错误优先的回调风格的函数(也就是将&nbsp;(err,&nbsp;value)&nbsp;=&gt;&nbsp;...&nbsp;回调作为最后一个参数),并返回一个返回&nbsp;promise&nbsp;的函数。 |
138
139**示例:**
140
141  ```ts
142  function fun(num, callback) {
143    if (typeof num === 'number') {
144        callback(null, num + 3);
145    } else {
146        callback("type err");
147    }
148  }
149
150  const addCall = util.promisify(fun);
151  (async () => {
152    try {
153        let res = await addCall(2);
154        console.log(res);
155    } catch (err) {
156        console.log(err);
157    }
158  })();
159  ```
160
161## util.generateRandomUUID<sup>9+</sup>
162
163generateRandomUUID(entropyCache?: boolean): string
164
165使用加密安全随机数生成器生成随机的RFC 4122版本4的string类型UUID。
166
167**系统能力:** SystemCapability.Utils.Lang
168
169**参数:**
170
171| 参数名 | 类型 | 必填 | 说明 |
172| -------- | -------- | -------- | -------- |
173| entropyCache | boolean | 否 | 是否使用已缓存的UUID, 默认true。 |
174
175**返回值:**
176
177| 类型 | 说明 |
178| -------- | -------- |
179| string | 表示此UUID的字符串。 |
180
181**示例:**
182
183  ```ts
184  let uuid = util.generateRandomUUID(true);
185  console.log("RFC 4122 Version 4 UUID:" + uuid);
186  // 输出:
187  // RFC 4122 Version 4 UUID:88368f2a-d5db-47d8-a05f-534fab0a0045
188  ```
189
190## util.generateRandomBinaryUUID<sup>9+</sup>
191
192generateRandomBinaryUUID(entropyCache?: boolean): Uint8Array
193
194使用加密安全随机数生成器生成随机的RFC 4122版本4的Uint8Array类型UUID。
195
196**系统能力:** SystemCapability.Utils.Lang
197
198**参数:**
199
200| 参数名 | 类型 | 必填 | 说明 |
201| -------- | -------- | -------- | -------- |
202| entropyCache | boolean | 否 | 是否使用已缓存的UUID, 默认true。 |
203
204**返回值:**
205
206| 类型 | 说明 |
207| -------- | -------- |
208| Uint8Array | 表示此UUID的Uint8Array值。 |
209
210**示例:**
211
212  ```ts
213  let uuid = util.generateRandomBinaryUUID(true);
214  console.log(JSON.stringify(uuid));
215  // 输出:
216  // 138,188,43,243,62,254,70,119,130,20,235,222,199,164,140,150
217  ```
218
219## util.parseUUID<sup>9+</sup>
220
221parseUUID(uuid: string): Uint8Array
222
223将generateRandomUUID生成的string类型UUID转换为generateRandomBinaryUUID生成的Uint8Array类型UUID,如RFC 4122版本4中所述。
224
225**系统能力:** SystemCapability.Utils.Lang
226
227**参数:**
228
229| 参数名 | 类型 | 必填 | 说明 |
230| -------- | -------- | -------- | -------- |
231| uuid | string | 是 | UUID字符串。 |
232
233**返回值:**
234
235| 类型 | 说明 |
236| -------- | -------- |
237| Uint8Array | 返回表示此UUID的Uint8Array,如果解析失败,则抛出SyntaxError。 |
238
239**示例:**
240
241  ```ts
242  let uuid = util.parseUUID("84bdf796-66cc-4655-9b89-d6218d100f9c");
243  console.log(JSON.stringify(uuid));
244  // 输出:
245  // 132,189,247,150,102,204,70,85,155,137,214,33,141,16,15,156
246  ```
247
248## util.printf<sup>(deprecated)</sup>
249
250printf(format: string,  ...args: Object[]): string
251
252通过式样化字符串对输入的内容按特定格式输出。
253
254> **说明:**
255>
256> 从API version 7开始支持,从API version 9开始废弃,建议使用[util.format<sup>9+</sup>](#utilformat9)替代。
257
258**系统能力:** SystemCapability.Utils.Lang
259
260**参数:**
261
262| 参数名 | 类型 | 必填 | 说明 |
263| -------- | -------- | -------- | -------- |
264| format | string | 是 | 式样化字符串。 |
265| ...args | Object[] | 否 | 替换式样化字符串通配符的数据,此参数缺失时,默认返回第一个参数。 |
266
267**返回值:**
268
269| 类型 | 说明 |
270| -------- | -------- |
271| string | 按特定格式式样化后的字符串。 |
272
273**示例:**
274
275  ```ts
276  let res = util.printf("%s", "hello world!");
277  console.log(res);
278  ```
279
280
281## util.getErrorString<sup>(deprecated)</sup>
282
283getErrorString(errno: number): string
284
285获取系统错误码对应的详细信息。
286
287> **说明:**
288>
289> 从API version 7开始支持,从API version 9开始废弃,建议使用[util.errnoToString<sup>9+</sup>](#utilerrnotostring9)替代。
290
291**系统能力:** SystemCapability.Utils.Lang
292
293**参数:**
294
295| 参数名 | 类型 | 必填 | 说明 |
296| -------- | -------- | -------- | -------- |
297| errno | number | 是 | 系统发生错误产生的错误码。 |
298
299**返回值:**
300
301| 类型 | 说明 |
302| -------- | -------- |
303| string | 错误码对应的详细信息。 |
304
305**示例:**
306
307  ```ts
308  let errnum = -1; // -1 : a system error number
309  let result = util.getErrorString(errnum);
310  console.log("result = " + result);
311  ```
312
313## util.promiseWrapper<sup>(deprecated)</sup>
314
315promiseWrapper(original: (err: Object, value: Object) =&gt; void): Object
316
317对异步函数处理并返回一个promise的版本。
318
319> **说明:**
320>
321> 此接口不可用,建议使用[util.promisify<sup>9+</sup>](#utilpromisify9)替代。
322
323**系统能力:** SystemCapability.Utils.Lang
324
325**参数:**
326
327| 参数名 | 类型 | 必填 | 说明 |
328| -------- | -------- | -------- | -------- |
329| original | Function | 是 | 异步函数。 |
330
331**返回值:**
332
333| 类型 | 说明 |
334| -------- | -------- |
335| Function | 采用遵循常见的错误优先的回调风格的函数(也就是将&nbsp;(err,&nbsp;value)&nbsp;=&gt;&nbsp;...&nbsp;回调作为最后一个参数),并返回一个返回&nbsp;promise&nbsp;的版本。 |
336
337
338## TextDecoder
339
340TextDecoder用于将字节数组解码为字符串,可以处理多种编码格式,包括utf-8、utf-16le/be、iso-8859和windows-1251等不同的编码格式。
341
342### 属性
343
344**系统能力:** 以下各项对应的系统能力均为SystemCapability.Utils.Lang345
346| 名称 | 类型 | 可读 | 可写 | 说明 |
347| -------- | -------- | -------- | -------- | -------- |
348| encoding | string | 是 | 否 | 编码格式。<br/>-&nbsp;支持格式:utf-8、ibm866、iso-8859-2、iso-8859-3、iso-8859-4、iso-8859-5、iso-8859-6、iso-8859-7、iso-8859-8、iso-8859-8-i、iso-8859-10、iso-8859-13、iso-8859-14、iso-8859-15、koi8-r、koi8-u、macintosh、windows-874、windows-1250、windows-1251、windows-1252、windows-1253、windows-1254、windows-1255、windows-1256、windows-1257、windows-1258、x-mac-cyrilli、gbk、gb18030、big5、euc-jp、iso-2022-jp、shift_jis、euc-kr、utf-16be、utf-16le。 |
349| fatal | boolean | 是 | 否 | 是否显示致命错误。 |
350| ignoreBOM | boolean | 是 | 否 | 是否忽略BOM(byte&nbsp;order&nbsp;marker)标记,默认值为false&nbsp;,表示解码结果包含BOM标记。 |
351
352### constructor<sup>9+</sup>
353
354constructor()
355
356TextDecoder的构造函数。
357
358**系统能力:** SystemCapability.Utils.Lang
359
360### create<sup>9+</sup>
361
362create(encoding?: string,options?: { fatal?: boolean; ignoreBOM?: boolean }): TextDecoder;
363
364替代有参构造功能。
365
366**系统能力:** SystemCapability.Utils.Lang
367
368**参数:**
369
370| 参数名   | 类型   | 必填 | 说明                                             |
371| -------- | ------ | ---- | ------------------------------------------------ |
372| encoding | string | 否   | 编码格式,默认值是'utf-8'。                      |
373| options  | Object | 否   | 编码相关选项参数,存在两个属性fatal和ignoreBOM。 |
374
375**表1.1**options
376
377| 名称      | 参数类型 | 必填 | 说明               |
378| --------- | -------- | ---- | ------------------ |
379| fatal     | boolean  | 否   | 是否显示致命错误,默认值是false。 |
380| ignoreBOM | boolean  | 否   | 是否忽略BOM标记,默认值是false。  |
381
382**示例:**
383
384```ts
385  let result = util.TextDecoder.create('utf-8', { ignoreBOM : true })
386  let retStr = result.encoding
387```
388
389### decodeWithStream<sup>9+</sup>
390
391decodeWithStream(input: Uint8Array, options?: { stream?: boolean }): string
392
393通过输入参数解码后输出对应文本。
394
395**系统能力:** SystemCapability.Utils.Lang
396
397**参数:**
398
399| 参数名 | 类型 | 必填 | 说明 |
400| -------- | -------- | -------- | -------- |
401| input | Uint8Array | 是 | 符合格式需要解码的数组。 |
402| options | Object | 否 | 解码相关选项参数。 |
403
404**表2** options
405
406| 名称 | 参数类型 | 必填 | 说明 |
407| -------- | -------- | -------- | -------- |
408| stream | boolean | 否 | 在随后的decodeWithStream()调用中是否跟随附加数据块。如果以块的形式处理数据,则设置为true;如果处理最后的数据块或数据未分块,则设置为false。默认为false。 |
409
410**返回值:**
411
412| 类型 | 说明 |
413| -------- | -------- |
414| string | 解码后的数据。 |
415
416**示例:**
417
418  ```ts
419  let textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true});
420  let result = new Uint8Array(6);
421  result[0] = 0xEF;
422  result[1] = 0xBB;
423  result[2] = 0xBF;
424  result[3] = 0x61;
425  result[4] = 0x62;
426  result[5] = 0x63;
427  console.log("input num:");
428  let retStr = textDecoder.decodeWithStream( result , {stream: false});
429  console.log("retStr = " + retStr);
430  ```
431
432### constructor<sup>(deprecated)</sup>
433
434constructor(encoding?: string, options?: { fatal?: boolean; ignoreBOM?: boolean })
435
436TextDecoder的构造函数。
437
438> **说明:**
439>
440> 从API version 7开始支持,从API version 9开始废弃,建议使用[create<sup>9+</sup>](#create9)替代。
441
442**系统能力:** SystemCapability.Utils.Lang
443
444**参数:**
445
446| 参数名 | 类型 | 必填 | 说明 |
447| -------- | -------- | -------- | -------- |
448| encoding | string | 否 | 编码格式,默认值是'utf-8'。 |
449| options | Object | 否 | 编码相关选项参数,存在两个属性fatal和ignoreBOM。 |
450
451  **表1** options
452
453| 名称 | 参数类型 | 必填 | 说明 |
454| -------- | -------- | -------- | -------- |
455| fatal | boolean | 否 | 是否显示致命错误,默认值是false。 |
456| ignoreBOM | boolean | 否 | 是否忽略BOM标记,默认值是false。 |
457
458**示例:**
459
460  ```ts
461  let textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true});
462  ```
463
464### decode<sup>(deprecated)</sup>
465
466decode(input: Uint8Array, options?: { stream?: false }): string
467
468通过输入参数解码后输出对应文本。
469
470> **说明:**
471>
472> 从API version 7开始支持,从API version 9开始废弃,建议使用[decodeWithStream<sup>9+</sup>](#decodewithstream9)替代。
473
474**系统能力:** SystemCapability.Utils.Lang
475
476**参数:**
477
478| 参数名 | 类型 | 必填 | 说明 |
479| -------- | -------- | -------- | -------- |
480| input | Uint8Array | 是 | 符合格式需要解码的数组。 |
481| options | Object | 否 | 解码相关选项参数。 |
482
483**表2** options
484
485| 名称 | 参数类型 | 必填 | 说明 |
486| -------- | -------- | -------- | -------- |
487| stream | boolean | 否 | 在随后的decode()调用中是否跟随附加数据块。如果以块的形式处理数据,则设置为true;如果处理最后的数据块或数据未分块,则设置为false。默认为false。 |
488
489**返回值:**
490
491| 类型 | 说明 |
492| -------- | -------- |
493| string | 解码后的数据。 |
494
495**示例:**
496
497  ```ts
498  let textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true});
499  let result = new Uint8Array(6);
500  result[0] = 0xEF;
501  result[1] = 0xBB;
502  result[2] = 0xBF;
503  result[3] = 0x61;
504  result[4] = 0x62;
505  result[5] = 0x63;
506  console.log("input num:");
507  let retStr = textDecoder.decode( result , {stream: false});
508  console.log("retStr = " + retStr);
509  ```
510
511## TextEncoder
512
513TextEncoder用于将字符串编码为字节数组,支持多种编码格式,包括utf-8、utf-16le/be等。需要注意的是,在使用TextEncoder进行编码时,不同编码格式下字符所占的字节数是不同的。例如,utf-8编码下中文字符通常占3个字节,而utf-16le/be编码下中文字符通常占2个字节。因此,在使用TextEncoder时需要明确指定要使用的编码格式,以确保编码结果正确。
514
515### 属性
516
517**系统能力:** 以下各项对应的系统能力均为SystemCapability.Utils.Lang518
519| 名称 | 类型 | 可读 | 可写 | 说明 |
520| -------- | -------- | -------- | -------- | -------- |
521| encoding | string | 是 | 否 | 编码格式,默认值是'utf-8'。 |
522
523
524### constructor
525
526constructor()
527
528TextEncoder的构造函数。
529
530**系统能力:** SystemCapability.Utils.Lang
531
532**示例:**
533
534  ```ts
535  let textEncoder = new util.TextEncoder();
536  ```
537
538### constructor<sup>9+</sup>
539
540constructor(encoding?: string)
541
542TextEncoder的构造函数。
543
544**系统能力:** SystemCapability.Utils.Lang
545
546**参数:**
547
548| 参数名 | 类型 | 必填 | 说明 |
549| ----- | ---- | ---- | ---- |
550| encoding | string | 否 | 编码格式,默认值为'utf-8'。 |
551
552**示例:**
553
554  ```ts
555  let textEncoder = new util.TextEncoder("utf-8");
556  ```
557
558### encodeInto<sup>9+</sup>
559
560encodeInto(input?: string): Uint8Array
561
562通过输入参数编码后输出对应文本。
563
564**系统能力:** SystemCapability.Utils.Lang
565
566**参数:**
567
568| 参数名 | 类型   | 必填 | 说明               |
569| ------ | ------ | ---- | ------------------ |
570| input  | string | 否   | 需要编码的字符串,默认值是空字符串。 |
571
572**返回值:**
573
574| 类型       | 说明               |
575| ---------- | ------------------ |
576| Uint8Array | 返回编码后的文本。 |
577
578**示例:**
579
580  ```ts
581  let textEncoder = new util.TextEncoder();
582  let buffer = new ArrayBuffer(20);
583  let result = new Uint8Array(buffer);
584  result = textEncoder.encodeInto("\uD800¥¥");
585  ```
586
587### encodeIntoUint8Array<sup>9+</sup>
588
589encodeIntoUint8Array(input: string, dest: Uint8Array): { read: number; written: number }
590
591放置生成的UTF-8编码文本。
592
593**系统能力:** SystemCapability.Utils.Lang
594
595**参数:**
596
597| 参数名 | 类型       | 必填 | 说明                                                    |
598| ------ | ---------- | ---- | ------------------------------------------------------- |
599| input  | string     | 是   | 需要编码的字符串。                                      |
600| dest   | Uint8Array | 是   | Uint8Array对象实例,用于将生成的UTF-8编码文本放入其中。 |
601
602**返回值:**
603
604| 类型       | 说明               |
605| ---------- | ------------------ |
606| Uint8Array | 返回编码后的文本。 |
607
608**示例:**
609
610  ```ts
611  let that = new util.TextEncoder()
612  let buffer = new ArrayBuffer(4)
613  let dest = new Uint8Array(buffer)
614  let result = new Object()
615  result = that.encodeIntoUint8Array('abcd', dest)
616  ```
617
618### encodeInto<sup>(deprecated)</sup>
619
620encodeInto(input: string, dest: Uint8Array): { read: number; written: number }
621
622放置生成的UTF-8编码文本。
623
624> **说明:**
625>
626> 从API version 7开始支持,从API version 9开始废弃,建议使用[encodeIntoUint8Array<sup>9+</sup>](#encodeintouint8array9)替代。
627
628**系统能力:** SystemCapability.Utils.Lang
629
630**参数:**
631
632| 参数名 | 类型 | 必填 | 说明 |
633| -------- | -------- | -------- | -------- |
634| input | string | 是 | 需要编码的字符串。 |
635| dest | Uint8Array | 是 | Uint8Array对象实例,用于将生成的UTF-8编码文本放入其中。 |
636
637**返回值:**
638
639| 类型 | 说明 |
640| -------- | -------- |
641| Uint8Array | 返回编码后的文本。 |
642
643**示例:**
644  ```ts
645  let that = new util.TextEncoder()
646  let buffer = new ArrayBuffer(4)
647  let dest = new Uint8Array(buffer)
648  let result = new Object()
649  result = that.encodeInto('abcd', dest)
650  ```
651
652### encode<sup>(deprecated)</sup>
653
654encode(input?: string): Uint8Array
655
656通过输入参数编码后输出对应文本。
657
658> **说明:**
659>
660> 从API version 7开始支持,从API version 9开始废弃,建议使用[encodeInto<sup>9+</sup>](#encodeinto9)替代。
661
662**系统能力:** SystemCapability.Utils.Lang
663
664**参数:**
665
666| 参数名 | 类型 | 必填 | 说明 |
667| -------- | -------- | -------- | -------- |
668| input | string | 否 | 需要编码的字符串,默认值是空字符串。 |
669
670**返回值:**
671
672| 类型 | 说明 |
673| -------- | -------- |
674| Uint8Array | 返回编码后的文本。 |
675
676**示例:**
677  ```ts
678  let textEncoder = new util.TextEncoder();
679  let buffer = new ArrayBuffer(20);
680  let result = new Uint8Array(buffer);
681  result = textEncoder.encode("\uD800¥¥");
682  ```
683
684## RationalNumber<sup>8+</sup>
685
686RationalNumber主要是对有理数进行比较,获取分子分母等方法。例如使用toString()方法可以将有理数转换为字符串形式,使用该类可以方便地进行有理数的各种操作。
687
688### constructor<sup>9+</sup>
689
690constructor()
691
692RationalNumber的构造函数。
693
694**系统能力:** SystemCapability.Utils.Lang
695
696**示例:**
697
698```ts
699  let rationalNumber = new util.RationalNumber();
700```
701
702### parseRationalNumber<sup>9+</sup>
703
704parseRationalNumber(numerator: number,denominator: number): RationalNumber
705
706替代原有参构造的参数处理。
707
708**系统能力:** SystemCapability.Utils.Lang
709
710**参数:**
711
712| 参数名      | 类型   | 必填 | 说明             |
713| ----------- | ------ | ---- | ---------------- |
714| numerator   | number | 是   | 分子,整数类型。 |
715| denominator | number | 是   | 分母,整数类型。 |
716
717**示例:**
718
719```ts
720  let rationalNumber = util.RationalNumber.parseRationalNumber(1,2)
721```
722
723### createRationalFromString<sup>8+</sup>
724
725static createRationalFromString​(rationalString: string): RationalNumber​
726
727基于给定的字符串创建一个RationalNumber对象。
728
729**系统能力:** SystemCapability.Utils.Lang
730
731**参数:**
732
733| 参数名 | 类型 | 必填 | 说明 |
734| -------- | -------- | -------- | -------- |
735| rationalString | string | 是 | 字符串格式。 |
736
737**返回值:**
738
739| 类型 | 说明 |
740| -------- | -------- |
741| object | 返回有理数类的对象。 |
742
743**示例:**
744
745```ts
746  let rationalNumber = new util.RationalNumber(1,2);
747  let rational = util.RationalNumber.createRationalFromString("3/4");
748```
749
750### compare<sup>9+</sup>
751
752compare​(another: RationalNumber): number​
753
754将当前的RationalNumber对象与给定的对象进行比较。
755
756**系统能力:** SystemCapability.Utils.Lang
757
758**参数:**
759
760| 参数名  | 类型           | 必填 | 说明               |
761| ------- | -------------- | ---- | ------------------ |
762| another | RationalNumber | 是   | 其他的有理数对象。 |
763
764**返回值:**
765
766| 类型   | 说明                                                         |
767| ------ | ------------------------------------------------------------ |
768| number | 如果两个对象相等,则返回0;如果给定对象小于当前对象,则返回1;如果给定对象大于当前对象,则返回-1。 |
769
770**示例:**
771
772  ```ts
773  let rationalNumber = new util.RationalNumber(1,2);
774  let rational = util.RationalNumber.createRationalFromString("3/4");
775  let result = rationalNumber.compare(rational);
776  ```
777
778### valueOf<sup>8+</sup>
779
780valueOf(): number
781
782以整数形式或者浮点数的形式获取当前RationalNumber对象的值。
783
784**系统能力:** SystemCapability.Utils.Lang
785
786**返回值:**
787
788| 类型 | 说明 |
789| -------- | -------- |
790| number | 返回整数或者浮点数的值。 |
791
792**示例:**
793
794```ts
795  let rationalNumber = new util.RationalNumber(1,2);
796  let result = rationalNumber.valueOf();
797```
798
799### equals<sup>8+</sup>
800
801equals​(obj: Object): boolean
802
803将当前的RationalNumber对象与给定的对象进行比较是否相等。
804
805**系统能力:** SystemCapability.Utils.Lang
806
807**参数:**
808
809| 参数名 | 类型 | 必填 | 说明 |
810| -------- | -------- | -------- | -------- |
811| object | Object | 是 | 其他类型对象。 |
812
813**返回值:**
814
815| 类型 | 说明 |
816| -------- | -------- |
817| boolean | 如果给定对象与当前对象相同,则返回true;否则返回false。 |
818
819**示例:**
820
821```ts
822  let rationalNumber = new util.RationalNumber(1,2);
823  let rational = util.RationalNumber.createRationalFromString("3/4");
824  let result = rationalNumber.equals(rational);
825```
826
827### getCommonFactor<sup>9+</sup>
828
829getCommonFactor(number1: number,number2: number): number
830
831获取两个指定整数的最大公约数。
832
833**系统能力:** SystemCapability.Utils.Lang
834
835**参数:**
836
837| 参数名  | 类型   | 必填 | 说明       |
838| ------- | ------ | ---- | ---------- |
839| number1 | number | 是   | 整数类型。 |
840| number2 | number | 是   | 整数类型。 |
841
842**返回值:**
843
844| 类型   | 说明                           |
845| ------ | ------------------------------ |
846| number | 返回两个给定数字的最大公约数。 |
847
848**示例:**
849
850```ts
851let rationalNumber = new util.RationalNumber(1,2);
852let result = util.RationalNumber.getCommonFactor(4,6);
853```
854
855### getNumerator<sup>8+</sup>
856
857getNumerator​(): number
858
859获取当前RationalNumber对象的分子。
860
861**系统能力:** SystemCapability.Utils.Lang
862
863**返回值:**
864
865| 类型 | 说明 |
866| -------- | -------- |
867| number | 返回RationalNumber对象的分子的值。 |
868
869**示例:**
870
871```ts
872  let rationalNumber = new util.RationalNumber(1,2);
873  let result = rationalNumber.getNumerator();
874```
875
876### getDenominator<sup>8+</sup>
877
878getDenominator​(): number
879
880获取当前RationalNumber对象的分母。
881
882**系统能力:** SystemCapability.Utils.Lang
883
884**返回值:**
885
886| 类型 | 说明 |
887| -------- | -------- |
888| number | 返回RationalNumber对象的分母的值。 |
889
890**示例:**
891
892```ts
893  let rationalNumber = new util.RationalNumber(1,2);
894  let result = rationalNumber.getDenominator();
895```
896
897### isZero<sup>8+</sup>
898
899isZero​():boolean
900
901检查当前RationalNumber对象是否为0。
902
903**系统能力:** SystemCapability.Utils.Lang
904
905**返回值:**
906
907| 类型 | 说明 |
908| -------- | -------- |
909| boolean | 如果当前对象表示的值为0,则返回true;否则返回false。 |
910
911**示例:**
912
913```ts
914  let rationalNumber = new util.RationalNumber(1,2);
915  let result = rationalNumber.isZero();
916```
917
918### isNaN<sup>8+</sup>
919
920isNaN​(): boolean
921
922检查当前RationalNumber对象是否表示非数字(NaN)值。
923
924**系统能力:** SystemCapability.Utils.Lang
925
926**返回值:**
927
928| 类型 | 说明 |
929| -------- | -------- |
930| boolean | 如果分母和分子都为0,则返回true;否则返回false。 |
931
932**示例:**
933
934```ts
935  let rationalNumber = new util.RationalNumber(1,2);
936  let result = rationalNumber.isNaN();
937```
938
939### isFinite<sup>8+</sup>
940
941isFinite​():boolean
942
943检查当前RationalNumber对象是否表示一个有限值。
944
945**系统能力:** SystemCapability.Utils.Lang
946
947**返回值:**
948
949| 类型 | 说明 |
950| -------- | -------- |
951| boolean | 如果分母不为0,则返回true;否则返回false。 |
952
953**示例:**
954
955```ts
956  let rationalNumber = new util.RationalNumber(1,2);
957  let result = rationalNumber.isFinite();
958```
959
960### toString<sup>8+</sup>
961
962toString​(): string
963
964获取当前RationalNumber对象的字符串表示形式。
965
966**系统能力:** SystemCapability.Utils.Lang
967
968**返回值:**
969
970| 类型 | 说明 |
971| -------- | -------- |
972| string | 返回Numerator/Denominator格式的字符串,例如3/5,如果当前对象的分子和分母都为0,则返回NaN。 |
973
974**示例:**
975
976```ts
977  let rationalNumber = new util.RationalNumber(1,2);
978  let result = rationalNumber.toString();
979```
980
981### constructor<sup>(deprecated)</sup>
982
983constructor(numerator: number,denominator: number)
984
985RationalNumber的构造函数。
986
987> **说明:**
988>
989> 从API version 8开始支持,从API version 9开始废弃,建议使用[constructor<sup>9+</sup>](#constructor9)替代。
990
991**系统能力:** SystemCapability.Utils.Lang
992
993**参数:**
994
995| 参数名 | 类型 | 必填 | 说明 |
996| -------- | -------- | -------- | -------- |
997| numerator | number | 是 | 分子,整数类型。 |
998| denominator | number | 是 | 分母,整数类型。 |
999
1000**示例:**
1001
1002```ts
1003  let rationalNumber = new util.RationalNumber(1,2);
1004```
1005
1006### compareTo<sup>(deprecated)</sup>
1007
1008compareTo​(another: RationalNumber): number​
1009
1010将当前的RationalNumber对象与给定的对象进行比较。
1011
1012> **说明:**
1013>
1014> 从API version 8开始支持,从API version 9开始废弃,建议使用[compare<sup>9+</sup>](#compare9)替代。
1015
1016**系统能力:** SystemCapability.Utils.Lang
1017
1018**参数:**
1019
1020| 参数名 | 类型 | 必填 | 说明 |
1021| -------- | -------- | -------- | -------- |
1022| another | RationalNumber | 是 | 其他的有理数对象。 |
1023
1024**返回值:**
1025
1026| 类型 | 说明 |
1027| -------- | -------- |
1028| number | 如果两个对象相等,则返回0;如果给定对象小于当前对象,则返回1;如果给定对象大于当前对象,则返回-1。 |
1029
1030**示例:**
1031
1032```ts
1033  let rationalNumber = new util.RationalNumber(1,2);
1034  let rational = util.RationalNumber.createRationalFromString("3/4");
1035  let result = rationalNumber.compareTo(rational);
1036```
1037
1038### getCommonDivisor<sup>(deprecated)</sup>
1039
1040static getCommonDivisor​(number1: number,number2: number): number
1041
1042获取两个指定整数的最大公约数。
1043
1044> **说明:**
1045>
1046> 从API version 8开始支持,从API version 9开始废弃,建议使用[getCommonFactor<sup>9+</sup>](#getcommonfactor9)替代。
1047
1048**系统能力:** SystemCapability.Utils.Lang
1049
1050**参数:**
1051
1052| 参数名 | 类型 | 必填 | 说明 |
1053| -------- | -------- | -------- | -------- |
1054| number1 | number | 是 | 整数类型。 |
1055| number2 | number | 是 | 整数类型。 |
1056
1057**返回值:**
1058
1059| 类型 | 说明 |
1060| -------- | -------- |
1061| number | 返回两个给定数字的最大公约数。 |
1062
1063**示例:**
1064
1065```ts
1066  let rationalNumber = new util.RationalNumber(1,2);
1067  let result = util.RationalNumber.getCommonDivisor(4,6);
1068```
1069
1070## LRUCache<sup>9+</sup>
1071
1072LRUCache用于在缓存空间不够的时候,将近期最少使用的数据替换为新数据。此设计基于资源访问的考虑:近期访问的数据,可能在不久的将来会再次访问。于是最少访问的数据就是价值最小的数据,是最应该踢出缓存空间的数据。
1073
1074### 属性
1075
1076**系统能力:** 以下各项对应的系统能力均为SystemCapability.Utils.Lang1077
1078| 名称   | 类型   | 可读 | 可写 | 说明                   |
1079| ------ | ------ | ---- | ---- | ---------------------- |
1080| length | number | 是   | 否   | 当前缓冲区中值的总数。 |
1081
1082**示例:**
1083
1084```ts
1085  let  pro : util.LRUCache<number, number> = new util.LRUCache();
1086  pro.put(2,10);
1087  pro.put(1,8);
1088  let result = pro.length;
1089```
1090
1091### constructor<sup>9+</sup>
1092
1093constructor(capacity?: number)
1094
1095默认构造函数用于创建一个新的LruBuffer实例,默认容量为64。
1096
1097**系统能力:** SystemCapability.Utils.Lang
1098
1099**参数:**
1100
1101| 参数名   | 类型   | 必填 | 说明                         |
1102| -------- | ------ | ---- | ---------------------------- |
1103| capacity | number | 否   | 指示要为缓冲区自定义的容量,默认值为64。 |
1104
1105**示例:**
1106
1107```ts
1108  let lrubuffer : util.LRUCache<number, number> = new util.LRUCache();
1109```
1110
1111
1112### updateCapacity<sup>9+</sup>
1113
1114updateCapacity(newCapacity: number): void
1115
1116将缓冲区容量更新为指定容量,如果newCapacity小于或等于0,则抛出异常。
1117
1118**系统能力:** SystemCapability.Utils.Lang
1119
1120**参数:**
1121
1122| 参数名      | 类型   | 必填 | 说明                         |
1123| ----------- | ------ | ---- | ---------------------------- |
1124| newCapacity | number | 是   | 指示要为缓冲区自定义的容量。 |
1125
1126**示例:**
1127
1128```ts
1129  let pro : util.LRUCache<number,number>= new util.LRUCache();
1130  pro.updateCapacity(100);
1131```
1132
1133
1134### toString<sup>9+</sup>
1135
1136toString(): string
1137
1138返回对象的字符串表示形式。
1139
1140**系统能力:** SystemCapability.Utils.Lang
1141
1142**返回值:**
1143
1144| 类型   | 说明                       |
1145| ------ | -------------------------- |
1146| string | 返回对象的字符串表示形式。 |
1147
1148**示例:**
1149
1150```ts
1151  let pro : util.LRUCache<number,number> = new util.LRUCache();
1152  pro.put(2,10);
1153  pro.get(2);
1154  pro.remove(20);
1155  let result = pro.toString();
1156```
1157
1158
1159### getCapacity<sup>9+</sup>
1160
1161getCapacity(): number
1162
1163获取当前缓冲区的容量。
1164
1165**系统能力:** SystemCapability.Utils.Lang
1166
1167**返回值:**
1168
1169| 类型   | 说明                   |
1170| ------ | ---------------------- |
1171| number | 返回当前缓冲区的容量。 |
1172
1173**示例:**
1174
1175  ```ts
1176  let pro : util.LRUCache<number,number> = new util.LRUCache();
1177  let result = pro.getCapacity();
1178  ```
1179
1180
1181### clear<sup>9+</sup>
1182
1183clear(): void
1184
1185从当前缓冲区清除键值对。后续会调用afterRemoval()方法执行后续操作。
1186
1187**系统能力:** SystemCapability.Utils.Lang
1188
1189**示例:**
1190
1191  ```ts
1192  let pro : util.LRUCache<number,number> = new util.LRUCache();
1193  pro.put(2,10);
1194  let result = pro.length;
1195  pro.clear();
1196  ```
1197
1198
1199### getCreateCount<sup>9+</sup>
1200
1201getCreateCount(): number
1202
1203获取createDefault()返回值的次数。
1204
1205**系统能力:** SystemCapability.Utils.Lang
1206
1207**返回值:**
1208
1209| 类型   | 说明                              |
1210| ------ | --------------------------------- |
1211| number | 返回createDefault()返回值的次数。 |
1212
1213**示例:**
1214
1215  ```ts
1216  let pro : util.LRUCache<number,number> = new util.LRUCache();
1217  pro.put(1,8);
1218  let result = pro.getCreateCount();
1219  ```
1220
1221
1222### getMissCount<sup>9+</sup>
1223
1224getMissCount(): number
1225
1226获取查询值不匹配的次数。
1227
1228**系统能力:** SystemCapability.Utils.Lang
1229
1230**返回值:**
1231
1232| 类型   | 说明                     |
1233| ------ | ------------------------ |
1234| number | 返回查询值不匹配的次数。 |
1235
1236**示例:**
1237
1238  ```ts
1239  let pro : util.LRUCache<number,number> = new util.LRUCache();
1240  pro.put(2,10);
1241  pro.get(2);
1242  let result = pro.getMissCount();
1243  ```
1244
1245
1246### getRemovalCount<sup>9+</sup>
1247
1248getRemovalCount(): number
1249
1250获取从缓冲区中逐出值的次数。
1251
1252**系统能力:** SystemCapability.Utils.Lang
1253
1254**返回值:**
1255
1256| 类型   | 说明                       |
1257| ------ | -------------------------- |
1258| number | 返回从缓冲区中驱逐的次数。 |
1259
1260**示例:**
1261
1262  ```ts
1263  let pro : util.LRUCache<number,number> = new util.LRUCache();
1264  pro.put(2,10);
1265  pro.updateCapacity(2);
1266  pro.put(50,22);
1267  let result = pro.getRemovalCount();
1268  ```
1269
1270
1271### getMatchCount<sup>9+</sup>
1272
1273getMatchCount(): number
1274
1275获取查询值匹配成功的次数。
1276
1277**系统能力:** SystemCapability.Utils.Lang
1278
1279**返回值:**
1280
1281| 类型   | 说明                       |
1282| ------ | -------------------------- |
1283| number | 返回查询值匹配成功的次数。 |
1284
1285**示例:**
1286
1287  ```ts
1288  let pro : util.LRUCache<number,number> = new util.LRUCache();
1289  pro.put(2,10);
1290  pro.get(2);
1291  let result = pro.getMatchCount();
1292  ```
1293
1294
1295### getPutCount<sup>9+</sup>
1296
1297getPutCount(): number
1298
1299获取将值添加到缓冲区的次数。
1300
1301**系统能力:** SystemCapability.Utils.Lang
1302
1303**返回值:**
1304
1305| 类型   | 说明                         |
1306| ------ | ---------------------------- |
1307| number | 返回将值添加到缓冲区的次数。 |
1308
1309**示例:**
1310
1311  ```ts
1312  let pro : util.LRUCache<number,number> = new util.LRUCache();
1313  pro.put(2,10);
1314  let result = pro.getPutCount();
1315  ```
1316
1317
1318### isEmpty<sup>9+</sup>
1319
1320isEmpty(): boolean
1321
1322检查当前缓冲区是否为空。
1323
1324**系统能力:** SystemCapability.Utils.Lang
1325
1326**返回值:**
1327
1328| 类型    | 说明                                     |
1329| ------- | ---------------------------------------- |
1330| boolean | 如果当前缓冲区不包含任何值,则返回true。 |
1331
1332**示例:**
1333
1334  ```ts
1335  let pro : util.LRUCache<number,number> = new util.LRUCache();
1336  pro.put(2,10);
1337  let result = pro.isEmpty();
1338  ```
1339
1340
1341### get<sup>9+</sup>
1342
1343get(key: K): V | undefined
1344
1345表示要查询的键。
1346
1347**系统能力:** SystemCapability.Utils.Lang
1348
1349**参数:**
1350
1351| 参数名 | 类型 | 必填 | 说明         |
1352| ------ | ---- | ---- | ------------ |
1353| key    | K    | 是   | 要查询的键。 |
1354
1355**返回值:**
1356
1357| 类型                     | 说明                                                         |
1358| ------------------------ | ------------------------------------------------------------ |
1359| V \| undefined | 如果指定的键存在于缓冲区中,则返回与键关联的值;否则返回undefined。 |
1360
1361**示例:**
1362
1363  ```ts
1364  let pro : util.LRUCache<number,number> = new util.LRUCache();
1365  pro.put(2,10);
1366  let result  = pro.get(2);
1367  ```
1368
1369
1370### put<sup>9+</sup>
1371
1372put(key: K,value: V): V
1373
1374将键值对添加到缓冲区。
1375
1376**系统能力:** SystemCapability.Utils.Lang
1377
1378**参数:**
1379
1380| 参数名 | 类型 | 必填 | 说明                       |
1381| ------ | ---- | ---- | -------------------------- |
1382| key    | K    | 是   | 要添加的密钥。             |
1383| value  | V    | 是   | 指示与要添加的键关联的值。 |
1384
1385**返回值:**
1386
1387| 类型 | 说明                                                         |
1388| ---- | ------------------------------------------------------------ |
1389| V    | 返回与添加的键关联的值;如果要添加的键已经存在,则返回原始值,如果键或值为空,则抛出此异常。 |
1390
1391**示例:**
1392
1393  ```ts
1394  let pro : util.LRUCache<number,number> = new util.LRUCache();
1395  let result = pro.put(2,10);
1396  ```
1397
1398### values<sup>9+</sup>
1399
1400values(): V[]
1401
1402获取当前缓冲区中所有值从最近访问到最近最少访问的顺序列表 。
1403
1404**系统能力:** SystemCapability.Utils.Lang
1405
1406**返回值:**
1407
1408| 类型      | 说明                                                         |
1409| --------- | ------------------------------------------------------------ |
1410| V&nbsp;[] | 按从最近访问到最近最少访问的顺序返回当前缓冲区中所有值的列表。 |
1411
1412**示例:**
1413
1414  ```ts
1415  let pro : util.LRUCache<number|string,number|string> = new util.LRUCache();
1416  pro.put(2,10);
1417  pro.put(2,"anhu");
1418  pro.put("afaf","grfb");
1419  let result = pro.values();
1420  ```
1421
1422
1423### keys<sup>9+</sup>
1424
1425keys(): K[]
1426
1427获取当前缓冲区中所有键从最近访问到最近最少访问的升序列表。
1428
1429**系统能力:** SystemCapability.Utils.Lang
1430
1431**返回值:**
1432
1433| 类型      | 说明                                                         |
1434| --------- | ------------------------------------------------------------ |
1435| K&nbsp;[] | 按升序返回当前缓冲区中所有键的列表,从最近访问到最近最少访问。 |
1436
1437**示例:**
1438
1439  ```ts
1440  let pro : util.LRUCache<number,number>= new util.LRUCache();
1441  pro.put(2,10);
1442  let result = pro.keys();
1443  ```
1444
1445
1446### remove<sup>9+</sup>
1447
1448remove(key: K): V | undefined
1449
1450从当前缓冲区中删除指定的键及其关联的值。
1451
1452**系统能力:** SystemCapability.Utils.Lang
1453
1454**参数:**
1455
1456| 参数名 | 类型 | 必填 | 说明           |
1457| ------ | ---- | ---- | -------------- |
1458| key    | K    | 是   | 要删除的密钥。 |
1459
1460**返回值:**
1461
1462| 类型                     | 说明                                                         |
1463| ------------------------ | ------------------------------------------------------------ |
1464| V&nbsp;\|&nbsp;undefined | 返回一个包含已删除键值对的Optional对象;如果key不存在,则返回一个空的Optional对象,如果key为null,则抛出异常。 |
1465
1466**示例:**
1467
1468  ```ts
1469  let pro : util.LRUCache<number,number>= new util.LRUCache();
1470  pro.put(2,10);
1471  let result = pro.remove(20);
1472  ```
1473
1474
1475### afterRemoval<sup>9+</sup>
1476
1477afterRemoval(isEvict: boolean,key: K,value: V,newValue: V): void
1478
1479删除值后执行后续操作。
1480
1481**系统能力:** SystemCapability.Utils.Lang
1482
1483**参数:**
1484
1485| 参数名   | 类型    | 必填 | 说明                                                         |
1486| -------- | ------- | ---- | ------------------------------------------------------------ |
1487| isEvict  | boolean | 是   | 因容量不足而调用该方法时,参数值为true,其他情况为false。    |
1488| key      | K       | 是   | 表示删除的键。                                               |
1489| value    | V       | 是   | 表示删除的值。                                               |
1490| newValue | V       | 是   | 如果已调用put方法并且要添加的键已经存在,则参数值是关联的新值。其他情况下参数值为空。 |
1491
1492**示例:**
1493
1494  ```ts
1495  let arr : Object[] = [];
1496  class ChildLruBuffer<K, V> extends util.LRUCache<K, V> {
1497    constructor() {
1498      super();
1499    }
1500
1501    afterRemoval(isEvict: boolean, key: K, value: V, newValue: V) : void
1502    {
1503      if (isEvict === false) {
1504        arr = [key, value, newValue];
1505      }
1506    }
1507  }
1508  let lru : ChildLruBuffer<number,number|null>= new ChildLruBuffer();
1509  lru.afterRemoval(false,10,30,null);
1510  ```
1511
1512
1513### contains<sup>9+</sup>
1514
1515contains(key: K): boolean
1516
1517检查当前缓冲区是否包含指定的键。
1518
1519**系统能力:** SystemCapability.Utils.Lang
1520
1521**参数:**
1522
1523| 参数名 | 类型   | 必填 | 说明             |
1524| ------ | ------ | ---- | ---------------- |
1525| key    | K | 是   | 表示要检查的键。 |
1526
1527**返回值:**
1528
1529| 类型    | 说明                                       |
1530| ------- | ------------------------------------------ |
1531| boolean | 如果缓冲区包含指定的键,则返回&nbsp;true。 |
1532
1533**示例:**
1534
1535  ```ts
1536  let pro : util.LRUCache<number|object,number> = new util.LRUCache();
1537  pro.put(2,10);
1538  class Lru{
1539  s : string = ""
1540  }
1541  let obj : Lru = {s : "key" }
1542  let result = pro.contains(obj);
1543  ```
1544
1545
1546### createDefault<sup>9+</sup>
1547
1548createDefault(key: K): V
1549
1550如果未计算特定键的值,则执行后续操作,参数表示丢失的键,返回与键关联的值。
1551
1552**系统能力:** SystemCapability.Utils.Lang
1553
1554**参数:**
1555
1556| 参数名 | 类型 | 必填 | 说明           |
1557| ------ | ---- | ---- | -------------- |
1558| key    | K    | 是   | 表示丢失的键。 |
1559
1560**返回值:**
1561
1562| 类型 | 说明               |
1563| ---- | ------------------ |
1564| V    | 返回与键关联的值。 |
1565
1566**示例:**
1567
1568  ```ts
1569  let pro : util.LRUCache<number,number> = new util.LRUCache();
1570  let result = pro.createDefault(50);
1571  ```
1572
1573
1574### entries<sup>9+</sup>
1575
1576entries(): IterableIterator&lt;[K,V]&gt;
1577
1578允许迭代包含在这个对象中的所有键值对。
1579
1580**系统能力:** SystemCapability.Utils.Lang
1581
1582**返回值:**
1583
1584| 类型        | 说明                 |
1585| ----------- | -------------------- |
1586| [K,&nbsp;V] | 返回一个可迭代数组。 |
1587
1588**示例:**
1589
1590  ```ts
1591  let pro : util.LRUCache<number,number> = new util.LRUCache();
1592  pro.put(2,10);
1593  let result = pro.entries();
1594  ```
1595
1596### [Symbol.iterator]<sup>9+</sup>
1597
1598[Symbol.iterator]\(): IterableIterator&lt;[K, V]&gt;
1599
1600返回一个键值对形式的二维数组。
1601
1602**系统能力:** SystemCapability.Utils.Lang
1603
1604**返回值:**
1605
1606| 类型        | 说明                           |
1607| ----------- | ------------------------------ |
1608| [K,&nbsp;V] | 返回一个键值对形式的二维数组。 |
1609
1610**示例:**
1611
1612  ```ts
1613  let pro : util.LRUCache<number,number> = new util.LRUCache();
1614  pro.put(2,10);
1615  let result = pro[Symbol.iterator]();
1616  ```
1617
1618## ScopeComparable<sup>8+</sup>
1619
1620ScopeComparable类型的值需要实现compareTo方法,确保传入的数据具有可比性。
1621
1622**系统能力:** SystemCapability.Utils.Lang
1623
1624### compareTo<sup>8+</sup>
1625
1626compareTo(other: ScopeComparable): boolean;
1627
1628比较两个值的大小,返回一个布尔值。
1629
1630**系统能力:** SystemCapability.Utils.Lang
1631
1632**参数:**
1633
1634| 参数名 | 类型 | 必填 | 说明           |
1635| ------ | ---- | ---- | -------------- |
1636| other  | [ScopeComparable](#scopecomparable8) | 是  | 表示要比较的值。 |
1637
1638**返回值:**
1639
1640| 类型 | 说明               |
1641| ---- | ------------------ |
1642| boolean | 调用compareTo的值大于等于传入的值返回true,否则返回false。|
1643
1644**示例:**
1645
1646构造新类,实现compareTo方法。后续示例代码中,均以此Temperature类为例。
1647
1648```ts
1649  class Temperature{
1650    private readonly _temp: number;
1651    constructor(value : number) {
1652      this._temp = value;
1653    }
1654    compareTo(value : Temperature ) {
1655      return this._temp >= value.getTemp();
1656    }
1657    getTemp() {
1658      return this._temp;
1659    }
1660    toString() : string {
1661      return this._temp.toString();
1662    }
1663  }
1664```
1665
1666## ScopeType<sup>8+</sup>
1667
1668用于表示范围中的值的类型。
1669
1670**系统能力:** SystemCapability.Utils.Lang
1671
1672| 类型 | 说明 |
1673| -------- | -------- |
1674| number | 表示值的类型为数字。 |
1675| [ScopeComparable](#scopecomparable8) | 表示值的类型为ScopeComparable。|
1676
1677## ScopeHelper<sup>9+</sup>
1678
1679ScopeHelper接口用于描述一个字段的有效范围。ScopeHelper实例的构造函数用于创建具有指定下限和上限的对象,并要求这些对象必须具有可比性。
1680
1681### constructor<sup>9+</sup>
1682
1683constructor(lowerObj: ScopeType, upperObj: ScopeType)
1684
1685用于创建指定下限和上限的作用域实例的构造函数,返回一个ScopeHelper对象。
1686
1687**系统能力:** SystemCapability.Utils.Lang
1688
1689**参数:**
1690
1691| 参数名   | 类型                     | 必填 | 说明                   |
1692| -------- | ------------------------ | ---- | ---------------------- |
1693| lowerObj | [ScopeType](#scopetype8) | 是   | 指定作用域实例的下限。 |
1694| upperObj | [ScopeType](#scopetype8) | 是   | 指定作用域实例的上限。 |
1695
1696**示例:**
1697
1698  ```ts
1699  class Temperature{
1700    private readonly _temp: number;
1701    constructor(value : number) {
1702      this._temp = value;
1703    }
1704    compareTo(value : Temperature ) {
1705      return this._temp >= value.getTemp();
1706    }
1707    getTemp() {
1708      return this._temp;
1709    }
1710    toString() : string {
1711      return this._temp.toString();
1712    }
1713  }
1714  let tempLower = new Temperature(30);
1715  let tempUpper = new Temperature(40);
1716  let range = new util.ScopeHelper(tempLower, tempUpper);
1717  ```
1718
1719
1720### toString<sup>9+</sup>
1721
1722toString(): string
1723
1724该字符串化方法返回一个包含当前范围的字符串表示形式。
1725
1726**系统能力:** SystemCapability.Utils.Lang
1727
1728**返回值:**
1729
1730| 类型   | 说明                                   |
1731| ------ | -------------------------------------- |
1732| string | 返回包含当前范围对象的字符串表示形式。 |
1733
1734**示例:**
1735
1736  ```ts
1737  class Temperature{
1738    private readonly _temp: number;
1739    constructor(value : number) {
1740      this._temp = value;
1741    }
1742    compareTo(value : Temperature ) {
1743      return this._temp >= value.getTemp();
1744    }
1745    getTemp() {
1746      return this._temp;
1747    }
1748    toString() : string {
1749      return this._temp.toString();
1750    }
1751  }
1752
1753  let tempLower = new Temperature(30);
1754  let tempUpper = new Temperature(40);
1755  let range = new util.ScopeHelper(tempLower, tempUpper);
1756  let result = range.toString();
1757  ```
1758
1759
1760### intersect<sup>9+</sup>
1761
1762intersect(range: ScopeHelper): ScopeHelper
1763
1764获取给定范围和当前范围的交集。
1765
1766**系统能力:** SystemCapability.Utils.Lang
1767
1768**参数:**
1769
1770| 参数名 | 类型                         | 必填 | 说明               |
1771| ------ | ---------------------------- | ---- | ------------------ |
1772| range  | [ScopeHelper](#scopehelper9) | 是   | 传入一个给定范围。 |
1773
1774**返回值:**
1775
1776| 类型                           | 说明                           |
1777| ------------------------------ | ------------------------------ |
1778| [ScopeHelper9+](#scopehelper9) | 返回给定范围和当前范围的交集。 |
1779
1780**示例:**
1781
1782  ```ts
1783  class Temperature{
1784    private readonly _temp: number;
1785    constructor(value : number) {
1786      this._temp = value;
1787    }
1788    compareTo(value : Temperature ) {
1789      return this._temp >= value.getTemp();
1790    }
1791    getTemp() {
1792      return this._temp;
1793    }
1794    toString() : string {
1795      return this._temp.toString();
1796    }
1797  }
1798
1799  let tempLower = new Temperature(30);
1800  let tempUpper = new Temperature(40);
1801  let range = new util.ScopeHelper(tempLower, tempUpper);
1802  let tempMiDF = new Temperature(35);
1803  let tempMidS = new Temperature(39);
1804  let rangeFir = new util.ScopeHelper(tempMiDF, tempMidS);
1805  range.intersect(rangeFir);
1806  ```
1807
1808
1809### intersect<sup>9+</sup>
1810
1811intersect(lowerObj:ScopeType,upperObj:ScopeType):ScopeHelper
1812
1813获取当前范围与给定下限和上限范围的交集。
1814
1815**系统能力:** SystemCapability.Utils.Lang
1816
1817**参数:**
1818
1819| 参数名   | 类型                     | 必填 | 说明             |
1820| -------- | ------------------------ | ---- | ---------------- |
1821| lowerObj | [ScopeType](#scopetype8) | 是   | 给定范围的下限。 |
1822| upperObj | [ScopeType](#scopetype8) | 是   | 给定范围的上限。 |
1823
1824**返回值:**
1825
1826| 类型                         | 说明                                     |
1827| ---------------------------- | ---------------------------------------- |
1828| [ScopeHelper](#scopehelper9) | 返回当前范围与给定下限和上限范围的交集。 |
1829
1830**示例:**
1831
1832  ```ts
1833  class Temperature{
1834    private readonly _temp: number;
1835    constructor(value : number) {
1836      this._temp = value;
1837    }
1838    compareTo(value : Temperature ) {
1839      return this._temp >= value.getTemp();
1840    }
1841    getTemp() {
1842      return this._temp;
1843    }
1844    toString() : string {
1845      return this._temp.toString();
1846    }
1847  }
1848
1849  let tempLower = new Temperature(30);
1850  let tempUpper = new Temperature(40);
1851  let tempMiDF = new Temperature(35);
1852  let tempMidS = new Temperature(39);
1853  let range = new util.ScopeHelper(tempLower, tempUpper);
1854  let result = range.intersect(tempMiDF, tempMidS);
1855  ```
1856
1857
1858### getUpper<sup>9+</sup>
1859
1860getUpper(): ScopeType
1861
1862获取当前范围的上限。
1863
1864**系统能力:** SystemCapability.Utils.Lang
1865
1866**返回值:**
1867
1868| 类型                     | 说明                   |
1869| ------------------------ | ---------------------- |
1870| [ScopeType](#scopetype8) | 返回当前范围的上限值。 |
1871
1872**示例:**
1873
1874  ```ts
1875  class Temperature{
1876    private readonly _temp: number;
1877    constructor(value : number) {
1878      this._temp = value;
1879    }
1880    compareTo(value : Temperature ) {
1881      return this._temp >= value.getTemp();
1882    }
1883    getTemp() {
1884      return this._temp;
1885    }
1886    toString() : string {
1887      return this._temp.toString();
1888    }
1889  }
1890
1891  let tempLower = new Temperature(30);
1892  let tempUpper = new Temperature(40);
1893  let range = new util.ScopeHelper(tempLower, tempUpper);
1894  let result = range.getUpper();
1895  ```
1896
1897
1898### getLower<sup>9+</sup>
1899
1900getLower(): ScopeType
1901
1902获取当前范围的下限。
1903
1904**系统能力:** SystemCapability.Utils.Lang
1905
1906**返回值:**
1907
1908| 类型                     | 说明                   |
1909| ------------------------ | ---------------------- |
1910| [ScopeType](#scopetype8) | 返回当前范围的下限值。 |
1911
1912**示例:**
1913
1914  ```ts
1915  class Temperature{
1916    private readonly _temp: number;
1917    constructor(value : number) {
1918      this._temp = value;
1919    }
1920    compareTo(value : Temperature ) {
1921      return this._temp >= value.getTemp();
1922    }
1923    getTemp() {
1924      return this._temp;
1925    }
1926    toString() : string {
1927      return this._temp.toString();
1928    }
1929  }
1930
1931  let tempLower = new Temperature(30);
1932  let tempUpper = new Temperature(40);
1933  let range = new util.ScopeHelper(tempLower, tempUpper);
1934  let result = range.getLower();
1935  ```
1936
1937
1938### expand<sup>9+</sup>
1939
1940expand(lowerObj: ScopeType,upperObj: ScopeType): ScopeHelper
1941
1942创建并返回包括当前范围和给定下限和上限的并集。
1943
1944**系统能力:** SystemCapability.Utils.Lang
1945
1946**参数:**
1947
1948| 参数名   | 类型                     | 必填 | 说明             |
1949| -------- | ------------------------ | ---- | ---------------- |
1950| lowerObj | [ScopeType](#scopetype8) | 是   | 给定范围的下限。 |
1951| upperObj | [ScopeType](#scopetype8) | 是   | 给定范围的上限。 |
1952
1953**返回值:**
1954
1955| 类型                         | 说明                                 |
1956| ---------------------------- | ------------------------------------ |
1957| [ScopeHelper](#scopehelper9) | 返回当前范围和给定下限和上限的并集。 |
1958
1959**示例:**
1960
1961  ```ts
1962  class Temperature{
1963    private readonly _temp: number;
1964    constructor(value : number) {
1965      this._temp = value;
1966    }
1967    compareTo(value : Temperature ) {
1968      return this._temp >= value.getTemp();
1969    }
1970    getTemp() {
1971      return this._temp;
1972    }
1973    toString() : string {
1974      return this._temp.toString();
1975    }
1976  }
1977
1978  let tempLower = new Temperature(30);
1979  let tempUpper = new Temperature(40);
1980  let tempMiDF = new Temperature(35);
1981  let tempMidS = new Temperature(39);
1982  let range = new util.ScopeHelper(tempLower, tempUpper);
1983  let result = range.expand(tempMiDF, tempMidS);
1984  ```
1985
1986
1987### expand<sup>9+</sup>
1988
1989expand(range: ScopeHelper): ScopeHelper
1990
1991创建并返回包括当前范围和给定范围的并集。
1992
1993**系统能力:** SystemCapability.Utils.Lang
1994
1995**参数:**
1996
1997| 参数名 | 类型                         | 必填 | 说明               |
1998| ------ | ---------------------------- | ---- | ------------------ |
1999| range  | [ScopeHelper](#scopehelper9) | 是   | 传入一个给定范围。 |
2000
2001**返回值:**
2002
2003| 类型                         | 说明                               |
2004| ---------------------------- | ---------------------------------- |
2005| [ScopeHelper](#scopehelper9) | 返回包括当前范围和给定范围的并集。 |
2006
2007**示例:**
2008
2009  ```ts
2010  class Temperature{
2011    private readonly _temp: number;
2012    constructor(value : number) {
2013      this._temp = value;
2014    }
2015    compareTo(value : Temperature ) {
2016      return this._temp >= value.getTemp();
2017    }
2018    getTemp() {
2019      return this._temp;
2020    }
2021    toString() : string {
2022      return this._temp.toString();
2023    }
2024  }
2025
2026  let tempLower = new Temperature(30);
2027  let tempUpper = new Temperature(40);
2028  let tempMiDF = new Temperature(35);
2029  let tempMidS = new Temperature(39);
2030  let range = new util.ScopeHelper(tempLower, tempUpper);
2031  let rangeFir = new util.ScopeHelper(tempMiDF, tempMidS);
2032  let result = range.expand(rangeFir);
2033  ```
2034
2035
2036### expand<sup>9+</sup>
2037
2038expand(value: ScopeType): ScopeHelper
2039
2040创建并返回包括当前范围和给定值的并集。
2041
2042**系统能力:** SystemCapability.Utils.Lang
2043
2044**参数:**
2045
2046| 参数名 | 类型                     | 必填 | 说明             |
2047| ------ | ------------------------ | ---- | ---------------- |
2048| value  | [ScopeType](#scopetype8) | 是   | 传入一个给定值。 |
2049
2050**返回值:**
2051
2052| 类型                         | 说明                             |
2053| ---------------------------- | -------------------------------- |
2054| [ScopeHelper](#scopehelper9) | 返回包括当前范围和给定值的并集。 |
2055
2056**示例:**
2057
2058  ```ts
2059  class Temperature{
2060    private readonly _temp: number;
2061    constructor(value : number) {
2062      this._temp = value;
2063    }
2064    compareTo(value : Temperature ) {
2065      return this._temp >= value.getTemp();
2066    }
2067    getTemp() {
2068      return this._temp;
2069    }
2070    toString() : string {
2071      return this._temp.toString();
2072    }
2073  }
2074
2075  let tempLower = new Temperature(30);
2076  let tempUpper = new Temperature(40);
2077  let tempMiDF = new Temperature(35);
2078  let range = new util.ScopeHelper(tempLower, tempUpper);
2079  let result = range.expand(tempMiDF);
2080  ```
2081
2082
2083### contains<sup>9+</sup>
2084
2085contains(value: ScopeType): boolean
2086
2087检查给定value是否包含在当前范围内。
2088
2089**系统能力:** SystemCapability.Utils.Lang
2090
2091**参数:**
2092
2093| 参数名 | 类型                     | 必填 | 说明             |
2094| ------ | ------------------------ | ---- | ---------------- |
2095| value  | [ScopeType](#scopetype8) | 是   | 传入一个给定值。 |
2096
2097**返回值:**
2098
2099| 类型    | 说明                                                |
2100| ------- | --------------------------------------------------- |
2101| boolean | 如果给定值包含在当前范围内返回true,否则返回false。 |
2102
2103**示例:**
2104
2105  ```ts
2106  class Temperature{
2107    private readonly _temp: number;
2108    constructor(value : number) {
2109      this._temp = value;
2110    }
2111    compareTo(value : Temperature ) {
2112      return this._temp >= value.getTemp();
2113    }
2114    getTemp() {
2115      return this._temp;
2116    }
2117    toString() : string {
2118      return this._temp.toString();
2119    }
2120  }
2121
2122  let tempLower = new Temperature(30);
2123  let tempUpper = new Temperature(40);
2124  let tempMiDF = new Temperature(35);
2125  let range = new util.ScopeHelper(tempLower, tempUpper);
2126  let result = range.contains(tempMiDF);
2127  ```
2128
2129
2130### contains<sup>9+</sup>
2131
2132contains(range: ScopeHelper): boolean
2133
2134检查给定range是否在当前范围内。
2135
2136**系统能力:** SystemCapability.Utils.Lang
2137
2138**参数:**
2139
2140| 参数名 | 类型                         | 必填 | 说明               |
2141| ------ | ---------------------------- | ---- | ------------------ |
2142| range  | [ScopeHelper](#scopehelper9) | 是   | 传入一个给定范围。 |
2143
2144**返回值:**
2145
2146| 类型    | 说明                                                  |
2147| ------- | ----------------------------------------------------- |
2148| boolean | 如果给定范围包含在当前范围内返回true,否则返回false。 |
2149
2150**示例:**
2151
2152  ```ts
2153  class Temperature{
2154    private readonly _temp: number;
2155    constructor(value : number) {
2156      this._temp = value;
2157    }
2158    compareTo(value : Temperature ) {
2159      return this._temp >= value.getTemp();
2160    }
2161    getTemp() {
2162      return this._temp;
2163    }
2164    toString() : string {
2165      return this._temp.toString();
2166    }
2167  }
2168
2169  let tempLower = new Temperature(30);
2170  let tempUpper = new Temperature(40);
2171  let range = new util.ScopeHelper(tempLower, tempUpper);
2172  let tempLess = new Temperature(20);
2173  let tempMore = new Temperature(45);
2174  let rangeSec = new util.ScopeHelper(tempLess, tempMore);
2175  let result = range.contains(rangeSec);
2176  ```
2177
2178
2179### clamp<sup>9+</sup>
2180
2181clamp(value: ScopeType): ScopeType
2182
2183将给定值限定到当前范围内。
2184
2185**系统能力:** SystemCapability.Utils.Lang
2186
2187**参数:**
2188
2189| 参数名 | 类型                     | 必填 | 说明           |
2190| ------ | ------------------------ | ---- | -------------- |
2191| value  | [ScopeType](#scopetype8) | 是   | 传入的给定值。 |
2192
2193**返回值:**
2194
2195| 类型                     | 说明                                                         |
2196| ------------------------ | ------------------------------------------------------------ |
2197| [ScopeType](#scopetype8) | 如果传入的value小于下限,则返回lowerObj;如果大于上限值则返回upperObj;如果在当前范围内,则返回value。 |
2198
2199**示例:**
2200
2201  ```ts
2202  class Temperature{
2203    private readonly _temp: number;
2204    constructor(value : number) {
2205      this._temp = value;
2206    }
2207    compareTo(value : Temperature ) {
2208      return this._temp >= value.getTemp();
2209    }
2210    getTemp() {
2211      return this._temp;
2212    }
2213    toString() : string {
2214      return this._temp.toString();
2215    }
2216  }
2217
2218  let tempLower = new Temperature(30);
2219  let tempUpper = new Temperature(40);
2220  let tempMiDF = new Temperature(35);
2221  let range = new util.ScopeHelper(tempLower, tempUpper);
2222  let result = range.clamp(tempMiDF);
2223  ```
2224
2225## Base64Helper<sup>9+</sup>
2226
2227Base64编码表包含A-Z、a-z、0-9这62个字符,以及"+"和"/"这两个特殊字符。在编码时,将原始数据按3个字节一组进行划分,得到若干个6位的数字,然后使用Base64编码表中对应的字符来表示这些数字。如果最后剩余1或2个字节,则需要使用"="字符进行补齐。
2228
2229### constructor<sup>9+</sup>
2230
2231constructor()
2232
2233Base64Helper的构造函数。
2234
2235**系统能力:** SystemCapability.Utils.Lang
2236
2237**示例:**
2238
2239  ```ts
2240  let base64 = new  util.Base64Helper();
2241  ```
2242
2243### encodeSync<sup>9+</sup>
2244
2245encodeSync(src: Uint8Array): Uint8Array
2246
2247通过输入参数编码后输出对应文本。
2248
2249**系统能力:** SystemCapability.Utils.Lang
2250
2251**参数:**
2252
2253| 参数名 | 类型       | 必填 | 说明                |
2254| ------ | ---------- | ---- | ------------------- |
2255| src    | Uint8Array | 是   | 编码输入Uint8数组。 |
2256
2257**返回值:**
2258
2259| 类型       | 说明                          |
2260| ---------- | ----------------------------- |
2261| Uint8Array | 返回编码后新分配的Uint8数组。 |
2262
2263**示例:**
2264
2265  ```ts
2266  let that = new util.Base64Helper();
2267  let array = new Uint8Array([115,49,51]);
2268  let result = that.encodeSync(array);
2269  ```
2270
2271
2272### encodeToStringSync<sup>9+</sup>
2273
2274encodeToStringSync(src: Uint8Array, options?: Type): string
2275
2276通过输入参数编码后输出对应文本。
2277
2278**系统能力:** SystemCapability.Utils.Lang
2279
2280**参数:**
2281
2282| 参数名 | 类型       | 必填 | 说明                |
2283| ------ | ---------- | ---- | ------------------- |
2284| src    | Uint8Array | 是   | 编码输入Uint8数组。 |
2285| options<sup>10+</sup>    | [Type](#type10) | 否   | 从API version 10开始支持该参数,表示对应的编码格式。<br/>此参数可选,可选值为:util.Type.BASICutil.Type.MIME,默认值为:util.Type.BASIC。<br/>- 当参数取值为util.Type.BASIC时,输出结果包含:64个可打印字符,包括大写字母A-Z、小写字母a-z、数字0-9共62个字符,再加上另外2个'+'和'/',没有回车符、换行符。<br/>- 当参数取值为util.Type.MIME时,输出结果包含:64个可打印字符,包括大写字母A-Z、小写字母a-z、数字0-9共62个字符,再加上另外2个'+'和'/',编码输出每一行不超过76个字符,而且每行以'\r\n'符结束。|
2286
2287**返回值:**
2288
2289| 类型   | 说明                 |
2290| ------ | -------------------- |
2291| string | 返回编码后的字符串。 |
2292
2293**示例:**
2294
2295  ```ts
2296  let that = new util.Base64Helper();
2297  let array = new Uint8Array([77,97,110,105,115,100,105,115,116,105,110,103,117,105,115,104,101,100,110,111,116,111,110,108,121,98,121,104,105,115,114,101,97,115,111,110,98,117,116,98,121,116,104,105,115,115,105,110,103,117,108,97,114,112,97,115,115,105,111,110,102,114,111,109,111,116,104,101,114,97,110,105,109,97,108,115,119,104,105,99,104,105,115,97,108,117,115,116,111,102,116,104,101,109,105,110,100,101,120,99,101,101,100,115,116,104,101,115,104,111,114,116,118,101,104,101,109,101,110,99,101,111,102,97,110,121,99,97,114,110,97,108,112,108,101,97,115,117,114,101]);
2298  let result = that.encodeToStringSync(array, util.Type.MIME);
2299  ```
2300
2301
2302### decodeSync<sup>9+</sup>
2303
2304decodeSync(src: Uint8Array | string, options?: Type): Uint8Array
2305
2306通过输入参数解码后输出对应文本。
2307
2308**系统能力:** SystemCapability.Utils.Lang
2309
2310**参数:**
2311
2312| 参数名 | 类型                           | 必填 | 说明                          |
2313| ------ | ------------------------------ | ---- | ----------------------------- |
2314| src    | Uint8Array&nbsp;\|&nbsp;string | 是   | 解码输入Uint8数组或者字符串。 |
2315| options<sup>10+</sup>    | [Type](#type10) | 否   | 从API version 10开始支持该参数,表示对应的编码格式。<br/>此参数可选,可选值为:util.Type.BASICutil.Type.MIME,默认值为:util.Type.BASIC。<br/>- 当参数取值为util.Type.BASIC时,表示入参包含:64个可打印字符,包括大写字母A-Z、小写字母a-z、数字0-9共62个字符,再加上另外2个'+'和'/',没有回车符、换行符。<br/>- 当参数取值为util.Type.MIME时,表示入参包含:64个可打印字符,包括大写字母A-Z、小写字母a-z、数字0-9共62个字符,再加上另外2个'+'和'/',每一行不超过76个字符,而且每行以'\r\n'符结束。 |
2316
2317**返回值:**
2318
2319| 类型       | 说明                          |
2320| ---------- | ----------------------------- |
2321| Uint8Array | 返回解码后新分配的Uint8数组。 |
2322
2323**示例:**
2324
2325  ```ts
2326  let that = new util.Base64Helper();
2327  let buff = 'TWFuaXNkaXN0aW5ndWlzaGVkbm90b25seWJ5aGlzcmVhc29uYnV0Ynl0aGlzc2luZ3VsYXJwYXNz\r\naW9uZnJvbW90aGVyYW5pbWFsc3doaWNoaXNhbHVzdG9mdGhlbWluZGV4Y2VlZHN0aGVzaG9ydHZl\r\naGVtZW5jZW9mYW55Y2FybmFscGxlYXN1cmU=\r\n';
2328  let result = that.decodeSync(buff, util.Type.MIME);
2329  ```
2330
2331
2332### encode<sup>9+</sup>
2333
2334encode(src: Uint8Array): Promise&lt;Uint8Array&gt;
2335
2336通过输入参数异步编码后输出对应文本。
2337
2338**系统能力:** SystemCapability.Utils.Lang
2339
2340**参数:**
2341
2342| 参数名 | 类型       | 必填 | 说明                    |
2343| ------ | ---------- | ---- | ----------------------- |
2344| src    | Uint8Array | 是   | 异步编码输入Uint8数组。 |
2345
2346**返回值:**
2347
2348| 类型                      | 说明                              |
2349| ------------------------- | --------------------------------- |
2350| Promise&lt;Uint8Array&gt; | 返回异步编码后新分配的Uint8数组。 |
2351
2352**示例:**
2353
2354  ```ts
2355  let that = new util.Base64Helper();
2356  let array = new Uint8Array([115,49,51]);
2357  let rarray = new Uint8Array([99,122,69,122]);
2358  that.encode(array).then(val=>{
2359    for (let i = 0; i < rarray.length; i++) {
2360      console.log(val[i].toString())
2361    }
2362  })
2363  ```
2364
2365
2366### encodeToString<sup>9+</sup>
2367
2368encodeToString(src: Uint8Array, options?: Type): Promise&lt;string&gt;
2369
2370通过输入参数异步编码后输出对应文本。
2371
2372**系统能力:** SystemCapability.Utils.Lang
2373
2374**参数:**
2375
2376| 参数名 | 类型       | 必填 | 说明                    |
2377| ------ | ---------- | ---- | ----------------------- |
2378| src    | Uint8Array | 是   | 异步编码输入Uint8数组。 |
2379| options<sup>10+</sup>    | [Type](#type10) | 否   |  从API version 10开始支持该参数,表示对应的编码格式。<br/>此参数可选,可选值为:util.Type.BASICutil.Type.MIME,默认值为:util.Type.BASIC。<br/>- 当参数取值为util.Type.BASIC时,输出结果包含:64个可打印字符,包括大写字母A-Z、小写字母a-z、数字0-9共62个字符,再加上另外2个'+'和'/',没有回车符、换行符。<br/>- 当参数取值为util.Type.MIME时,输出结果包含:64个可打印字符,包括大写字母A-Z、小写字母a-z、数字0-9共62个字符,再加上另外2个'+'和'/',编码输出每一行不超过76个字符,而且每行以'\r\n'符结束。 |
2380
2381**返回值:**
2382
2383| 类型                  | 说明                     |
2384| --------------------- | ------------------------ |
2385| Promise&lt;string&gt; | 返回异步编码后的字符串。 |
2386
2387**示例:**
2388
2389  ```ts
2390  let that = new util.Base64Helper();
2391  let array = new Uint8Array([77,97,110,105,115,100,105,115,116,105,110,103,117,105,115,104,101,100,110,111,116,111,110,108,121,98,121,104,105,115,114,101,97,115,111,110,98,117,116,98,121,116,104,105,115,115,105,110,103,117,108,97,114,112,97,115,115,105,111,110,102,114,111,109,111,116,104,101,114,97,110,105,109,97,108,115,119,104,105,99,104,105,115,97,108,117,115,116,111,102,116,104,101,109,105,110,100,101,120,99,101,101,100,115,116,104,101,115,104,111,114,116,118,101,104,101,109,101,110,99,101,111,102,97,110,121,99,97,114,110,97,108,112,108,101,97,115,117,114,101]);
2392  that.encodeToString(array, util.Type.MIME).then(val=>{
2393    // 根据开发者需求进行添加。
2394  })
2395  ```
2396
2397
2398### decode<sup>9+</sup>
2399
2400decode(src: Uint8Array | string, options?: Type): Promise&lt;Uint8Array&gt;
2401
2402通过输入参数异步解码后输出对应文本。
2403
2404**系统能力:** SystemCapability.Utils.Lang
2405
2406**参数:**
2407
2408| 参数名 | 类型                           | 必填 | 说明                              |
2409| ------ | ------------------------------ | ---- | --------------------------------- |
2410| src    | Uint8Array&nbsp;\|&nbsp;string | 是   | 异步解码输入Uint8数组或者字符串。 |
2411| options<sup>10+</sup>    | [Type](#type10) | 否   | 从API version 10开始支持该参数,表示对应的编码格式。<br/>此参数可选,可选值为:util.Type.BASICutil.Type.MIME,默认值为:util.Type.BASIC。<br/>- 当参数取值为util.Type.BASIC时,表示入参包含:64个可打印字符,包括大写字母A-Z、小写字母a-z、数字0-9共62个字符,再加上另外2个'+'和'/',没有回车符、换行符。<br/>- 当参数取值为util.Type.MIME时,表示入参包含:64个可打印字符,包括大写字母A-Z、小写字母a-z、数字0-9共62个字符,再加上另外2个'+'和'/',每一行不超过76个字符,而且每行以'\r\n'符结束。 |
2412
2413**返回值:**
2414
2415| 类型                      | 说明                              |
2416| ------------------------- | --------------------------------- |
2417| Promise&lt;Uint8Array&gt; | 返回异步解码后新分配的Uint8数组。 |
2418
2419**示例:**
2420
2421  ```ts
2422  let that = new util.Base64Helper();
2423  let array = 'TWFuaXNkaXN0aW5ndWlzaGVkbm90b25seWJ5aGlzcmVhc29uYnV0Ynl0aGlzc2luZ3VsYXJwYXNz\r\naW9uZnJvbW90aGVyYW5pbWFsc3doaWNoaXNhbHVzdG9mdGhlbWluZGV4Y2VlZHN0aGVzaG9ydHZl\r\naGVtZW5jZW9mYW55Y2FybmFscGxlYXN1cmU=\r\n';
2424  that.decode(array, util.Type.MIME).then(val=>{
2425    // 根据开发者需求进行添加。
2426  })
2427  ```
2428
2429
2430## Type<sup>10+</sup>
2431
2432Base64编码格式枚举。
2433
2434**系统能力:** SystemCapability.Utils.Lang
2435
2436| 名称   | 值                     | 说明             |
2437| -------- | ------------------------ | ---------------- |
2438| BASIC | 0 | 表示BASIC编码格式 |
2439| MIME | 1 | 表示MIME编码格式。 |
2440
2441
2442## types<sup>8+</sup>
2443
2444types为不同类型的内置对象提供类型检查,可以避免由于类型错误导致的异常或崩溃。该模块包含了多个工具函数,用于判断JS对象是否属于各种类型例如:ArrayBuffer、Map、Set等。
2445
2446### constructor<sup>8+</sup>
2447
2448constructor()
2449
2450Types的构造函数。
2451
2452**系统能力:** SystemCapability.Utils.Lang
2453
2454**示例:**
2455
2456  ```ts
2457  let type = new util.types();
2458  ```
2459
2460
2461### isAnyArrayBuffer<sup>8+</sup>
2462
2463isAnyArrayBuffer(value: Object): boolean
2464
2465检查输入的value是否是ArrayBuffer类型。
2466
2467**系统能力:** SystemCapability.Utils.Lang
2468
2469**参数:**
2470
2471| 参数名 | 类型 | 必填 | 说明 |
2472| -------- | -------- | -------- | -------- |
2473| value | Object | 是 | 待检测对象。 |
2474
2475**返回值:**
2476
2477| 类型 | 说明 |
2478| -------- | -------- |
2479| boolean | 判断的结果,如果是ArrayBuffer类型为true,反之为false。 |
2480
2481**示例:**
2482
2483  ```ts
2484  let that = new util.types();
2485  let result = that.isAnyArrayBuffer(new ArrayBuffer(0));
2486  ```
2487
2488
2489### isArrayBufferView<sup>8+</sup>
2490
2491isArrayBufferView(value: Object): boolean
2492
2493检查输入的value是否是内置ArrayBufferView辅助类型。
2494
2495ArrayBufferView辅助类型包括:Int8Array、Int16Array、Int32Array、Uint8Array、Uint8ClampedArray、Uint32Array、Float32Array、Float64Array、DataView。
2496
2497**系统能力:** SystemCapability.Utils.Lang
2498
2499**参数:**
2500
2501| 参数名 | 类型 | 必填 | 说明 |
2502| -------- | -------- | -------- | -------- |
2503| value | Object | 是 | 待检测对象。 |
2504
2505**返回值:**
2506
2507| 类型 | 说明 |
2508| -------- | -------- |
2509| boolean | 判断的结果,如果是内置包含的ArrayBufferView辅助类型为true,反之为false。 |
2510
2511**示例:**
2512
2513  ```ts
2514  let that = new util.types();
2515  let result = that.isArrayBufferView(new Int8Array([]));
2516  ```
2517
2518
2519### isArgumentsObject<sup>8+</sup>
2520
2521isArgumentsObject(value: Object): boolean
2522
2523检查输入的value是否是一个arguments对象类型。
2524
2525**系统能力:** SystemCapability.Utils.Lang
2526
2527**参数:**
2528
2529| 参数名 | 类型 | 必填 | 说明 |
2530| -------- | -------- | -------- | -------- |
2531| value | Object | 是 | 待检测对象。 |
2532
2533**返回值:**
2534
2535| 类型 | 说明 |
2536| -------- | -------- |
2537| boolean | 判断的结果,如果是内置包含的arguments类型为true,反之为false。 |
2538
2539**示例:**
2540
2541  ```ts
2542  let that = new util.types();
2543  function foo() {
2544      let result = that.isArgumentsObject(arguments);
2545  }
2546  let f = foo();
2547  ```
2548
2549
2550### isArrayBuffer<sup>8+</sup>
2551
2552isArrayBuffer(value: Object): boolean
2553
2554检查输入的value是否是ArrayBuffer类型。
2555
2556**系统能力:** SystemCapability.Utils.Lang
2557
2558**参数:**
2559
2560| 参数名 | 类型 | 必填 | 说明 |
2561| -------- | -------- | -------- | -------- |
2562| value | Object | 是 | 待检测对象。 |
2563
2564**返回值:**
2565
2566| 类型 | 说明 |
2567| -------- | -------- |
2568| boolean | 判断的结果,如果是内置包含的ArrayBuffer类型为true,反之为false。 |
2569
2570**示例:**
2571
2572  ```ts
2573  let that = new util.types();
2574  let result = that.isArrayBuffer(new ArrayBuffer(0));
2575  ```
2576
2577
2578### isAsyncFunction<sup>8+</sup>
2579
2580isAsyncFunction(value: Object): boolean
2581
2582检查输入的value是否是一个异步函数类型。
2583
2584**系统能力:** SystemCapability.Utils.Lang
2585
2586**参数:**
2587
2588| 参数名 | 类型 | 必填 | 说明 |
2589| -------- | -------- | -------- | -------- |
2590| value | Object | 是 | 待检测对象。 |
2591
2592**返回值:**
2593
2594| 类型 | 说明 |
2595| -------- | -------- |
2596| boolean | 判断的结果,如果是内置包含的异步函数类型为true,反之为false。 |
2597
2598**示例:**
2599
2600  ```ts
2601  let that = new util.types();
2602  let result = that.isAsyncFunction(async () => {});
2603  ```
2604
2605
2606### isBooleanObject<sup>8+</sup>
2607
2608isBooleanObject(value: Object): boolean
2609
2610检查输入的value是否是一个Boolean对象类型。
2611
2612**系统能力:** SystemCapability.Utils.Lang
2613
2614**参数:**
2615
2616| 参数名 | 类型 | 必填 | 说明 |
2617| -------- | -------- | -------- | -------- |
2618| value | Object | 是 | 待检测对象。 |
2619
2620**返回值:**
2621
2622| 类型 | 说明 |
2623| -------- | -------- |
2624| boolean | 判断的结果,如果是内置包含的Boolean对象类型为true,反之为false。 |
2625
2626**示例:**
2627
2628  ```ts
2629  let that = new util.types();
2630  let result = that.isBooleanObject(new Boolean(true));
2631  ```
2632
2633
2634### isBoxedPrimitive<sup>8+</sup>
2635
2636isBoxedPrimitive(value: Object): boolean
2637
2638检查输入的value是否是Boolean或Number或String或Symbol对象类型。
2639
2640**系统能力:** SystemCapability.Utils.Lang
2641
2642**参数:**
2643
2644| 参数名 | 类型 | 必填 | 说明 |
2645| -------- | -------- | -------- | -------- |
2646| value | Object | 是 | 待检测对象。 |
2647
2648**返回值:**
2649
2650| 类型 | 说明 |
2651| -------- | -------- |
2652| boolean | 判断的结果,如果是内置包含的Boolean或Number或String或Symbol对象类型为true,反之为false。 |
2653
2654**示例:**
2655
2656  ```ts
2657  let that = new util.types();
2658  let result = that.isBoxedPrimitive(new Boolean(false));
2659  ```
2660
2661
2662### isDataView<sup>8+</sup>
2663
2664isDataView(value: Object): boolean
2665
2666检查输入的value是否是DataView类型。
2667
2668**系统能力:** SystemCapability.Utils.Lang
2669
2670**参数:**
2671
2672| 参数名 | 类型 | 必填 | 说明 |
2673| -------- | -------- | -------- | -------- |
2674| value | Object | 是 | 待检测对象。 |
2675
2676**返回值:**
2677
2678| 类型 | 说明 |
2679| -------- | -------- |
2680| boolean | 判断的结果,如果是内置包含的DataView对象类型为true,反之为false。 |
2681
2682**示例:**
2683
2684  ```ts
2685  let that = new util.types();
2686  const ab = new ArrayBuffer(20);
2687  let result = that.isDataView(new DataView(ab));
2688  ```
2689
2690
2691### isDate<sup>8+</sup>
2692
2693isDate(value: Object): boolean
2694
2695检查输入的value是否是Date类型。
2696
2697**系统能力:** SystemCapability.Utils.Lang
2698
2699**参数:**
2700
2701| 参数名 | 类型 | 必填 | 说明 |
2702| -------- | -------- | -------- | -------- |
2703| value | Object | 是 | 待检测对象。 |
2704
2705**返回值:**
2706
2707| 类型 | 说明 |
2708| -------- | -------- |
2709| boolean | 判断的结果,如果是内置包含的Date对象类型为true,反之为false。 |
2710
2711**示例:**
2712
2713  ```ts
2714  let that = new util.types();
2715  let result = that.isDate(new Date());
2716  ```
2717
2718
2719### isExternal<sup>8+</sup>
2720
2721isExternal(value: Object): boolean
2722
2723检查输入的value是否是native External类型。
2724
2725**系统能力:** SystemCapability.Utils.Lang
2726
2727**参数:**
2728
2729| 参数名 | 类型 | 必填 | 说明 |
2730| -------- | -------- | -------- | -------- |
2731| value | Object | 是 | 待检测对象。 |
2732
2733**返回值:**
2734
2735| 类型 | 说明 |
2736| -------- | -------- |
2737| boolean | 判断的结果,如果是内置包含native&nbsp;External类型为true,反之为false。 |
2738
2739**示例:**
2740
2741  ```ts
2742  let that = new util.types();
2743  let result = that.isExternal(true);
2744  ```
2745
2746
2747### isFloat32Array<sup>8+</sup>
2748
2749isFloat32Array(value: Object): boolean
2750
2751检查输入的value是否是Float32Array数组类型。
2752
2753**系统能力:** SystemCapability.Utils.Lang
2754
2755**参数:**
2756
2757| 参数名 | 类型 | 必填 | 说明 |
2758| -------- | -------- | -------- | -------- |
2759| value | Object | 是 | 待检测对象。 |
2760
2761**返回值:**
2762
2763| 类型 | 说明 |
2764| -------- | -------- |
2765| boolean | 判断的结果,如果是内置包含的Float32Array数组类型为true,反之为false。 |
2766
2767**示例:**
2768
2769  ```ts
2770  let that = new util.types();
2771  let result = that.isFloat32Array(new Float32Array());
2772  ```
2773
2774
2775### isFloat64Array<sup>8+</sup>
2776
2777isFloat64Array(value: Object): boolean
2778
2779检查输入的value是否是Float64Array数组类型。
2780
2781**系统能力:** SystemCapability.Utils.Lang
2782
2783**参数:**
2784
2785| 参数名 | 类型 | 必填 | 说明 |
2786| -------- | -------- | -------- | -------- |
2787| value | Object | 是 | 待检测对象。 |
2788
2789**返回值:**
2790
2791| 类型 | 说明 |
2792| -------- | -------- |
2793| boolean | 判断的结果,如果是内置包含的Float64Array数组类型为true,反之为false。 |
2794
2795**示例:**
2796
2797  ```ts
2798  let that = new util.types();
2799  let result = that.isFloat64Array(new Float64Array());
2800  ```
2801
2802
2803### isGeneratorFunction<sup>8+</sup>
2804
2805isGeneratorFunction(value: Object): boolean
2806
2807检查输入的value是否是generator函数类型。
2808
2809**系统能力:** SystemCapability.Utils.Lang
2810
2811**参数:**
2812
2813| 参数名 | 类型 | 必填 | 说明 |
2814| -------- | -------- | -------- | -------- |
2815| value | Object | 是 | 待检测对象。 |
2816
2817**返回值:**
2818
2819| 类型 | 说明 |
2820| -------- | -------- |
2821| boolean | 判断的结果,如果是内置包含的generator函数类型为true,反之为false。 |
2822
2823**示例:**
2824
2825  ```ts
2826  let that = new util.types();
2827  let result = that.isGeneratorFunction(function* foo() {});
2828  ```
2829
2830
2831### isGeneratorObject<sup>8+</sup>
2832
2833isGeneratorObject(value: Object): boolean
2834
2835检查输入的value是否是generator对象类型。
2836
2837**系统能力:** SystemCapability.Utils.Lang
2838
2839**参数:**
2840
2841| 参数名 | 类型 | 必填 | 说明 |
2842| -------- | -------- | -------- | -------- |
2843| value | Object | 是 | 待检测对象。 |
2844
2845**返回值:**
2846
2847| 类型 | 说明 |
2848| -------- | -------- |
2849| boolean | 判断的结果,如果是内置包含的generator对象类型为true,反之为false。 |
2850
2851**示例:**
2852
2853  ```ts
2854  let that = new util.types();
2855  function* foo() {}
2856  const generator = foo();
2857  let result = that.isGeneratorObject(generator);
2858  ```
2859
2860
2861### isInt8Array<sup>8+</sup>
2862
2863isInt8Array(value: Object): boolean
2864
2865检查输入的value是否是Int8Array数组类型。
2866
2867**系统能力:** SystemCapability.Utils.Lang
2868
2869**参数:**
2870
2871| 参数名 | 类型 | 必填 | 说明 |
2872| -------- | -------- | -------- | -------- |
2873| value | Object | 是 | 待检测对象。 |
2874
2875**返回值:**
2876
2877| 类型 | 说明 |
2878| -------- | -------- |
2879| boolean | 判断的结果,如果是内置包含的Int8Array数组类型为true,反之为false。 |
2880
2881**示例:**
2882
2883  ```ts
2884  let that = new util.types();
2885  let result = that.isInt8Array(new Int8Array([]));
2886  ```
2887
2888
2889### isInt16Array<sup>8+</sup>
2890
2891isInt16Array(value: Object): boolean
2892
2893检查输入的value是否是Int16Array数组类型。
2894
2895**系统能力:** SystemCapability.Utils.Lang
2896
2897**参数:**
2898
2899| 参数名 | 类型 | 必填 | 说明 |
2900| -------- | -------- | -------- | -------- |
2901| value | Object | 是 | 待检测对象。 |
2902
2903**返回值:**
2904
2905| 类型 | 说明 |
2906| -------- | -------- |
2907| boolean | 判断的结果,如果是内置包含的Int16Array数组类型为true,反之为false。 |
2908
2909**示例:**
2910
2911  ```ts
2912  let that = new util.types();
2913  let result = that.isInt16Array(new Int16Array([]));
2914  ```
2915
2916
2917### isInt32Array<sup>8+</sup>
2918
2919isInt32Array(value: Object): boolean
2920
2921检查输入的value是否是Int32Array数组类型。
2922
2923**系统能力:** SystemCapability.Utils.Lang
2924
2925**参数:**
2926
2927| 参数名 | 类型 | 必填 | 说明 |
2928| -------- | -------- | -------- | -------- |
2929| value | Object | 是 | 待检测对象。 |
2930
2931**返回值:**
2932
2933| 类型 | 说明 |
2934| -------- | -------- |
2935| boolean | 判断的结果,如果是内置包含的Int32Array数组类型为true,反之为false。 |
2936
2937**示例:**
2938
2939  ```ts
2940  let that = new util.types();
2941  let result = that.isInt32Array(new Int32Array([]));
2942  ```
2943
2944
2945### isMap<sup>8+</sup>
2946
2947isMap(value: Object): boolean
2948
2949检查输入的value是否是Map类型。
2950
2951**系统能力:** SystemCapability.Utils.Lang
2952
2953**参数:**
2954
2955| 参数名 | 类型 | 必填 | 说明 |
2956| -------- | -------- | -------- | -------- |
2957| value | Object | 是 | 待检测对象。 |
2958
2959**返回值:**
2960
2961| 类型 | 说明 |
2962| -------- | -------- |
2963| boolean | 判断的结果,如果是内置包含的Map类型为true,反之为false。 |
2964
2965**示例:**
2966
2967  ```ts
2968  let that = new util.types();
2969  let result = that.isMap(new Map());
2970  ```
2971
2972
2973### isMapIterator<sup>8+</sup>
2974
2975isMapIterator(value: Object): boolean
2976
2977检查输入的value是否是Map的Iterator类型。
2978
2979**系统能力:** SystemCapability.Utils.Lang
2980
2981**参数:**
2982
2983
2984| 参数名 | 类型 | 必填 | 说明 |
2985| -------- | -------- | -------- | -------- |
2986| value | Object | 是 | 待检测对象。 |
2987
2988**返回值:**
2989
2990| 类型 | 说明 |
2991| -------- | -------- |
2992| boolean | 判断的结果,如果是内置包含的Map的Iterator类型为true,反之为false。 |
2993
2994**示例:**
2995
2996  ```ts
2997  let that = new util.types();
2998  const map : Map<number,number> = new Map();
2999  let result = that.isMapIterator(map.keys());
3000  ```
3001
3002
3003### isNativeError<sup>8+</sup>
3004
3005isNativeError(value: Object): boolean
3006
3007检查输入的value是否是Error类型。
3008
3009**系统能力:** SystemCapability.Utils.Lang
3010
3011**参数:**
3012
3013| 参数名 | 类型 | 必填 | 说明 |
3014| -------- | -------- | -------- | -------- |
3015| value | Object | 是 | 待检测对象。 |
3016
3017**返回值:**
3018
3019| 类型 | 说明 |
3020| -------- | -------- |
3021| boolean | 判断的结果,如果是内置包含的Error类型为true,反之为false。 |
3022
3023**示例:**
3024
3025  ```ts
3026  let that = new util.types();
3027  let result = that.isNativeError(new TypeError());
3028  ```
3029
3030
3031### isNumberObject<sup>8+</sup>
3032
3033isNumberObject(value: Object): boolean
3034
3035检查输入的value是否是Number对象类型。
3036
3037**系统能力:** SystemCapability.Utils.Lang
3038
3039**参数:**
3040
3041| 参数名 | 类型 | 必填 | 说明 |
3042| -------- | -------- | -------- | -------- |
3043| value | Object | 是 | 待检测对象。 |
3044
3045**返回值:**
3046
3047| 类型 | 说明 |
3048| -------- | -------- |
3049| boolean | 判断的结果,如果是内置包含的Number对象类型为true,反之为false。 |
3050
3051**示例:**
3052
3053  ```ts
3054  let that = new util.types();
3055  let result = that.isNumberObject(new Number(0));
3056  ```
3057
3058
3059### isPromise<sup>8+</sup>
3060
3061isPromise(value: Object): boolean
3062
3063检查输入的value是否是Promise类型。
3064
3065**系统能力:** SystemCapability.Utils.Lang
3066
3067**参数:**
3068
3069| 参数名 | 类型 | 必填 | 说明 |
3070| -------- | -------- | -------- | -------- |
3071| value | Object | 是 | 待检测对象。 |
3072
3073**返回值:**
3074
3075| 类型 | 说明 |
3076| -------- | -------- |
3077| boolean | 判断的结果,如果是内置包含的Promise类型为true,反之为false。 |
3078
3079**示例:**
3080
3081  ```ts
3082  let that = new util.types();
3083  let result = that.isPromise(Promise.resolve(1));
3084  ```
3085
3086
3087### isProxy<sup>8+</sup>
3088
3089isProxy(value: Object): boolean
3090
3091检查输入的value是否是Proxy类型。
3092
3093**系统能力:** SystemCapability.Utils.Lang
3094
3095**参数:**
3096
3097| 参数名 | 类型 | 必填 | 说明 |
3098| -------- | -------- | -------- | -------- |
3099| value | Object | 是 | 待检测对象。 |
3100
3101**返回值:**
3102
3103| 类型 | 说明 |
3104| -------- | -------- |
3105| boolean | 判断的结果,如果是内置包含的Proxy类型为true,反之为false。 |
3106
3107**示例:**
3108
3109  ```ts
3110  class Target{
3111  }
3112  let that = new util.types();
3113  const target : Target = {};
3114  const proxy = new Proxy(target, target);
3115  let result = that.isProxy(proxy);
3116  ```
3117
3118
3119### isRegExp<sup>8+</sup>
3120
3121isRegExp(value: Object): boolean
3122
3123检查输入的value是否是RegExp类型。
3124
3125**系统能力:** SystemCapability.Utils.Lang
3126
3127**参数:**
3128
3129| 参数名 | 类型 | 必填 | 说明 |
3130| -------- | -------- | -------- | -------- |
3131| value | Object | 是 | 待检测对象。 |
3132
3133**返回值:**
3134
3135| 类型 | 说明 |
3136| -------- | -------- |
3137| boolean | 判断的结果,如果是内置包含的RegExp类型为true,反之为false。 |
3138
3139**示例:**
3140
3141  ```ts
3142  let that = new util.types();
3143  let result = that.isRegExp(new RegExp('abc'));
3144  ```
3145
3146
3147### isSet<sup>8+</sup>
3148
3149isSet(value: Object): boolean
3150
3151检查输入的value是否是Set类型。
3152
3153**系统能力:** SystemCapability.Utils.Lang
3154
3155**参数:**
3156
3157| 参数名 | 类型 | 必填 | 说明 |
3158| -------- | -------- | -------- | -------- |
3159| value | Object | 是 | 待检测对象。 |
3160
3161**返回值:**
3162
3163| 类型 | 说明 |
3164| -------- | -------- |
3165| boolean | 判断的结果,如果是内置包含的Set类型为true,反之为false。 |
3166
3167**示例:**
3168
3169  ```ts
3170  let that = new util.types();
3171  let set : Set<number> = new Set();
3172  let result = that.isSet(set);
3173  ```
3174
3175
3176### isSetIterator<sup>8+</sup>
3177
3178isSetIterator(value: Object): boolean
3179
3180检查输入的value是否是Set的Iterator类型。
3181
3182**系统能力:** SystemCapability.Utils.Lang
3183
3184**参数:**
3185
3186| 参数名 | 类型 | 必填 | 说明 |
3187| -------- | -------- | -------- | -------- |
3188| value | Object | 是 | 待检测对象。 |
3189
3190**返回值:**
3191
3192| 类型 | 说明 |
3193| -------- | -------- |
3194| boolean | 判断的结果,如果是内置包含的Set的Iterator类型为true,反之为false。 |
3195
3196**示例:**
3197
3198  ```ts
3199  let that = new util.types();
3200  const set : Set<number> = new Set();
3201  let result = that.isSetIterator(set.keys());
3202  ```
3203
3204
3205### isStringObject<sup>8+</sup>
3206
3207isStringObject(value: Object): boolean
3208
3209检查输入的value是否是String对象类型。
3210
3211**系统能力:** SystemCapability.Utils.Lang
3212
3213**参数:**
3214
3215| 参数名 | 类型 | 必填 | 说明 |
3216| -------- | -------- | -------- | -------- |
3217| value | Object | 是 | 待检测对象。 |
3218
3219**返回值:**
3220
3221| 类型 | 说明 |
3222| -------- | -------- |
3223| boolean | 判断的结果,如果是内置包含的String对象类型为true,反之为false。 |
3224
3225**示例:**
3226
3227  ```ts
3228  let that = new util.types();
3229  let result = that.isStringObject(new String('foo'));
3230  ```
3231
3232
3233### isSymbolObjec<sup>8+</sup>
3234
3235isSymbolObject(value: Object): boolean
3236
3237检查输入的value是否是Symbol对象类型。
3238
3239**系统能力:** SystemCapability.Utils.Lang
3240
3241**参数:**
3242
3243| 参数名 | 类型 | 必填 | 说明 |
3244| -------- | -------- | -------- | -------- |
3245| value | Object | 是 | 待检测对象。 |
3246
3247**返回值:**
3248
3249| 类型 | 说明 |
3250| -------- | -------- |
3251| boolean | 判断的结果,如果是内置包含的Symbol对象类型为true,反之为false。 |
3252
3253**示例:**
3254
3255  ```ts
3256  let that = new util.types();
3257  const symbols = Symbol('foo');
3258  let result = that.isSymbolObject(Object(symbols));
3259  ```
3260
3261
3262### isTypedArray<sup>8+</sup>
3263
3264isTypedArray(value: Object): boolean
3265
3266检查输入的value是否是TypedArray类型的辅助类型。
3267
3268TypedArray类型的辅助类型,包括Int8Array、Int16Array、Int32Array、Uint8Array、Uint8ClampedArray、Uint16Array、Uint32Array、Float32Array、Float64Array、DataView。
3269
3270**系统能力:** SystemCapability.Utils.Lang
3271
3272**参数:**
3273
3274| 参数名 | 类型 | 必填 | 说明 |
3275| -------- | -------- | -------- | -------- |
3276| value | Object | 是 | 待检测对象。 |
3277
3278**返回值:**
3279
3280| 类型 | 说明 |
3281| -------- | -------- |
3282| boolean | 判断的结果,如果是内置包含的TypedArray包含的类型为true,反之为false。 |
3283
3284**示例:**
3285
3286  ```ts
3287  let that = new util.types();
3288  let result = that.isTypedArray(new Float64Array([]));
3289  ```
3290
3291
3292### isUint8Array<sup>8+</sup>
3293
3294isUint8Array(value: Object): boolean
3295
3296检查输入的value是否是Uint8Array数组类型。
3297
3298**系统能力:** SystemCapability.Utils.Lang
3299
3300**参数:**
3301
3302| 参数名 | 类型 | 必填 | 说明 |
3303| -------- | -------- | -------- | -------- |
3304| value | Object | 是 | 待检测对象。 |
3305
3306**返回值:**
3307
3308| 类型 | 说明 |
3309| -------- | -------- |
3310| boolean | 判断的结果,如果是内置包含的Uint8Array数组类型为true,反之为false。 |
3311
3312**示例:**
3313
3314  ```ts
3315  let that = new util.types();
3316  let result = that.isUint8Array(new Uint8Array([]));
3317  ```
3318
3319
3320### isUint8ClampedArray<sup>8+</sup>
3321
3322isUint8ClampedArray(value: Object): boolean
3323
3324检查输入的value是否是Uint8ClampedArray数组类型。
3325
3326**系统能力:** SystemCapability.Utils.Lang
3327
3328**参数:**
3329
3330| 参数名 | 类型 | 必填 | 说明 |
3331| -------- | -------- | -------- | -------- |
3332| value | Object | 是 | 待检测对象。 |
3333
3334**返回值:**
3335
3336| 类型 | 说明 |
3337| -------- | -------- |
3338| boolean | 判断的结果,如果是内置包含的Uint8ClampedArray数组类型为true,反之为false。 |
3339
3340**示例:**
3341
3342  ```ts
3343  let that = new util.types();
3344  let result = that.isUint8ClampedArray(new Uint8ClampedArray([]));
3345  ```
3346
3347
3348### isUint16Array<sup>8+</sup>
3349
3350isUint16Array(value: Object): boolean
3351
3352检查输入的value是否是Uint16Array数组类型。
3353
3354**系统能力:** SystemCapability.Utils.Lang
3355
3356**参数:**
3357
3358| 参数名 | 类型 | 必填 | 说明 |
3359| -------- | -------- | -------- | -------- |
3360| value | Object | 是 | 待检测对象。 |
3361
3362**返回值:**
3363
3364| 类型 | 说明 |
3365| -------- | -------- |
3366| boolean | 判断的结果,如果是内置包含的Uint16Array数组类型为true,反之为false。 |
3367
3368**示例:**
3369
3370  ```ts
3371  let that = new util.types();
3372  let result = that.isUint16Array(new Uint16Array([]));
3373  ```
3374
3375
3376### isUint32Array<sup>8+</sup>
3377
3378isUint32Array(value: Object): boolean
3379
3380检查输入的value是否是Uint32Array数组类型。
3381
3382**系统能力:** SystemCapability.Utils.Lang
3383
3384**参数:**
3385
3386| 参数名 | 类型 | 必填 | 说明 |
3387| -------- | -------- | -------- | -------- |
3388| value | Object | 是 | 待检测对象。 |
3389
3390**返回值:**
3391
3392| 类型 | 说明 |
3393| -------- | -------- |
3394| boolean | 判断的结果,如果是内置包含的Uint32Array数组类型为true,反之为false。 |
3395
3396**示例:**
3397
3398  ```ts
3399  let that = new util.types();
3400  let result = that.isUint32Array(new Uint32Array([]));
3401  ```
3402
3403
3404### isWeakMap<sup>8+</sup>
3405
3406isWeakMap(value: Object): boolean
3407
3408检查输入的value是否是WeakMap类型。
3409
3410**系统能力:** SystemCapability.Utils.Lang
3411
3412**参数:**
3413
3414| 参数名 | 类型 | 必填 | 说明 |
3415| -------- | -------- | -------- | -------- |
3416| value | Object | 是 | 待检测对象。 |
3417
3418**返回值:**
3419
3420| 类型 | 说明 |
3421| -------- | -------- |
3422| boolean | 判断的结果,如果是内置包含的WeakMap类型为true,反之为false。 |
3423
3424**示例:**
3425
3426  ```ts
3427  let that = new util.types();
3428  let value : WeakMap<object,number> = new WeakMap();
3429  let result = that.isWeakMap(value);
3430  ```
3431
3432
3433### isWeakSet<sup>8+</sup>
3434
3435isWeakSet(value: Object): boolean
3436
3437检查输入的value是否是WeakSet类型。
3438
3439**系统能力:** SystemCapability.Utils.Lang
3440
3441**参数:**
3442
3443| 参数名 | 类型 | 必填 | 说明 |
3444| -------- | -------- | -------- | -------- |
3445| value | Object | 是 | 待检测对象。 |
3446
3447**返回值:**
3448
3449| 类型 | 说明 |
3450| -------- | -------- |
3451| boolean | 判断的结果,如果是内置包含的WeakSet类型为true,反之为false。 |
3452
3453**示例:**
3454
3455  ```ts
3456  let that = new util.types();
3457  let result = that.isWeakSet(new WeakSet());
3458  ```
3459
3460
3461### isBigInt64Array<sup>8+</sup>
3462
3463isBigInt64Array(value: Object): boolean
3464
3465检查输入的value是否是BigInt64Array类型。
3466
3467**系统能力:** SystemCapability.Utils.Lang
3468
3469**参数:**
3470
3471| 参数名 | 类型 | 必填 | 说明 |
3472| -------- | -------- | -------- | -------- |
3473| value | Object | 是 | 待检测对象。 |
3474
3475**返回值:**
3476
3477| 类型 | 说明 |
3478| -------- | -------- |
3479| boolean | 判断的结果,如果是内置包含的BigInt64Array类型为true,反之为false。 |
3480
3481**示例:**
3482
3483  ```ts
3484  let that = new util.types();
3485  let result = that.isBigInt64Array(new BigInt64Array([]));
3486  ```
3487
3488
3489### isBigUint64Array<sup>8+</sup>
3490
3491isBigUint64Array(value: Object): boolean
3492
3493检查输入的value是否是BigUint64Array类型。
3494
3495**系统能力:** SystemCapability.Utils.Lang
3496
3497**参数:**
3498
3499| 参数名 | 类型 | 必填 | 说明 |
3500| -------- | -------- | -------- | -------- |
3501| value | Object | 是 | 待检测对象。 |
3502
3503**返回值:**
3504
3505| 类型 | 说明 |
3506| -------- | -------- |
3507| boolean | 判断的结果,如果是内置包含的BigUint64Array类型为true,反之为false。 |
3508
3509**示例:**
3510
3511  ```ts
3512  let that = new util.types();
3513  let result = that.isBigUint64Array(new BigUint64Array([]));
3514  ```
3515
3516
3517### isModuleNamespaceObject<sup>8+</sup>
3518
3519isModuleNamespaceObject(value: Object): boolean
3520
3521检查输入的value是否是Module Namespace Object类型。
3522
3523**系统能力:** SystemCapability.Utils.Lang
3524
3525**参数:**
3526
3527| 参数名 | 类型 | 必填 | 说明 |
3528| -------- | -------- | -------- | -------- |
3529| value | Object | 是 | 待检测对象。 |
3530
3531**返回值:**
3532
3533| 类型 | 说明 |
3534| -------- | -------- |
3535| boolean | 判断的结果,如果是内置包含的Module Namespace Object类型为true,反之为false。 |
3536
3537**示例:**
3538
3539  ```ts
3540  import url from '@ohos.url'
3541  let that = new util.types();
3542  let result = that.isModuleNamespaceObject(url);
3543  ```
3544
3545
3546### isSharedArrayBuffer<sup>8+</sup>
3547
3548isSharedArrayBuffer(value: Object): boolean
3549
3550检查输入的value是否是SharedArrayBuffer类型。
3551
3552**系统能力:** SystemCapability.Utils.Lang
3553
3554**参数:**
3555
3556| 参数名 | 类型 | 必填 | 说明 |
3557| -------- | -------- | -------- | -------- |
3558| value | Object | 是 | 待检测对象。 |
3559
3560**返回值:**
3561
3562| 类型 | 说明 |
3563| -------- | -------- |
3564| boolean | 判断的结果,如果是内置包含的SharedArrayBuffer类型为true,反之为false。 |
3565
3566**示例:**
3567
3568  ```ts
3569  let that = new util.types();
3570  let result = that.isSharedArrayBuffer(new SharedArrayBuffer(0));
3571  ```
3572
3573## LruBuffer<sup>(deprecated)</sup>
3574
3575> **说明:**
3576>
3577> 从API version 8开始支持,从API version 9开始废弃,建议使用[LRUCache<sup>9+</sup>](#lrucache9)替代。
3578
3579### 属性
3580
3581**系统能力:** 以下各项对应的系统能力均为SystemCapability.Utils.Lang3582
3583| 名称 | 类型 | 可读 | 可写 | 说明 |
3584| -------- | -------- | -------- | -------- | -------- |
3585| length | number | 是 | 否 | 当前缓冲区中值的总数。 |
3586
3587**示例:**
3588
3589  ```ts
3590  let pro : util.LruBuffer<number,number>= new util.LruBuffer();
3591  pro.put(2,10);
3592  pro.put(1,8);
3593  let result = pro.length;
3594  ```
3595
3596### constructor<sup>(deprecated)</sup>
3597
3598constructor(capacity?: number)
3599
3600默认构造函数用于创建一个新的LruBuffer实例,默认容量为64。
3601
3602> **说明:**
3603>
3604> 从API version 8开始支持,从API version 9开始废弃,建议使用[LRUCache.constructor<sup>9+</sup>](#constructor9-3)替代。
3605
3606**系统能力:** SystemCapability.Utils.Lang
3607
3608**参数:**
3609
3610| 参数名 | 类型 | 必填 | 说明 |
3611| -------- | -------- | -------- | -------- |
3612| capacity | number | 否 | 指示要为缓冲区自定义的容量,默认值为64。 |
3613
3614**示例:**
3615
3616  ```ts
3617  let lrubuffer : util.LruBuffer<number,number> = new util.LruBuffer();
3618  ```
3619
3620### updateCapacity<sup>(deprecated)</sup>
3621
3622updateCapacity(newCapacity: number): void
3623
3624将缓冲区容量更新为指定容量,如果newCapacity小于或等于0,则抛出异常。
3625
3626> **说明:**
3627>
3628> 从API version 8开始支持,从API version 9开始废弃,建议使用[LRUCache.updateCapacity<sup>9+</sup>](#updatecapacity9)替代。
3629
3630**系统能力:** SystemCapability.Utils.Lang
3631
3632**参数:**
3633
3634| 参数名 | 类型 | 必填 | 说明 |
3635| -------- | -------- | -------- | -------- |
3636| newCapacity | number | 是 | 指示要为缓冲区自定义的容量。 |
3637
3638**示例:**
3639
3640  ```ts
3641  let pro : util.LruBuffer<number,number> = new util.LruBuffer();
3642  let result = pro.updateCapacity(100);
3643  ```
3644
3645### toString<sup>(deprecated)</sup>
3646
3647toString(): string
3648
3649返回对象的字符串表示形式。
3650
3651> **说明:**
3652>
3653> 从API version 8开始支持,从API version 9开始废弃,建议使用[LRUCache.toString<sup>9+</sup>](#tostring9)替代。
3654
3655**系统能力:** SystemCapability.Utils.Lang
3656
3657**返回值:**
3658
3659| 类型 | 说明 |
3660| -------- | -------- |
3661| string | 返回对象的字符串表示形式。 |
3662
3663**示例:**
3664
3665  ```ts
3666  let pro : util.LruBuffer<number,number> = new util.LruBuffer();
3667  pro.put(2,10);
3668  pro.get(2);
3669  pro.remove(20);
3670  let result = pro.toString();
3671  ```
3672
3673### getCapacity<sup>(deprecated)</sup>
3674
3675getCapacity(): number
3676
3677获取当前缓冲区的容量。
3678
3679> **说明:**
3680>
3681> 从API version 8开始支持,从API version 9开始废弃,建议使用[LRUCache.getCapacity<sup>9+</sup>](#getcapacity9)替代。
3682
3683**系统能力:** SystemCapability.Utils.Lang
3684
3685**返回值:**
3686
3687| 类型 | 说明 |
3688| -------- | -------- |
3689| number | 返回当前缓冲区的容量。 |
3690
3691**示例:**
3692
3693  ```ts
3694  let pro : util.LruBuffer<number,number> = new util.LruBuffer();
3695  let result = pro.getCapacity();
3696  ```
3697
3698### clear<sup>(deprecated)</sup>
3699
3700clear(): void
3701
3702从当前缓冲区清除键值对。后续会调用afterRemoval()方法执行后续操作。
3703
3704> **说明:**
3705>
3706> 从API version 8开始支持,从API version 9开始废弃,建议使用[LRUCache.clear<sup>9+</sup>](#clear9)替代。
3707
3708**系统能力:** SystemCapability.Utils.Lang
3709
3710**示例:**
3711
3712  ```ts
3713  let pro : util.LruBuffer<number,number> = new util.LruBuffer();
3714  pro.put(2,10);
3715  let result = pro.length;
3716  pro.clear();
3717  ```
3718
3719### getCreateCount<sup>(deprecated)</sup>
3720
3721getCreateCount(): number
3722
3723获取createDefault()返回值的次数。
3724
3725> **说明:**
3726>
3727> 从API version 8开始支持,从API version 9开始废弃,建议使用[LRUCache.getCreateCount<sup>9+</sup>](#getcreatecount9)替代。
3728
3729**系统能力:** SystemCapability.Utils.Lang
3730
3731**返回值:**
3732
3733| 类型 | 说明 |
3734| -------- | -------- |
3735| number | 返回createDefault()返回值的次数。 |
3736
3737**示例:**
3738
3739  ```ts
3740  let pro : util.LruBuffer<number,number> = new util.LruBuffer();
3741  pro.put(1,8);
3742  let result = pro.getCreateCount();
3743  ```
3744
3745### getMissCount<sup>(deprecated)</sup>
3746
3747getMissCount(): number
3748
3749获取查询值不匹配的次数。
3750
3751> **说明:**
3752>
3753> 从API version 8开始支持,从API version 9开始废弃,建议使用[LRUCache.getMissCount<sup>9+</sup>](#getmisscount9)替代。
3754
3755**系统能力:** SystemCapability.Utils.Lang
3756
3757**返回值:**
3758
3759| 类型 | 说明 |
3760| -------- | -------- |
3761| number | 返回查询值不匹配的次数。 |
3762
3763**示例:**
3764
3765  ```ts
3766  let pro : util.LruBuffer<number,number> = new util.LruBuffer();
3767  pro.put(2,10);
3768  pro.get(2);
3769  let result = pro.getMissCount();
3770  ```
3771
3772### getRemovalCount<sup>(deprecated)</sup>
3773
3774getRemovalCount(): number
3775
3776获取从缓冲区中逐出值的次数。
3777
3778> **说明:**
3779>
3780> 从API version 8开始支持,从API version 9开始废弃,建议使用[LRUCache.getRemovalCount<sup>9+</sup>](#getremovalcount9)替代。
3781
3782**系统能力:** SystemCapability.Utils.Lang
3783
3784**返回值:**
3785
3786| 类型 | 说明 |
3787| -------- | -------- |
3788| number | 返回从缓冲区中驱逐的次数。 |
3789
3790**示例:**
3791
3792  ```ts
3793  let pro : util.LruBuffer<number,number> = new util.LruBuffer();
3794  pro.put(2,10);
3795  pro.updateCapacity(2);
3796  pro.put(50,22);
3797  let result = pro.getRemovalCount();
3798  ```
3799
3800### getMatchCount<sup>(deprecated)</sup>
3801
3802getMatchCount(): number
3803
3804获取查询值匹配成功的次数。
3805
3806> **说明:**
3807>
3808> 从API version 8开始支持,从API version 9开始废弃,建议使用[LRUCache.getMatchCount<sup>9+</sup>](#getmatchcount9)替代。
3809
3810**系统能力:** SystemCapability.Utils.Lang
3811
3812**返回值:**
3813
3814| 类型 | 说明 |
3815| -------- | -------- |
3816| number | 返回查询值匹配成功的次数。 |
3817
3818**示例:**
3819
3820  ```ts
3821  let pro : util.LruBuffer<number,number> = new util.LruBuffer();
3822  pro.put(2,10);
3823  pro.get(2);
3824  let result = pro.getMatchCount();
3825  ```
3826
3827### getPutCount<sup>(deprecated)</sup>
3828
3829getPutCount(): number
3830
3831获取将值添加到缓冲区的次数。
3832
3833> **说明:**
3834>
3835> 从API version 8开始支持,从API version 9开始废弃,建议使用[LRUCache.getPutCount<sup>9+</sup>](#getputcount9)替代。
3836
3837**系统能力:** SystemCapability.Utils.Lang
3838
3839**返回值:**
3840
3841| 类型 | 说明 |
3842| -------- | -------- |
3843| number | 返回将值添加到缓冲区的次数。 |
3844
3845**示例:**
3846
3847  ```ts
3848  let pro : util.LruBuffer<number,number> = new util.LruBuffer();
3849  pro.put(2,10);
3850  let result = pro.getPutCount();
3851  ```
3852
3853### isEmpty<sup>(deprecated)</sup>
3854
3855isEmpty(): boolean
3856
3857检查当前缓冲区是否为空。
3858
3859> **说明:**
3860>
3861> 从API version 8开始支持,从API version 9开始废弃,建议使用[LRUCache.isEmpty<sup>9+</sup>](#isempty9)替代。
3862
3863**系统能力:** SystemCapability.Utils.Lang
3864
3865**返回值:**
3866
3867| 类型 | 说明 |
3868| -------- | -------- |
3869| boolean | 如果当前缓冲区不包含任何值,则返回true。 |
3870
3871**示例:**
3872
3873  ```ts
3874  let pro : util.LruBuffer<number,number> = new util.LruBuffer();
3875  pro.put(2,10);
3876  let result = pro.isEmpty();
3877  ```
3878
3879### get<sup>(deprecated)</sup>
3880
3881get(key: K): V | undefined
3882
3883表示要查询的键。
3884
3885> **说明:**
3886>
3887> 从API version 8开始支持,从API version 9开始废弃,建议使用[LRUCache.get<sup>9+</sup>](#get9)替代。
3888
3889**系统能力:** SystemCapability.Utils.Lang
3890
3891**参数:**
3892
3893| 参数名 | 类型 | 必填 | 说明 |
3894| -------- | -------- | -------- | -------- |
3895| key | K | 是 | 要查询的键。 |
3896
3897**返回值:**
3898
3899| 类型 | 说明 |
3900| -------- | -------- |
3901| V&nbsp;\|&nbsp;undefined | 如果指定的键存在于缓冲区中,则返回与键关联的值;否则返回undefined。 |
3902
3903**示例:**
3904
3905  ```ts
3906  let pro : util.LruBuffer<number,number> = new util.LruBuffer();
3907  pro.put(2,10);
3908  let result  = pro.get(2);
3909  ```
3910
3911### put<sup>(deprecated)</sup>
3912
3913put(key: K,value: V): V
3914
3915将键值对添加到缓冲区。
3916
3917> **说明:**
3918>
3919> 从API version 8开始支持,从API version 9开始废弃,建议使用[LRUCache.put<sup>9+</sup>](#put9)替代。
3920
3921**系统能力:** SystemCapability.Utils.Lang
3922
3923**参数:**
3924
3925| 参数名 | 类型 | 必填 | 说明 |
3926| -------- | -------- | -------- | -------- |
3927| key | K | 是 | 要添加的密钥。 |
3928| value | V | 是 | 指示与要添加的键关联的值。 |
3929
3930**返回值:**
3931
3932| 类型 | 说明 |
3933| -------- | -------- |
3934| V | 返回与添加的键关联的值;如果要添加的键已经存在,则返回原始值,如果键或值为空,则抛出此异常。 |
3935
3936**示例:**
3937
3938  ```ts
3939  let pro : util.LruBuffer<number,number> = new util.LruBuffer();
3940  let result = pro.put(2,10);
3941  ```
3942
3943### values<sup>(deprecated)</sup>
3944
3945values(): V[]
3946
3947获取当前缓冲区中所有值从最近访问到最近最少访问的顺序列表。
3948
3949> **说明:**
3950>
3951> 从API version 8开始支持,从API version 9开始废弃,建议使用[LRUCache.values<sup>9+</sup>](#values9)替代。
3952
3953**系统能力:** SystemCapability.Utils.Lang
3954
3955**返回值:**
3956
3957| 类型 | 说明 |
3958| -------- | -------- |
3959| V&nbsp;[] | 按从最近访问到最近最少访问的顺序返回当前缓冲区中所有值的列表。 |
3960
3961**示例:**
3962
3963  ```ts
3964  let pro : util.LruBuffer<number|string,number|string> = new util.LruBuffer();
3965  pro.put(2,10);
3966  pro.put(2,"anhu");
3967  pro.put("afaf","grfb");
3968  let result = pro.values();
3969  ```
3970
3971### keys<sup>(deprecated)</sup>
3972
3973keys(): K[]
3974
3975获取当前缓冲区中所有键从最近访问到最近最少访问的升序列表。
3976
3977> **说明:**
3978>
3979> 从API version 8开始支持,从API version 9开始废弃,建议使用[LRUCache.keys<sup>9+</sup>](#keys9)替代。
3980
3981**系统能力:** SystemCapability.Utils.Lang
3982
3983**返回值:**
3984
3985| 类型 | 说明 |
3986| -------- | -------- |
3987| K&nbsp;[] | 按升序返回当前缓冲区中所有键的列表,从最近访问到最近最少访问。 |
3988
3989**示例:**
3990
3991  ```ts
3992  let pro : util.LruBuffer<number,number> = new util.LruBuffer();
3993  pro.put(2,10);
3994  let result = pro.keys();
3995  ```
3996
3997### remove<sup>(deprecated)</sup>
3998
3999remove(key: K): V | undefined
4000
4001从当前缓冲区中删除指定的键及其关联的值。
4002
4003> **说明:**
4004>
4005> 从API version 8开始支持,从API version 9开始废弃,建议使用[LRUCache.remove<sup>9+</sup>](#remove9)替代。
4006
4007**系统能力:** SystemCapability.Utils.Lang
4008
4009**参数:**
4010
4011| 参数名 | 类型 | 必填 | 说明 |
4012| -------- | -------- | -------- | -------- |
4013| key | K | 是 | 要删除的密钥。 |
4014
4015**返回值:**
4016
4017| 类型 | 说明 |
4018| -------- | -------- |
4019| V&nbsp;\|&nbsp;undefined | 返回一个包含已删除键值对的Optional对象;如果key不存在,则返回一个空的Optional对象,如果key为null,则抛出异常。 |
4020
4021**示例:**
4022
4023  ```ts
4024  let pro : util.LruBuffer<number,number> = new util.LruBuffer();
4025  pro.put(2,10);
4026  let result = pro.remove(20);
4027  ```
4028
4029### afterRemoval<sup>(deprecated)</sup>
4030
4031afterRemoval(isEvict: boolean,key: K,value: V,newValue: V): void
4032
4033删除值后执行后续操作。
4034
4035> **说明:**
4036>
4037> 从API version 8开始支持,从API version 9开始废弃,建议使用[LRUCache.afterRemoval<sup>9+</sup>](#afterremoval9)替代。
4038
4039**系统能力:** SystemCapability.Utils.Lang
4040
4041**参数:**
4042
4043| 参数名 | 类型 | 必填 | 说明 |
4044| -------- | -------- | -------- | -------- |
4045| isEvict | boolean | 是 | 因容量不足而调用该方法时,参数值为true,其他情况为false。 |
4046| key | K | 是 | 表示删除的键。 |
4047| value | V | 是 | 表示删除的值。 |
4048| newValue | V | 是 | 如果已调用put方法并且要添加的键已经存在,则参数值是关联的新值。其他情况下参数值为空。 |
4049
4050**示例:**
4051
4052  ```ts
4053  let arr : object = [];
4054  class ChildLruBuffer<K, V> extends util.LruBuffer<K, V>
4055  {
4056  	constructor()
4057  	{
4058  		super();
4059  	}
4060  	afterRemoval(isEvict : boolean, key : K, value : V, newValue : V)
4061  	{
4062  		if (isEvict === false)
4063  		{
4064  			arr = [key, value, newValue];
4065  		}
4066  	}
4067  }
4068  let lru : ChildLruBuffer<number,number|null> = new ChildLruBuffer();
4069  lru.afterRemoval(false,10,30,null);
4070  ```
4071
4072### contains<sup>(deprecated)</sup>
4073
4074contains(key: K): boolean
4075
4076检查当前缓冲区是否包含指定的键。
4077
4078
4079> **说明:**
4080>
4081> 从API version 8开始支持,从API version 9开始废弃,建议使用[LRUCache.contains<sup>9+</sup>](#contains9)替代。
4082
4083**系统能力:** SystemCapability.Utils.Lang
4084
4085**参数:**
4086
4087| 参数名 | 类型 | 必填 | 说明 |
4088| -------- | -------- | -------- | -------- |
4089| key | K | 是 | 表示要检查的键。 |
4090
4091**返回值:**
4092
4093| 类型 | 说明 |
4094| -------- | -------- |
4095| boolean | 如果缓冲区包含指定的键,则返回&nbsp;true。 |
4096
4097**示例:**
4098
4099  ```ts
4100  let pro : util.LruBuffer<number,number> = new util.LruBuffer();
4101  pro.put(2,10);
4102  let result = pro.contains(20);
4103  ```
4104
4105### createDefault<sup>(deprecated)</sup>
4106
4107createDefault(key: K): V
4108
4109如果未计算特定键的值,则执行后续操作,参数表示丢失的键,返回与键关联的值。
4110
4111> **说明:**
4112>
4113> 从API version 8开始支持,从API version 9开始废弃,建议使用[LRUCache.createDefault<sup>9+</sup>](#createdefault9)替代。
4114
4115**系统能力:** SystemCapability.Utils.Lang
4116
4117**参数:**
4118
4119| 参数名 | 类型 | 必填 | 说明 |
4120| -------- | -------- | -------- | -------- |
4121| key | K | 是 | 表示丢失的键。 |
4122
4123**返回值:**
4124
4125| 类型 | 说明 |
4126| -------- | -------- |
4127| V | 返回与键关联的值。 |
4128
4129**示例:**
4130
4131  ```ts
4132  let pro : util.LruBuffer<number,number> = new util.LruBuffer();
4133  let result = pro.createDefault(50);
4134  ```
4135
4136### entries<sup>(deprecated)</sup>
4137
4138entries(): IterableIterator&lt;[K,V]&gt;
4139
4140允许迭代包含在这个对象中的所有键值对。
4141
4142> **说明:**
4143>
4144> 从API version 8开始支持,从API version 9开始废弃,建议使用[LRUCache.entries<sup>9+</sup>](#entries9)替代。
4145
4146**系统能力:** SystemCapability.Utils.Lang
4147
4148**返回值:**
4149
4150| 类型 | 说明 |
4151| -------- | -------- |
4152| [K,&nbsp;V] | 返回一个可迭代数组。 |
4153
4154**示例:**
4155
4156  ```ts
4157  let pro : util.LruBuffer<number,number> = new util.LruBuffer();
4158  pro.put(2,10);
4159  let result = pro.entries();
4160  ```
4161
4162### [Symbol.iterator]<sup>(deprecated)</sup>
4163
4164[Symbol.iterator]\(): IterableIterator&lt;[K, V]&gt;
4165
4166返回一个键值对形式的二维数组。
4167
4168> **说明:**
4169>
4170> 从API version 8开始支持,从API version 9开始废弃,建议使用[LRUCache.Symbol.iterator<sup>9+</sup>](#symboliterator9)替代。
4171
4172**系统能力:** SystemCapability.Utils.Lang
4173
4174**返回值:**
4175
4176| 类型 | 说明 |
4177| -------- | -------- |
4178| [K,&nbsp;V] | 返回一个键值对形式的二维数组。 |
4179
4180**示例:**
4181
4182  ```ts
4183  let pro : util.LruBuffer<number,number> = new util.LruBuffer();
4184  pro.put(2,10);
4185  let result = pro[Symbol.iterator]();
4186  ```
4187
4188## Scope<sup>(deprecated)</sup>
4189
4190> **说明:**
4191>
4192> 从API version 8开始支持,从API version 9开始废弃,建议使用[ScopeHelper<sup>9+</sup>](#scopehelper9)替代。
4193
4194### constructor<sup>(deprecated)</sup>
4195
4196constructor(lowerObj: ScopeType, upperObj: ScopeType)
4197
4198用于创建指定下限和上限的作用域实例的构造函数,返回一个Scope对象。
4199
4200> **说明:**
4201>
4202> 从API version 8开始支持,从API version 9开始废弃,建议使用[ScopeHelper.constructor<sup>9+</sup>](#constructor9-4)替代。
4203
4204
4205**系统能力:** SystemCapability.Utils.Lang
4206
4207**参数:**
4208
4209| 参数名 | 类型 | 必填 | 说明 |
4210| -------- | -------- | -------- | -------- |
4211| lowerObj | [ScopeType](#scopetype8) | 是 | 指定作用域实例的下限。 |
4212| upperObj | [ScopeType](#scopetype8) | 是 | 指定作用域实例的上限。 |
4213
4214**示例:**
4215  ```ts
4216  class Temperature{
4217    private readonly _temp: number;
4218    constructor(value : number) {
4219      this._temp = value;
4220    }
4221    compareTo(value : Temperature ) {
4222      return this._temp >= value.getTemp();
4223    }
4224    getTemp() {
4225      return this._temp;
4226    }
4227    toString() : string {
4228      return this._temp.toString();
4229    }
4230  }
4231  let tempLower = new Temperature(30);
4232  let tempUpper = new Temperature(40);
4233  let range = new util.Scope(tempLower, tempUpper);
4234  ```
4235
4236### toString<sup>(deprecated)</sup>
4237
4238toString(): string
4239
4240该字符串化方法返回一个包含当前范围的字符串表示形式。
4241
4242> **说明:**
4243>
4244> 从API version 8开始支持,从API version 9开始废弃,建议使用[ScopeHelper.toString<sup>9+</sup>](#tostring9-1)替代。
4245
4246**系统能力:** SystemCapability.Utils.Lang
4247
4248**返回值:**
4249
4250| 类型 | 说明 |
4251| -------- | -------- |
4252| string | 返回包含当前范围对象的字符串表示形式。 |
4253
4254**示例:**
4255
4256  ```ts
4257  class Temperature{
4258    private readonly _temp: number;
4259    constructor(value : number) {
4260      this._temp = value;
4261    }
4262    compareTo(value : Temperature ) {
4263      return this._temp >= value.getTemp();
4264    }
4265    getTemp() {
4266      return this._temp;
4267    }
4268    toString() : string {
4269      return this._temp.toString();
4270    }
4271  }
4272
4273  let tempLower = new Temperature(30);
4274  let tempUpper = new Temperature(40);
4275  let range = new util.Scope(tempLower, tempUpper);
4276  let result = range.toString();
4277  ```
4278
4279### intersect<sup>(deprecated)</sup>
4280
4281intersect(range: Scope): Scope
4282
4283获取给定范围和当前范围的交集。
4284
4285> **说明:**
4286>
4287> 从API version 8开始支持,从API version 9开始废弃,建议使用[ScopeHelper.intersect<sup>9+</sup>](#intersect9)替代。
4288
4289**系统能力:** SystemCapability.Utils.Lang
4290
4291**参数:**
4292
4293| 参数名 | 类型 | 必填 | 说明 |
4294| -------- | -------- | -------- | -------- |
4295| range | [Scope](#scopedeprecated) | 是 | 传入一个给定范围。 |
4296
4297**返回值:**
4298
4299| 类型 | 说明 |
4300| -------- | -------- |
4301| [Scope](#scopedeprecated) | 返回给定范围和当前范围的交集。 |
4302
4303**示例:**
4304
4305  ```ts
4306  class Temperature{
4307    private readonly _temp: number;
4308    constructor(value : number) {
4309      this._temp = value;
4310    }
4311    compareTo(value : Temperature ) {
4312      return this._temp >= value.getTemp();
4313    }
4314    getTemp() {
4315      return this._temp;
4316    }
4317    toString() : string {
4318      return this._temp.toString();
4319    }
4320  }
4321
4322  let tempLower = new Temperature(30);
4323  let tempUpper = new Temperature(40);
4324  let range = new util.Scope(tempLower, tempUpper);
4325  let tempMiDF = new Temperature(35);
4326  let tempMidS = new Temperature(39);
4327  let rangeFir = new util.Scope(tempMiDF, tempMidS);
4328  let result = range.intersect(rangeFir );
4329  ```
4330
4331### intersect<sup>(deprecated)</sup>
4332
4333intersect(lowerObj:ScopeType,upperObj:ScopeType):Scope
4334
4335获取当前范围与给定下限和上限范围的交集。
4336
4337> **说明:**
4338>
4339> 从API version 8开始支持,从API version 9开始废弃,建议使用[ScopeHelper.intersect<sup>9+</sup>](#intersect9-1)替代。
4340
4341**系统能力:** SystemCapability.Utils.Lang
4342
4343**参数:**
4344
4345| 参数名 | 类型 | 必填 | 说明 |
4346| -------- | -------- | -------- | -------- |
4347| lowerObj | [ScopeType](#scopetype8) | 是 | 给定范围的下限。 |
4348| upperObj | [ScopeType](#scopetype8) | 是 | 给定范围的上限。 |
4349
4350**返回值:**
4351
4352| 类型 | 说明 |
4353| -------- | -------- |
4354| [Scope](#scopedeprecated) | 返回当前范围与给定下限和上限范围的交集。 |
4355
4356**示例:**
4357
4358  ```ts
4359  class Temperature{
4360    private readonly _temp: number;
4361    constructor(value : number) {
4362      this._temp = value;
4363    }
4364    compareTo(value : Temperature ) {
4365      return this._temp >= value.getTemp();
4366    }
4367    getTemp() {
4368      return this._temp;
4369    }
4370    toString() : string {
4371      return this._temp.toString();
4372    }
4373  }
4374
4375  let tempLower = new Temperature(30);
4376  let tempUpper = new Temperature(40);
4377  let tempMiDF = new Temperature(35);
4378  let tempMidS = new Temperature(39);
4379  let range = new util.Scope(tempLower, tempUpper);
4380  let result = range.intersect(tempMiDF, tempMidS);
4381  ```
4382
4383### getUpper<sup>(deprecated)</sup>
4384
4385getUpper(): ScopeType
4386
4387获取当前范围的上限。
4388
4389> **说明:**
4390>
4391> 从API version 8开始支持,从API version 9开始废弃,建议使用[ScopeHelper.getUpper<sup>9+</sup>](#getupper9)替代。
4392
4393**系统能力:** SystemCapability.Utils.Lang
4394
4395**返回值:**
4396
4397| 类型 | 说明 |
4398| -------- | -------- |
4399| [ScopeType](#scopetype8) | 返回当前范围的上限值。 |
4400
4401**示例:**
4402
4403  ```ts
4404  class Temperature{
4405    private readonly _temp: number;
4406    constructor(value : number) {
4407      this._temp = value;
4408    }
4409    compareTo(value : Temperature ) {
4410      return this._temp >= value.getTemp();
4411    }
4412    getTemp() {
4413      return this._temp;
4414    }
4415    toString() : string {
4416      return this._temp.toString();
4417    }
4418  }
4419
4420  let tempLower = new Temperature(30);
4421  let tempUpper = new Temperature(40);
4422  let range = new util.Scope(tempLower, tempUpper);
4423  let result = range.getUpper();
4424  ```
4425
4426### getLower<sup>(deprecated)</sup>
4427
4428getLower(): ScopeType
4429
4430获取当前范围的下限。
4431
4432> **说明:**
4433>
4434> 从API version 8开始支持,从API version 9开始废弃,建议使用[ScopeHelper.getLower<sup>9+</sup>](#getlower9)替代。
4435
4436**系统能力:** SystemCapability.Utils.Lang
4437
4438**返回值:**
4439
4440| 类型 | 说明 |
4441| -------- | -------- |
4442| [ScopeType](#scopetype8) | 返回当前范围的下限值。 |
4443
4444**示例:**
4445
4446  ```ts
4447  class Temperature{
4448    private readonly _temp: number;
4449    constructor(value : number) {
4450      this._temp = value;
4451    }
4452    compareTo(value : Temperature ) {
4453      return this._temp >= value.getTemp();
4454    }
4455    getTemp() {
4456      return this._temp;
4457    }
4458    toString() : string {
4459      return this._temp.toString();
4460    }
4461  }
4462
4463  let tempLower = new Temperature(30);
4464  let tempUpper = new Temperature(40);
4465  let range = new util.Scope(tempLower, tempUpper);
4466  let result = range.getLower();
4467  ```
4468
4469### expand<sup>(deprecated)</sup>
4470
4471expand(lowerObj: ScopeType,upperObj: ScopeType): Scope
4472
4473创建并返回包括当前范围和给定下限和上限的并集。
4474
4475> **说明:**
4476>
4477> 从API version 8开始支持,从API version 9开始废弃,建议使用[ScopeHelper.expand<sup>9+</sup>](#expand9)替代。
4478
4479**系统能力:** SystemCapability.Utils.Lang
4480
4481**参数:**
4482
4483| 参数名 | 类型 | 必填 | 说明 |
4484| -------- | -------- | -------- | -------- |
4485| lowerObj | [ScopeType](#scopetype8) | 是 | 给定范围的下限。 |
4486| upperObj | [ScopeType](#scopetype8) | 是 | 给定范围的上限。 |
4487
4488**返回值:**
4489
4490| 类型 | 说明 |
4491| -------- | -------- |
4492| [Scope](#scopedeprecated) | 返回当前范围和给定下限和上限的并集。 |
4493
4494**示例:**
4495
4496  ```ts
4497  class Temperature{
4498    private readonly _temp: number;
4499    constructor(value : number) {
4500      this._temp = value;
4501    }
4502    compareTo(value : Temperature ) {
4503      return this._temp >= value.getTemp();
4504    }
4505    getTemp() {
4506      return this._temp;
4507    }
4508    toString() : string {
4509      return this._temp.toString();
4510    }
4511  }
4512
4513  let tempLower = new Temperature(30);
4514  let tempUpper = new Temperature(40);
4515  let tempMiDF = new Temperature(35);
4516  let tempMidS = new Temperature(39);
4517  let range = new util.Scope(tempLower, tempUpper);
4518  let result = range.expand(tempMiDF, tempMidS);
4519  ```
4520
4521### expand<sup>(deprecated)</sup>
4522
4523expand(range: Scope): Scope
4524
4525创建并返回包括当前范围和给定范围的并集。
4526
4527> **说明:**
4528>
4529> 从API version 8开始支持,从API version 9开始废弃,建议使用[ScopeHelper.expand<sup>9+</sup>](#expand9-1)替代。
4530
4531**系统能力:** SystemCapability.Utils.Lang
4532
4533**参数:**
4534
4535| 参数名 | 类型 | 必填 | 说明 |
4536| -------- | -------- | -------- | -------- |
4537| range | [Scope](#scopedeprecated) | 是 | 传入一个给定范围。 |
4538
4539**返回值:**
4540
4541| 类型 | 说明 |
4542| -------- | -------- |
4543| [Scope](#scopedeprecated) | 返回包括当前范围和给定范围的并集。 |
4544
4545**示例:**
4546
4547  ```ts
4548  class Temperature{
4549    private readonly _temp: number;
4550    constructor(value : number) {
4551      this._temp = value;
4552    }
4553    compareTo(value : Temperature ) {
4554      return this._temp >= value.getTemp();
4555    }
4556    getTemp() {
4557      return this._temp;
4558    }
4559    toString() : string {
4560      return this._temp.toString();
4561    }
4562  }
4563
4564  let tempLower = new Temperature(30);
4565  let tempUpper = new Temperature(40);
4566  let tempMiDF = new Temperature(35);
4567  let tempMidS = new Temperature(39);
4568  let range = new util.Scope(tempLower, tempUpper);
4569  let rangeFir = new util.Scope(tempMiDF, tempMidS);
4570  let result = range.expand(rangeFir);
4571  ```
4572
4573### expand<sup>(deprecated)</sup>
4574
4575expand(value: ScopeType): Scope
4576
4577创建并返回包括当前范围和给定值的并集。
4578
4579> **说明:**
4580>
4581> 从API version 8开始支持,从API version 9开始废弃,建议使用[ScopeHelper.expand<sup>9+</sup>](#expand9-2)替代。
4582
4583**系统能力:** SystemCapability.Utils.Lang
4584
4585**参数:**
4586
4587| 参数名 | 类型 | 必填 | 说明 |
4588| -------- | -------- | -------- | -------- |
4589| value | [ScopeType](#scopetype8) | 是 | 传入一个给定值。 |
4590
4591**返回值:**
4592
4593| 类型 | 说明 |
4594| -------- | -------- |
4595| [Scope](#scopedeprecated) | 返回包括当前范围和给定值的并集。 |
4596
4597**示例:**
4598
4599  ```ts
4600  class Temperature{
4601    private readonly _temp: number;
4602    constructor(value : number) {
4603      this._temp = value;
4604    }
4605    compareTo(value : Temperature ) {
4606      return this._temp >= value.getTemp();
4607    }
4608    getTemp() {
4609      return this._temp;
4610    }
4611    toString() : string {
4612      return this._temp.toString();
4613    }
4614  }
4615
4616  let tempLower = new Temperature(30);
4617  let tempUpper = new Temperature(40);
4618  let tempMiDF = new Temperature(35);
4619  let range = new util.Scope(tempLower, tempUpper);
4620  let result = range.expand(tempMiDF);
4621  ```
4622
4623### contains<sup>(deprecated)</sup>
4624
4625contains(value: ScopeType): boolean
4626
4627检查给定value是否包含在当前范围内。
4628
4629> **说明:**
4630>
4631> 从API version 8开始支持,从API version 9开始废弃,建议使用[ScopeHelper.contains<sup>9+</sup>](#contains9-1)替代。
4632
4633**系统能力:** SystemCapability.Utils.Lang
4634
4635**参数:**
4636
4637| 参数名 | 类型 | 必填 | 说明 |
4638| -------- | -------- | -------- | -------- |
4639| value | [ScopeType](#scopetype8) | 是 | 传入一个给定值。 |
4640
4641**返回值:**
4642
4643| 类型 | 说明 |
4644| -------- | -------- |
4645| boolean | 如果给定值包含在当前范围内返回true,否则返回false。 |
4646
4647**示例:**
4648
4649  ```ts
4650  class Temperature{
4651    private readonly _temp: number;
4652    constructor(value : number) {
4653      this._temp = value;
4654    }
4655    compareTo(value : Temperature ) {
4656      return this._temp >= value.getTemp();
4657    }
4658    getTemp() {
4659      return this._temp;
4660    }
4661    toString() : string {
4662      return this._temp.toString();
4663    }
4664  }
4665
4666  let tempLower = new Temperature(30);
4667  let tempUpper = new Temperature(40);
4668  let tempMiDF = new Temperature(35);
4669  let range = new util.Scope(tempLower, tempUpper);
4670  let result = range.contains(tempMiDF);
4671  ```
4672
4673### contains<sup>(deprecated)</sup>
4674
4675contains(range: Scope): boolean
4676
4677检查给定range是否在当前范围内。
4678
4679> **说明:**
4680>
4681> 从API version 8开始支持,从API version 9开始废弃,建议使用[ScopeHelper.contains<sup>9+</sup>](#contains9-2)替代。
4682
4683**系统能力:** SystemCapability.Utils.Lang
4684
4685**参数:**
4686
4687| 参数名 | 类型 | 必填 | 说明 |
4688| -------- | -------- | -------- | -------- |
4689| range | [Scope](#scopedeprecated) | 是 | 传入一个给定范围。 |
4690
4691**返回值:**
4692
4693| 类型 | 说明 |
4694| -------- | -------- |
4695| boolean | 如果给定范围包含在当前范围内返回true,否则返回false。 |
4696
4697**示例:**
4698
4699  ```ts
4700  class Temperature{
4701    private readonly _temp: number;
4702    constructor(value : number) {
4703      this._temp = value;
4704    }
4705    compareTo(value : Temperature ) {
4706      return this._temp >= value.getTemp();
4707    }
4708    getTemp() {
4709      return this._temp;
4710    }
4711    toString() : string {
4712      return this._temp.toString();
4713    }
4714  }
4715
4716  let tempLower = new Temperature(30);
4717  let tempUpper = new Temperature(40);
4718  let range = new util.Scope(tempLower, tempUpper);
4719  let tempLess = new Temperature(20);
4720  let tempMore = new Temperature(45);
4721  let rangeSec = new util.Scope(tempLess, tempMore);
4722  let result = range.contains(rangeSec);
4723  ```
4724
4725### clamp<sup>(deprecated)</sup>
4726
4727
4728clamp(value: ScopeType): ScopeType
4729
4730将给定值限定到当前范围内。
4731
4732> **说明:**
4733>
4734> 从API version 8开始支持,从API version 9开始废弃,建议使用[ScopeHelper.clamp<sup>9+</sup>](#clamp9)替代。
4735
4736**系统能力:** SystemCapability.Utils.Lang
4737
4738**参数:**
4739
4740| 参数名 | 类型 | 必填 | 说明 |
4741| -------- | -------- | -------- | -------- |
4742| value | [ScopeType](#scopetype8) | 是 | 传入的给定值。 |
4743
4744**返回值:**
4745
4746| 类型 | 说明 |
4747| -------- | -------- |
4748| [ScopeType](#scopetype8) | 如果传入的value小于下限,则返回lowerObj;如果大于上限值则返回upperObj;如果在当前范围内,则返回value。 |
4749
4750**示例:**
4751
4752  ```ts
4753  class Temperature{
4754    private readonly _temp: number;
4755    constructor(value : number) {
4756      this._temp = value;
4757    }
4758    compareTo(value : Temperature ) {
4759      return this._temp >= value.getTemp();
4760    }
4761    getTemp() {
4762      return this._temp;
4763    }
4764    toString() : string {
4765      return this._temp.toString();
4766    }
4767  }
4768
4769  let tempLower = new Temperature(30);
4770  let tempUpper = new Temperature(40);
4771  let tempMiDF = new Temperature(35);
4772  let range = new util.Scope(tempLower, tempUpper);
4773  let result = range.clamp(tempMiDF);
4774  ```
4775
4776
4777## Base64<sup>(deprecated)</sup>
4778
4779> **说明:**
4780>
4781> 从API version 8开始支持,从API version 9开始废弃,建议使用[Base64Helper<sup>9+</sup>](#base64helper9)替代。
4782
4783### constructor<sup>(deprecated)</sup>
4784
4785constructor()
4786
4787Base64的构造函数。
4788
4789> **说明:**
4790>
4791> 从API version 8开始支持,从API version 9开始废弃,建议使用[Base64Helper.constructor<sup>9+</sup>](#constructor9-5)替代。
4792
4793**系统能力:** SystemCapability.Utils.Lang
4794
4795**示例:**
4796
4797  ```ts
4798  let base64 = new  util.Base64();
4799  ```
4800
4801### encodeSync<sup>(deprecated)</sup>
4802
4803encodeSync(src: Uint8Array): Uint8Array
4804
4805通过输入参数编码后输出对应文本。
4806
4807> **说明:**
4808>
4809> 从API version 8开始支持,从API version 9开始废弃,建议使用[Base64Helper.encodeSync<sup>9+</sup>](#encodesync9)替代。
4810
4811**系统能力:** SystemCapability.Utils.Lang
4812
4813**参数:**
4814
4815| 参数名 | 类型 | 必填 | 说明 |
4816| -------- | -------- | -------- | -------- |
4817| src | Uint8Array | 是 | 编码输入Uint8数组。 |
4818
4819**返回值:**
4820
4821| 类型 | 说明 |
4822| -------- | -------- |
4823| Uint8Array | 返回编码后新分配的Uint8数组。 |
4824
4825**示例:**
4826
4827  ```ts
4828  let that = new util.Base64();
4829  let array = new Uint8Array([115,49,51]);
4830  let result = that.encodeSync(array);
4831  ```
4832
4833### encodeToStringSync<sup>(deprecated)</sup>
4834
4835encodeToStringSync(src: Uint8Array): string
4836
4837通过输入参数编码后输出对应文本。
4838
4839> **说明:**
4840>
4841> 从API version 8开始支持,从API version 9开始废弃,建议使用[Base64Helper.encodeToStringSync<sup>9+</sup>](#encodetostringsync9)替代。
4842
4843**系统能力:** SystemCapability.Utils.Lang
4844
4845**参数:**
4846
4847| 参数名 | 类型 | 必填 | 说明 |
4848| -------- | -------- | -------- | -------- |
4849| src | Uint8Array | 是 | 编码输入Uint8数组。 |
4850
4851**返回值:**
4852
4853| 类型 | 说明 |
4854| -------- | -------- |
4855| string | 返回编码后的字符串。 |
4856
4857**示例:**
4858
4859  ```ts
4860  let that = new util.Base64();
4861  let array = new Uint8Array([115,49,51]);
4862  let result = that.encodeToStringSync(array);
4863  ```
4864
4865### decodeSync<sup>(deprecated)</sup>
4866
4867decodeSync(src: Uint8Array | string): Uint8Array
4868
4869通过输入参数解码后输出对应文本。
4870
4871> **说明:**
4872>
4873> 从API version 8开始支持,从API version 9开始废弃,建议使用[Base64Helper.decodeSync<sup>9+</sup>](#decodesync9)替代。
4874
4875**系统能力:** SystemCapability.Utils.Lang
4876
4877**参数:**
4878
4879| 参数名 | 类型 | 必填 | 说明 |
4880| -------- | -------- | -------- | -------- |
4881| src | Uint8Array&nbsp;\|&nbsp;string | 是 | 解码输入Uint8数组或者字符串。 |
4882
4883**返回值:**
4884
4885| 类型 | 说明 |
4886| -------- | -------- |
4887| Uint8Array | 返回解码后新分配的Uint8数组。 |
4888
4889**示例:**
4890
4891  ```ts
4892  let that = new util.Base64();
4893  let buff = 'czEz';
4894  let result = that.decodeSync(buff);
4895  ```
4896
4897### encode<sup>(deprecated)</sup>
4898
4899encode(src: Uint8Array): Promise&lt;Uint8Array&gt;
4900
4901通过输入参数异步编码后输出对应文本。
4902
4903> **说明:**
4904>
4905> 从API version 8开始支持,从API version 9开始废弃,建议使用[Base64Helper.encode<sup>9+</sup>](#encode9)替代。
4906
4907**系统能力:** SystemCapability.Utils.Lang
4908
4909**参数:**
4910
4911| 参数名 | 类型 | 必填 | 说明 |
4912| -------- | -------- | -------- | -------- |
4913| src | Uint8Array | 是 | 异步编码输入Uint8数组。 |
4914
4915**返回值:**
4916
4917| 类型 | 说明 |
4918| -------- | -------- |
4919| Promise&lt;Uint8Array&gt; | 返回异步编码后新分配的Uint8数组。 |
4920
4921**示例:**
4922
4923  ```ts
4924  let that = new util.Base64();
4925  let array = new Uint8Array([115,49,51]);
4926  let rarray = new Uint8Array([99,122,69,122]);
4927  that.encode(array).then(val=>{
4928      for (let i = 0; i < rarray.length; i++) {
4929          console.log(val[i].toString())
4930      }
4931  })
4932  ```
4933
4934### encodeToString<sup>(deprecated)</sup>
4935
4936encodeToString(src: Uint8Array): Promise&lt;string&gt;
4937
4938通过输入参数异步编码后输出对应文本。
4939
4940> **说明:**
4941>
4942> 从API version 8开始支持,从API version 9开始废弃,建议使用[Base64Helper.encodeToString<sup>9+</sup>](#encodetostring9)替代。
4943
4944**系统能力:** SystemCapability.Utils.Lang
4945
4946**参数:**
4947
4948| 参数名 | 类型 | 必填 | 说明 |
4949| -------- | -------- | -------- | -------- |
4950| src | Uint8Array | 是 | 异步编码输入Uint8数组。 |
4951
4952**返回值:**
4953
4954| 类型 | 说明 |
4955| -------- | -------- |
4956| Promise&lt;string&gt; | 返回异步编码后的字符串。 |
4957
4958**示例:**
4959
4960  ```ts
4961  let that = new util.Base64();
4962  let array = new Uint8Array([115,49,51]);
4963  that.encodeToString(array).then(val=>{
4964      console.log(val)
4965  })
4966  ```
4967
4968### decode<sup>(deprecated)</sup>
4969
4970
4971decode(src: Uint8Array | string): Promise&lt;Uint8Array&gt;
4972
4973通过输入参数异步解码后输出对应文本。
4974
4975> **说明:**
4976>
4977> 从API version 8开始支持,从API version 9开始废弃,建议使用[Base64Helper.decode<sup>9+</sup>](#decode9)替代。
4978
4979**系统能力:** SystemCapability.Utils.Lang
4980
4981**参数:**
4982
4983| 参数名 | 类型 | 必填 | 说明 |
4984| -------- | -------- | -------- | -------- |
4985| src | Uint8Array&nbsp;\|&nbsp;string | 是 | 异步解码输入Uint8数组或者字符串。 |
4986
4987**返回值:**
4988
4989| 类型 | 说明 |
4990| -------- | -------- |
4991| Promise&lt;Uint8Array&gt; | 返回异步解码后新分配的Uint8数组。 |
4992
4993**示例:**
4994
4995  ```ts
4996  let that = new util.Base64();
4997  let array = new Uint8Array([99,122,69,122]);
4998  let rarray = new Uint8Array([115,49,51]);
4999  that.decode(array).then(val=>{
5000      for (let i = 0; i < rarray.length; i++) {
5001          console.log(val[i].toString())
5002      }
5003  })
5004  ```
5005