Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
961e0af1
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
961e0af1
编写于
11月 09, 2022
作者:
O
openharmony_ci
提交者:
Gitee
11月 09, 2022
浏览文件
操作
浏览文件
下载
差异文件
!10952 Description of adding new interfaces
Merge pull request !10952 from jiangkai43/master
上级
f23ecf5f
43c30c26
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
1765 addition
and
281 deletion
+1765
-281
zh-cn/application-dev/reference/apis/js-apis-convertxml.md
zh-cn/application-dev/reference/apis/js-apis-convertxml.md
+46
-2
zh-cn/application-dev/reference/apis/js-apis-util.md
zh-cn/application-dev/reference/apis/js-apis-util.md
+1719
-279
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-convertxml.md
浏览文件 @
961e0af1
...
@@ -14,8 +14,53 @@ import convertxml from '@ohos.convertxml';
...
@@ -14,8 +14,53 @@ import convertxml from '@ohos.convertxml';
## ConvertXML
## ConvertXML
### convertToJSObject<sup>9+</sup>
### convert
convertToJSObject(xml: string, options?: ConvertOptions) : Object
转换xml文本为JavaScript对象。
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------- | --------------------------------- | ---- | --------------- |
| xml | string | 是 | 传入的xml文本。 |
| options |
[
ConvertOptions
](
#convertoptions
)
| 否 | 转换选项。 |
**返回值:**
| 类型 | 说明 |
| ------ | ---------------------------- |
| Object | 处理后返回的JavaScript对象。 |
**示例:**
```
js
let
xml
=
'
<?xml version="1.0" encoding="utf-8"?>
'
+
'
<note importance="high" logged="true">
'
+
'
<title>Happy</title>
'
+
'
<todo>Work</todo>
'
+
'
<todo>Play</todo>
'
+
'
</note>
'
;
let
conv
=
new
convertxml
.
convertToJSObject
();
let
options
=
{
trim
:
false
,
declarationKey
:
"
_declaration
"
,
instructionKey
:
"
_instruction
"
,
attributesKey
:
"
_attributes
"
,
textKey
:
"
_text
"
,
cdataKey
:
"
_cdata
"
,
doctypeKey
:
"
_doctype
"
,
commentKey
:
"
_comment
"
,
parentKey
:
"
_parent
"
,
typeKey
:
"
_type
"
,
nameKey
:
"
_name
"
,
elementsKey
:
"
_elements
"
}
let
result
=
JSON
.
stringify
(
conv
.
convert
(
xml
,
options
));
console
.
log
(
result
);
// 输出(宽泛型)
// {"_declaration":{"_attributes":{"version":"1.0","encoding":"utf-8"}},"_elements":[{"_type":"element","_name":"note","_attributes":{"importance":"high","logged":"true"},"_elements":[{"_type":"element","_name":"title","_elements":[{"_type":"text","_text":"Happy"}]},{"_type":"element","_name":"todo","_elements":[{"_type":"text","_text":"Work"}]},{"_type":"element","_name":"todo","_elements":[{"_type":"text","_text":"Play"}]}]}]}
```
### convert<sup>(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[convertToJSObject9+](#converttojsobject9)替代。
convert(xml: string, options?: ConvertOptions) : Object
convert(xml: string, options?: ConvertOptions) : Object
...
@@ -23,7 +68,6 @@ convert(xml: string, options?: ConvertOptions) : Object
...
@@ -23,7 +68,6 @@ convert(xml: string, options?: ConvertOptions) : Object
**系统能力:**
SystemCapability.Utils.Lang
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
...
...
zh-cn/application-dev/reference/apis/js-apis-util.md
浏览文件 @
961e0af1
...
@@ -14,7 +14,38 @@
...
@@ -14,7 +14,38 @@
import util from '@ohos.util';
import util from '@ohos.util';
```
```
## util.printf
## util.format<sup>9+</sup>
format(format: string, ...args: Object[]): string
通过式样化字符串对输入的内容按特定格式输出。
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------- | -------- | ---- | -------------- |
| format | string | 是 | 式样化字符串。 |
| ...args | Object[] | 否 | 待式样化数据。 |
**返回值:**
| 类型 | 说明 |
| ------ | ---------------------------- |
| string | 按特定格式式样化后的字符串。 |
**示例:**
```
js
let
res
=
util
.
format
(
"
%s
"
,
"
hello world!
"
);
console
.
log
(
res
);
```
## util.printf<sup>(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[util.format9+](#utilformat9)替代。
printf(format: string, ...args: Object[]): string
printf(format: string, ...args: Object[]): string
...
@@ -41,8 +72,38 @@ printf(format: string, ...args: Object[]): string
...
@@ -41,8 +72,38 @@ printf(format: string, ...args: Object[]): string
console
.
log
(
res
);
console
.
log
(
res
);
```
```
## util.errnoToString<sup>9+</sup>
errnoToString(errno: number): string
获取系统错误码对应的详细信息。
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | -------------------------- |
| errno | number | 是 | 系统发生错误产生的错误码。 |
**返回值:**
| 类型 | 说明 |
| ------ | ---------------------- |
| string | 错误码对应的详细信息。 |
**示例:**
```
js
let
errnum
=
10
;
// 10 : a system error number
let
result
=
util
.
errnoToString
(
errnum
);
console
.
log
(
"
result =
"
+
result
);
```
## util.getErrorString<sup>(deprecated)</sup>
## util.getErrorString
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[util.errnoToString9+](#utilerrnotostring9)替代。
getErrorString(errno: number): string
getErrorString(errno: number): string
...
@@ -69,7 +130,6 @@ getErrorString(errno: number): string
...
@@ -69,7 +130,6 @@ getErrorString(errno: number): string
console
.
log
(
"
result =
"
+
result
);
console
.
log
(
"
result =
"
+
result
);
```
```
## util.callbackWrapper
## util.callbackWrapper
callbackWrapper(original: Function): (err: Object, value: Object )=
>
void
callbackWrapper(original: Function): (err: Object, value: Object )=
>
void
...
@@ -103,30 +163,6 @@ callbackWrapper(original: Function): (err: Object, value: Object )=>void
...
@@ -103,30 +163,6 @@ callbackWrapper(original: Function): (err: Object, value: Object )=>void
},
err
)
},
err
)
```
```
## util.promiseWrapper<sup>(deprecated)</sup>
promiseWrapper(original: (err: Object, value: Object) =
>
void): Object
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[util.promisify9+](#utilpromisify9)替代。
对异步函数处理并返回一个promise的版本。
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| original | Function | 是 | 异步函数。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Function | 采用遵循常见的错误优先的回调风格的函数(也就是将
(err,
value)
=
>
...
回调作为最后一个参数),并返回一个返回
promise
的版本。 |
## util.promisify<sup>9+</sup>
## util.promisify<sup>9+</sup>
promisify(original: (err: Object, value: Object) =
>
void): Function
promisify(original: (err: Object, value: Object) =
>
void): Function
...
@@ -162,6 +198,29 @@ promisify(original: (err: Object, value: Object) => void): Function
...
@@ -162,6 +198,29 @@ promisify(original: (err: Object, value: Object) => void): Function
})
})
```
```
## util.promiseWrapper<sup>(deprecated)</sup>
promiseWrapper(original: (err: Object, value: Object) =
>
void): Object
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[util.promisify9+](#utilpromisify9)替代。
对异步函数处理并返回一个promise的版本。
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| original | Function | 是 | 异步函数。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Function | 采用遵循常见的错误优先的回调风格的函数(也就是将
(err,
value)
=
>
...
回调作为最后一个参数),并返回一个返回
promise
的版本。 |
## util.randomUUID<sup>9+</sup>
## util.randomUUID<sup>9+</sup>
randomUUID(entropyCache?: boolean): string
randomUUID(entropyCache?: boolean): string
...
@@ -244,7 +303,7 @@ parseUUID(uuid: string): Uint8Array
...
@@ -244,7 +303,7 @@ parseUUID(uuid: string): Uint8Array
console
.
log
(
JSON
.
stringify
(
uuid
));
console
.
log
(
JSON
.
stringify
(
uuid
));
// 输出:
// 输出:
// 132,189,247,150,102,204,70,85,155,137,214,33,141,16,15,156
// 132,189,247,150,102,204,70,85,155,137,214,33,141,16,15,156
```
```
## TextDecoder
## TextDecoder
...
@@ -258,8 +317,45 @@ parseUUID(uuid: string): Uint8Array
...
@@ -258,8 +317,45 @@ parseUUID(uuid: string): Uint8Array
| fatal | boolean | 是 | 否 | 是否显示致命错误。 |
| fatal | boolean | 是 | 否 | 是否显示致命错误。 |
| ignoreBOM | boolean | 是 | 否 | 是否忽略BOM(byte
order
marker)标记,默认值为false
,表示解码结果包含BOM标记。 |
| ignoreBOM | boolean | 是 | 否 | 是否忽略BOM(byte
order
marker)标记,默认值为false
,表示解码结果包含BOM标记。 |
### constructor<sup>9+</sup>
### constructor
constructor()
TextDecoder的构造函数。
**系统能力:**
SystemCapability.Utils.Lang
### create<sup>9+</sup>
create(encoding?: string,options?: { fatal?: boolean; ignoreBOM?: boolean },): TextDecoder;
替代有参构造功能。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ------------------------------------------------ |
| encoding | string | 否 | 编码格式。 |
| options | Object | 否 | 编码相关选项参数,存在两个属性fatal和ignoreBOM。 |
**表1.1**
options
| 名称 | 参数类型 | 必填 | 说明 |
| --------- | -------- | ---- | ------------------ |
| fatal | boolean | 否 | 是否显示致命错误。 |
| ignoreBOM | boolean | 否 | 是否忽略BOM标记。 |
**示例:**
```
js
let
textDecoder
=
new
util
.
TextDecoder
()
textDecoder
.
create
(
'
utf-8
'
,
{
ignoreBOM
:
true
});
```
### constructor<sup>(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[constructor9+](#constructor9)替代。
constructor(encoding?: string, options?: { fatal?: boolean; ignoreBOM?: boolean },)
constructor(encoding?: string, options?: { fatal?: boolean; ignoreBOM?: boolean },)
...
@@ -286,7 +382,6 @@ TextDecoder的构造函数。
...
@@ -286,7 +382,6 @@ TextDecoder的构造函数。
let
textDecoder
=
new
util
.
TextDecoder
(
"
utf-8
"
,{
ignoreBOM
:
true
});
let
textDecoder
=
new
util
.
TextDecoder
(
"
utf-8
"
,{
ignoreBOM
:
true
});
```
```
### decode
### decode
decode(input: Uint8Array, options?: { stream?: false }): string
decode(input: Uint8Array, options?: { stream?: false }): string
...
@@ -397,8 +492,39 @@ TextEncoder的构造函数。
...
@@ -397,8 +492,39 @@ TextEncoder的构造函数。
let
textEncoder
=
new
util
.
TextEncoder
();
let
textEncoder
=
new
util
.
TextEncoder
();
```
```
### encodeInto<sup>9+</sup>
encodeInto(input?: string): Uint8Array
通过输入参数编码后输出对应文本。
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ------------------ |
| input | string | 是 | 需要编码的字符串。 |
**返回值:**
| 类型 | 说明 |
| ---------- | ------------------ |
| Uint8Array | 返回编码后的文本。 |
**示例:**
```
js
let
textEncoder
=
new
util
.
TextEncoder
();
let
buffer
=
new
ArrayBuffer
(
20
);
let
result
=
new
Uint8Array
(
buffer
);
result
=
textEncoder
.
encodeInto
(
"
\
uD800¥¥
"
);
```
### encode<sup>(deprecated)</sup>
### encode
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[encodeInto9+](#encodeinto9)替代。
encode(input?: string): Uint8Array
encode(input?: string): Uint8Array
...
@@ -426,8 +552,41 @@ encode(input?: string): Uint8Array
...
@@ -426,8 +552,41 @@ encode(input?: string): Uint8Array
result
=
textEncoder
.
encode
(
"
\
uD800¥¥
"
);
result
=
textEncoder
.
encode
(
"
\
uD800¥¥
"
);
```
```
### encodeIntoUint8Array<sup>9+</sup>
encodeIntoUint8Array(input: string, dest: Uint8Array, ): { read: number; written: number }
放置生成的UTF-8编码文本。
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ---------- | ---- | ------------------------------------------------------- |
| input | string | 是 | 需要编码的字符串。 |
| dest | Uint8Array | 是 | Uint8Array对象实例,用于将生成的UTF-8编码文本放入其中。 |
**返回值:**
| 类型 | 说明 |
| ---------- | ------------------ |
| Uint8Array | 返回编码后的文本。 |
**示例:**
```
js
let
that
=
new
util
.
TextEncoder
()
let
buffer
=
new
ArrayBuffer
(
4
)
let
dest
=
new
Uint8Array
(
buffer
)
let
result
=
new
Object
()
result
=
that
.
encodeInto
(
'
abcd
'
,
dest
)
```
### encodeInto<sup>(deprecated)</sup>
### encodeInto
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[encodeIntoUint8Array9+](#encodeintouint8array9)替代。
encodeInto(input: string, dest: Uint8Array, ): { read: number; written: number }
encodeInto(input: string, dest: Uint8Array, ): { read: number; written: number }
...
@@ -459,8 +618,46 @@ encodeInto(input: string, dest: Uint8Array, ): { read: number; written: number }
...
@@ -459,8 +618,46 @@ encodeInto(input: string, dest: Uint8Array, ): { read: number; written: number }
## RationalNumber<sup>8+</sup>
## RationalNumber<sup>8+</sup>
### constructor<sup>9+</sup>
### constructor<sup>8+</sup>
constructor()
RationalNumber的构造函数。
**系统能力:**
SystemCapability.Utils.Lang
**示例:**
```
js
let
rationalNumber
=
new
util
.
RationalNumber
();
```
### parseRationalNumber<sup>9+</sup>
parseRationalNumber(numerator: number,denominator: number)
替代原有参构造的参数处理。
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----------- | ------ | ---- | ---------------- |
| numerator | number | 是 | 分子,整数类型。 |
| denominator | number | 是 | 分母,整数类型。 |
**示例:**
```
js
let
rationalNumber
=
new
util
.
RationalNumber
();
rationalNumber
.
parseRationalNumber
(
1
,
2
)
```
### constructor<sup>8+(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[constructor9+](#constructor9)替代。
constructor(numerator: number,denominator: number)
constructor(numerator: number,denominator: number)
...
@@ -476,11 +673,11 @@ RationalNumber的构造函数。
...
@@ -476,11 +673,11 @@ RationalNumber的构造函数。
| denominator | number | 是 | 分母,整数类型。 |
| denominator | number | 是 | 分母,整数类型。 |
**示例:**
**示例:**
```
js
```
js
let
rationalNumber
=
new
util
.
RationalNumber
(
1
,
2
);
let
rationalNumber
=
new
util
.
RationalNumber
(
1
,
2
);
```
```
### createRationalFromString<sup>8+</sup>
### createRationalFromString<sup>8+</sup>
static createRationalFromString(rationalString: string): RationalNumber
static createRationalFromString(rationalString: string): RationalNumber
...
@@ -507,8 +704,38 @@ static createRationalFromString(rationalString: string): RationalNumber
...
@@ -507,8 +704,38 @@ static createRationalFromString(rationalString: string): RationalNumber
let
rational
=
util
.
RationalNumber
.
createRationalFromString
(
"
3/4
"
);
let
rational
=
util
.
RationalNumber
.
createRationalFromString
(
"
3/4
"
);
```
```
### compare<sup>9+</sup>
compare(another: RationalNumber): number
将当前的RationalNumber对象与给定的对象进行比较。
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------- | -------------- | ---- | ------------------ |
| another | RationalNumber | 是 | 其他的有理数对象。 |
**返回值:**
| 类型 | 说明 |
| ------ | ------------------------------------------------------------ |
| number | 如果两个对象相等,则返回0;如果给定对象小于当前对象,则返回1;如果给定对象大于当前对象,则返回-1。 |
**示例:**
```
js
let
rationalNumber
=
new
util
.
RationalNumber
(
1
,
2
);
let
rational
=
util
.
RationalNumber
.
createRationalFromString
(
"
3/4
"
);
let
result
=
rationalNumber
.
compare
(
rational
);
```
### compareTo<sup>8+</sup><sup>(deprecated)</sup>
### compareTo<sup>8+</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[compare9+](#compare9)替代。
compareTo(another: RationalNumber): number
compareTo(another: RationalNumber): number
...
@@ -535,7 +762,6 @@ compareTo(another: RationalNumber): number
...
@@ -535,7 +762,6 @@ compareTo(another: RationalNumber): number
let
result
=
rationalNumber
.
compareTo
(
rational
);
let
result
=
rationalNumber
.
compareTo
(
rational
);
```
```
### valueOf<sup>8+</sup>
### valueOf<sup>8+</sup>
valueOf(): number
valueOf(): number
...
@@ -556,7 +782,6 @@ valueOf(): number
...
@@ -556,7 +782,6 @@ valueOf(): number
let
result
=
rationalNumber
.
valueOf
();
let
result
=
rationalNumber
.
valueOf
();
```
```
### equals<sup>8+</sup>
### equals<sup>8+</sup>
equals(obj: Object): boolean
equals(obj: Object): boolean
...
@@ -584,8 +809,37 @@ equals(obj: Object): boolean
...
@@ -584,8 +809,37 @@ equals(obj: Object): boolean
let
result
=
rationalNumber
.
equals
(
rational
);
let
result
=
rationalNumber
.
equals
(
rational
);
```
```
### getCommonFactor<sup>9+</sup>
getCommonFactor(number1: number,number2: number): number
获取两个指定整数的最大公约数。
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | ---------- |
| number1 | number | 是 | 整数类型。 |
| number2 | number | 是 | 整数类型。 |
**返回值:**
| 类型 | 说明 |
| ------ | ------------------------------ |
| number | 返回两个给定数字的最大公约数。 |
**示例:**
```
js
let
rationalNumber
=
new
util
.
RationalNumber
(
1
,
2
);
let
result
=
util
.
RationalNumber
.
getCommonFactor
(
4
,
6
);
```
### getCommonDivisor<sup>8+</sup>
### getCommonDivisor<sup>8+(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[getCommonFactor9+](#getcommonfactor9)替代。
static getCommonDivisor(number1: number,number2: number): number
static getCommonDivisor(number1: number,number2: number): number
...
@@ -612,7 +866,6 @@ static getCommonDivisor(number1: number,number2: number): number
...
@@ -612,7 +866,6 @@ static getCommonDivisor(number1: number,number2: number): number
let
result
=
util
.
RationalNumber
.
getCommonDivisor
(
4
,
6
);
let
result
=
util
.
RationalNumber
.
getCommonDivisor
(
4
,
6
);
```
```
### getNumerator<sup>8+</sup>
### getNumerator<sup>8+</sup>
getNumerator(): number
getNumerator(): number
...
@@ -633,7 +886,6 @@ getNumerator(): number
...
@@ -633,7 +886,6 @@ getNumerator(): number
let
result
=
rationalNumber
.
getNumerator
();
let
result
=
rationalNumber
.
getNumerator
();
```
```
### getDenominator<sup>8+</sup>
### getDenominator<sup>8+</sup>
getDenominator(): number
getDenominator(): number
...
@@ -654,7 +906,6 @@ getDenominator(): number
...
@@ -654,7 +906,6 @@ getDenominator(): number
let
result
=
rationalNumber
.
getDenominator
();
let
result
=
rationalNumber
.
getDenominator
();
```
```
### isZero<sup>8+</sup>
### isZero<sup>8+</sup>
isZero():boolean
isZero():boolean
...
@@ -675,7 +926,6 @@ isZero():boolean
...
@@ -675,7 +926,6 @@ isZero():boolean
let
result
=
rationalNumber
.
isZero
();
let
result
=
rationalNumber
.
isZero
();
```
```
### isNaN<sup>8+</sup>
### isNaN<sup>8+</sup>
isNaN(): boolean
isNaN(): boolean
...
@@ -696,7 +946,6 @@ isNaN(): boolean
...
@@ -696,7 +946,6 @@ isNaN(): boolean
let
result
=
rationalNumber
.
isNaN
();
let
result
=
rationalNumber
.
isNaN
();
```
```
### isFinite<sup>8+</sup>
### isFinite<sup>8+</sup>
isFinite():boolean
isFinite():boolean
...
@@ -717,7 +966,6 @@ isFinite():boolean
...
@@ -717,7 +966,6 @@ isFinite():boolean
let
result
=
rationalNumber
.
isFinite
();
let
result
=
rationalNumber
.
isFinite
();
```
```
### toString<sup>8+</sup>
### toString<sup>8+</sup>
toString(): string
toString(): string
...
@@ -738,26 +986,27 @@ toString(): string
...
@@ -738,26 +986,27 @@ toString(): string
let
result
=
rationalNumber
.
toString
();
let
result
=
rationalNumber
.
toString
();
```
```
## LruBuffer<sup>8+</sup>
## LRUCache<sup>9+</sup>
### 属性
### 属性
**系统能力:**
以下各项对应的系统能力均为SystemCapability.Utils.Lang。
**系统能力:**
以下各项对应的系统能力均为SystemCapability.Utils.Lang。
| 名称
| 类型 | 可读 | 可写 | 说明
|
| 名称
| 类型 | 可读 | 可写 | 说明
|
| ------
-- | -------- | -------- | -------- |
-------- |
| ------
| ------ | ---- | ---- | --------------
-------- |
| length | number | 是
| 否
| 当前缓冲区中值的总数。 |
| length | number | 是
| 否
| 当前缓冲区中值的总数。 |
**示例:**
**示例:**
```
js
```
js
let
pro
=
new
util
.
LruBuffer
();
let
pro
=
new
util
.
LRUCache
();
pro
.
put
(
2
,
10
);
pro
.
put
(
2
,
10
);
pro
.
put
(
1
,
8
);
pro
.
put
(
1
,
8
);
let
result
=
pro
.
length
;
let
result
=
pro
.
length
;
```
```
### constructor<sup>9+</sup>
### constructor<sup>8+</sup>
constructor(capacity?: number)
constructor(capacity?: number)
...
@@ -767,17 +1016,18 @@ constructor(capacity?: number)
...
@@ -767,17 +1016,18 @@ constructor(capacity?: number)
**参数:**
**参数:**
| 参数名
| 类型 | 必填 | 说明
|
| 参数名
| 类型 | 必填 | 说明
|
| -------- | ------
-- | -------- |
-------- |
| -------- | ------
| ---- | --------------------
-------- |
| capacity | number | 否 | 指示要为缓冲区自定义的容量。 |
| capacity | number | 否
| 指示要为缓冲区自定义的容量。 |
**示例:**
**示例:**
```
js
```
js
let
lrubuffer
=
new
util
.
LruBuffer
();
let
lrubuffer
=
new
util
.
LRUCache
();
```
```
### updateCapacity<sup>
8
+</sup>
### updateCapacity<sup>
9
+</sup>
updateCapacity(newCapacity: number): void
updateCapacity(newCapacity: number): void
...
@@ -787,18 +1037,19 @@ updateCapacity(newCapacity: number): void
...
@@ -787,18 +1037,19 @@ updateCapacity(newCapacity: number): void
**参数:**
**参数:**
| 参数名
| 类型 | 必填 | 说明
|
| 参数名
| 类型 | 必填 | 说明
|
| --------
| -------- | -------- |
-------- |
| --------
--- | ------ | ---- | --------------------
-------- |
| newCapacity | number | 是 | 指示要为缓冲区自定义的容量。 |
| newCapacity | number | 是
| 指示要为缓冲区自定义的容量。 |
**示例:**
**示例:**
```
js
```
js
let
pro
=
new
util
.
LruBuffer
();
let
pro
=
new
util
.
LRUCache
();
let
result
=
pro
.
updateCapacity
(
100
);
let
result
=
pro
.
updateCapacity
(
100
);
```
```
### toString<sup>
8
+</sup>
### toString<sup>
9
+</sup>
toString(): string
toString(): string
...
@@ -808,21 +1059,22 @@ toString(): string
...
@@ -808,21 +1059,22 @@ toString(): string
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| ------
-- |
-------- |
| ------
| ------------------
-------- |
| string | 返回对象的字符串表示形式。 |
| string | 返回对象的字符串表示形式。 |
**示例:**
**示例:**
```
js
```
js
let
pro
=
new
util
.
LruBuffer
();
let
pro
=
new
util
.
LRUCache
();
pro
.
put
(
2
,
10
);
pro
.
put
(
2
,
10
);
pro
.
get
(
2
);
pro
.
get
(
2
);
pro
.
remove
(
20
);
pro
.
remove
(
20
);
let
result
=
pro
.
toString
();
let
result
=
pro
.
toString
();
```
```
### getCapacity<sup>
8
+</sup>
### getCapacity<sup>
9
+</sup>
getCapacity(): number
getCapacity(): number
...
@@ -832,18 +1084,19 @@ getCapacity(): number
...
@@ -832,18 +1084,19 @@ getCapacity(): number
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| ------
-- |
-------- |
| ------
| --------------
-------- |
| number | 返回当前缓冲区的容量。 |
| number | 返回当前缓冲区的容量。 |
**示例:**
**示例:**
```
js
```
js
let
pro
=
new
util
.
LruBuffer
();
let
pro
=
new
util
.
LRUCache
();
let
result
=
pro
.
getCapacity
();
let
result
=
pro
.
getCapacity
();
```
```
### clear<sup>
8
+</sup>
### clear<sup>
9
+</sup>
clear(): void
clear(): void
...
@@ -852,15 +1105,16 @@ clear(): void
...
@@ -852,15 +1105,16 @@ clear(): void
**系统能力:**
SystemCapability.Utils.Lang
**系统能力:**
SystemCapability.Utils.Lang
**示例:**
**示例:**
```
js
```
js
let
pro
=
new
util
.
LruBuffer
();
let
pro
=
new
util
.
LRUCache
();
pro
.
put
(
2
,
10
);
pro
.
put
(
2
,
10
);
let
result
=
pro
.
length
;
let
result
=
pro
.
length
;
pro
.
clear
();
pro
.
clear
();
```
```
### getCreateCount<sup>
8
+</sup>
### getCreateCount<sup>
9
+</sup>
getCreateCount(): number
getCreateCount(): number
...
@@ -870,19 +1124,20 @@ getCreateCount(): number
...
@@ -870,19 +1124,20 @@ getCreateCount(): number
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| ------
-- |
-------- |
| ------
| -------------------------
-------- |
| number | 返回createDefault()返回值的次数。 |
| number | 返回createDefault()返回值的次数。 |
**示例:**
**示例:**
```
js
```
js
let
pro
=
new
util
.
LruBuffer
();
let
pro
=
new
util
.
LRUCache
();
pro
.
put
(
1
,
8
);
pro
.
put
(
1
,
8
);
let
result
=
pro
.
getCreateCount
();
let
result
=
pro
.
getCreateCount
();
```
```
### getMissCount<sup>
8
+</sup>
### getMissCount<sup>
9
+</sup>
getMissCount(): number
getMissCount(): number
...
@@ -892,20 +1147,21 @@ getMissCount(): number
...
@@ -892,20 +1147,21 @@ getMissCount(): number
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| ------
-- |
-------- |
| ------
| ----------------
-------- |
| number | 返回查询值不匹配的次数。 |
| number | 返回查询值不匹配的次数。 |
**示例:**
**示例:**
```
js
```
js
let
pro
=
new
util
.
LruBuffer
();
let
pro
=
new
util
.
LRUCache
();
pro
.
put
(
2
,
10
);
pro
.
put
(
2
,
10
);
pro
.
get
(
2
);
pro
.
get
(
2
);
let
result
=
pro
.
getMissCount
();
let
result
=
pro
.
getMissCount
();
```
```
### getRemovalCount<sup>
8
+</sup>
### getRemovalCount<sup>
9
+</sup>
getRemovalCount(): number
getRemovalCount(): number
...
@@ -915,21 +1171,22 @@ getRemovalCount(): number
...
@@ -915,21 +1171,22 @@ getRemovalCount(): number
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| ------
-- |
-------- |
| ------
| ------------------
-------- |
| number | 返回从缓冲区中驱逐的次数。 |
| number | 返回从缓冲区中驱逐的次数。 |
**示例:**
**示例:**
```
js
```
js
let
pro
=
new
util
.
LruBuffer
();
let
pro
=
new
util
.
LRUCache
();
pro
.
put
(
2
,
10
);
pro
.
put
(
2
,
10
);
pro
.
updateCapacity
(
2
);
pro
.
updateCapacity
(
2
);
pro
.
put
(
50
,
22
);
pro
.
put
(
50
,
22
);
let
result
=
pro
.
getRemovalCount
();
let
result
=
pro
.
getRemovalCount
();
```
```
### getMatchCount<sup>
8
+</sup>
### getMatchCount<sup>
9
+</sup>
getMatchCount(): number
getMatchCount(): number
...
@@ -939,20 +1196,21 @@ getMatchCount(): number
...
@@ -939,20 +1196,21 @@ getMatchCount(): number
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| ------
-- |
-------- |
| ------
| ------------------
-------- |
| number | 返回查询值匹配成功的次数。 |
| number | 返回查询值匹配成功的次数。 |
**示例:**
**示例:**
```
js
```
js
let
pro
=
new
util
.
LruBuffer
();
let
pro
=
new
util
.
LRUCache
();
pro
.
put
(
2
,
10
);
pro
.
put
(
2
,
10
);
pro
.
get
(
2
);
pro
.
get
(
2
);
let
result
=
pro
.
getMatchCount
();
let
result
=
pro
.
getMatchCount
();
```
```
### getPutCount<sup>
8
+</sup>
### getPutCount<sup>
9
+</sup>
getPutCount(): number
getPutCount(): number
...
@@ -962,19 +1220,20 @@ getPutCount(): number
...
@@ -962,19 +1220,20 @@ getPutCount(): number
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| ------
-- |
-------- |
| ------
| --------------------
-------- |
| number | 返回将值添加到缓冲区的次数。 |
| number | 返回将值添加到缓冲区的次数。 |
**示例:**
**示例:**
```
js
```
js
let
pro
=
new
util
.
LruBuffer
();
let
pro
=
new
util
.
LRUCache
();
pro
.
put
(
2
,
10
);
pro
.
put
(
2
,
10
);
let
result
=
pro
.
getPutCount
();
let
result
=
pro
.
getPutCount
();
```
```
### isEmpty<sup>
8
+</sup>
### isEmpty<sup>
9
+</sup>
isEmpty(): boolean
isEmpty(): boolean
...
@@ -984,19 +1243,20 @@ isEmpty(): boolean
...
@@ -984,19 +1243,20 @@ isEmpty(): boolean
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| -------
- |
-------- |
| -------
| --------------------------------
-------- |
| boolean | 如果当前缓冲区不包含任何值,则返回true。 |
| boolean | 如果当前缓冲区不包含任何值,则返回true。 |
**示例:**
**示例:**
```
js
```
js
let
pro
=
new
util
.
LruBuffer
();
let
pro
=
new
util
.
LRUCache
();
pro
.
put
(
2
,
10
);
pro
.
put
(
2
,
10
);
let
result
=
pro
.
isEmpty
();
let
result
=
pro
.
isEmpty
();
```
```
### get<sup>
8
+</sup>
### get<sup>
9
+</sup>
get(key: K): V | undefined
get(key: K): V | undefined
...
@@ -1006,25 +1266,26 @@ get(key: K): V | undefined
...
@@ -1006,25 +1266,26 @@ get(key: K): V | undefined
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明
|
| ------
-- | -------- | -------- |
-------- |
| ------
| ---- | ---- | ----
-------- |
| key
| K | 是
| 要查询的键。 |
| key
| K | 是
| 要查询的键。 |
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| --------
|
-------- |
| --------
---------------- | ----------------------------------------------------
-------- |
| V
\|
undefined | 如果指定的键存在于缓冲区中,则返回与键关联的值;否则返回undefined。 |
| V
\|
undefined | 如果指定的键存在于缓冲区中,则返回与键关联的值;否则返回undefined。 |
**示例:**
**示例:**
```
js
```
js
let
pro
=
new
util
.
LruBuffer
();
let
pro
=
new
util
.
LRUCache
();
pro
.
put
(
2
,
10
);
pro
.
put
(
2
,
10
);
let
result
=
pro
.
get
(
2
);
let
result
=
pro
.
get
(
2
);
```
```
### put<sup>
8
+</sup>
### put<sup>
9
+</sup>
put(key: K,value: V): V
put(key: K,value: V): V
...
@@ -1034,24 +1295,25 @@ put(key: K,value: V): V
...
@@ -1034,24 +1295,25 @@ put(key: K,value: V): V
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明
|
| ------
-- | -------- | -------- |
-------- |
| ------
| ---- | ---- | ------------------
-------- |
| key
| K | 是 | 要添加的密钥。
|
| key
| K | 是 | 要添加的密钥。
|
| value
| V | 是
| 指示与要添加的键关联的值。 |
| value
| V | 是
| 指示与要添加的键关联的值。 |
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明
|
| ----
---- |
-------- |
| ----
| ----------------------------------------------------
-------- |
| V | 返回与添加的键关联的值;如果要添加的键已经存在,则返回原始值,如果键或值为空,则抛出此异常。 |
| V
| 返回与添加的键关联的值;如果要添加的键已经存在,则返回原始值,如果键或值为空,则抛出此异常。 |
**示例:**
**示例:**
```
js
```
js
let
pro
=
new
util
.
LruBuffer
();
let
pro
=
new
util
.
LRUCache
();
let
result
=
pro
.
put
(
2
,
10
);
let
result
=
pro
.
put
(
2
,
10
);
```
```
### values<sup>
8
+</sup>
### values<sup>
9
+</sup>
values(): V[]
values(): V[]
...
@@ -1061,21 +1323,22 @@ values(): V[]
...
@@ -1061,21 +1323,22 @@ values(): V[]
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| --------
|
-------- |
| --------
- | ----------------------------------------------------
-------- |
| V
[] | 按从最近访问到最近最少访问的顺序返回当前缓冲区中所有值的列表。 |
| V
[] | 按从最近访问到最近最少访问的顺序返回当前缓冲区中所有值的列表。 |
**示例:**
**示例:**
```
js
```
js
let
pro
=
new
util
.
LruBuffer
();
let
pro
=
new
util
.
LRUCache
();
pro
.
put
(
2
,
10
);
pro
.
put
(
2
,
10
);
pro
.
put
(
2
,
"
anhu
"
);
pro
.
put
(
2
,
"
anhu
"
);
pro
.
put
(
"
afaf
"
,
"
grfb
"
);
pro
.
put
(
"
afaf
"
,
"
grfb
"
);
let
result
=
pro
.
values
();
let
result
=
pro
.
values
();
```
```
### keys<sup>
8
+</sup>
### keys<sup>
9
+</sup>
keys(): K[]
keys(): K[]
...
@@ -1085,19 +1348,20 @@ keys(): K[]
...
@@ -1085,19 +1348,20 @@ keys(): K[]
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| --------
|
-------- |
| --------
- | ----------------------------------------------------
-------- |
| K
[] | 按升序返回当前缓冲区中所有键的列表,从最近访问到最近最少访问。 |
| K
[] | 按升序返回当前缓冲区中所有键的列表,从最近访问到最近最少访问。 |
**示例:**
**示例:**
```
js
```
js
let
pro
=
new
util
.
LruBuffer
();
let
pro
=
new
util
.
LRUCache
();
pro
.
put
(
2
,
10
);
pro
.
put
(
2
,
10
);
let
result
=
pro
.
keys
();
let
result
=
pro
.
keys
();
```
```
### remove<sup>
8
+</sup>
### remove<sup>
9
+</sup>
remove(key: K): V | undefined
remove(key: K): V | undefined
...
@@ -1107,25 +1371,26 @@ remove(key: K): V | undefined
...
@@ -1107,25 +1371,26 @@ remove(key: K): V | undefined
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明
|
| ------
-- | -------- | -------- |
-------- |
| ------
| ---- | ---- | ------
-------- |
| key
| K | 是
| 要删除的密钥。 |
| key
| K | 是
| 要删除的密钥。 |
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| --------
|
-------- |
| --------
---------------- | ----------------------------------------------------
-------- |
| V
\|
undefined | 返回一个包含已删除键值对的Optional对象;如果key不存在,则返回一个空的Optional对象,如果key为null,则抛出异常。 |
| V
\|
undefined | 返回一个包含已删除键值对的Optional对象;如果key不存在,则返回一个空的Optional对象,如果key为null,则抛出异常。 |
**示例:**
**示例:**
```
js
```
js
let
pro
=
new
util
.
LruBuffer
();
let
pro
=
new
util
.
LRUCache
();
pro
.
put
(
2
,
10
);
pro
.
put
(
2
,
10
);
let
result
=
pro
.
remove
(
20
);
let
result
=
pro
.
remove
(
20
);
```
```
### afterRemoval<sup>
8
+</sup>
### afterRemoval<sup>
9
+</sup>
afterRemoval(isEvict: boolean,key: K,value: V,newValue: V): void
afterRemoval(isEvict: boolean,key: K,value: V,newValue: V): void
...
@@ -1135,36 +1400,37 @@ afterRemoval(isEvict: boolean,key: K,value: V,newValue: V): void
...
@@ -1135,36 +1400,37 @@ afterRemoval(isEvict: boolean,key: K,value: V,newValue: V): void
**参数:**
**参数:**
| 参数名
| 类型 | 必填 | 说明
|
| 参数名
| 类型 | 必填 | 说明
|
| -------- | -------
- | -------- |
-------- |
| -------- | -------
| ---- | ----------------------------------------------------
-------- |
| isEvict
| boolean | 否 | 因容量不足而调用该方法时,参数值为true,其他情况为false。
|
| isEvict
| boolean | 否 | 因容量不足而调用该方法时,参数值为true,其他情况为false。
|
| key
| K | 是 | 表示删除的键。
|
| key
| K | 是 | 表示删除的键。
|
| value
| V | 是 | 表示删除的值。
|
| value
| V | 是 | 表示删除的值。
|
| newValue | V
| 否
| 如果已调用put方法并且要添加的键已经存在,则参数值是关联的新值。其他情况下参数值为空。 |
| newValue | V
| 否
| 如果已调用put方法并且要添加的键已经存在,则参数值是关联的新值。其他情况下参数值为空。 |
**示例:**
**示例:**
```
js
```
js
let
arr
=
[];
let
arr
=
[];
class
ChildLruBuffer
<
K
,
V
>
extends
util
.
LruBuffer
<
K
,
V
>
class
ChildLruBuffer
<
K
,
V
>
extends
util
.
LRUCache
<
K
,
V
>
{
{
constructor
()
constructor
()
{
{
super
();
super
();
}
}
afterRemoval
(
isEvict
,
key
,
value
,
newValue
)
afterRemoval
(
isEvict
,
key
,
value
,
newValue
)
{
{
if
(
isEvict
===
false
)
if
(
isEvict
===
false
)
{
{
arr
=
[
key
,
value
,
newValue
];
arr
=
[
key
,
value
,
newValue
];
}
}
}
}
}
}
let
lru
=
new
ChildLruBuffer
();
let
lru
=
new
ChildLruBuffer
();
lru
.
afterRemoval
(
false
,
10
,
30
,
null
);
lru
.
afterRemoval
(
false
,
10
,
30
,
null
);
```
```
### contains<sup>
8
+</sup>
### contains<sup>
9
+</sup>
contains(key: K): boolean
contains(key: K): boolean
...
@@ -1174,136 +1440,1067 @@ contains(key: K): boolean
...
@@ -1174,136 +1440,1067 @@ contains(key: K): boolean
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| ------ | ---- | ---- | ---------------- |
| key | K | 是 | 表示要检查的键。 |
| key | K | 是 | 表示要检查的键。 |
**返回值:**
| 类型 | 说明 |
| ------- | ------------------------------------------ |
| boolean | 如果缓冲区包含指定的键,则返回
true。 |
**示例:**
```
js
let
pro
=
new
util
.
LRUCache
();
pro
.
put
(
2
,
10
);
let
result
=
pro
.
contains
(
20
);
```
### createDefault<sup>9+</sup>
createDefault(key: K): V
如果未计算特定键的值,则执行后续操作,参数表示丢失的键,返回与键关联的值。
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ---- | ---- | -------------- |
| key | K | 是 | 表示丢失的键。 |
**返回值:**
| 类型 | 说明 |
| ---- | ------------------ |
| V | 返回与键关联的值。 |
**示例:**
```
js
let
pro
=
new
util
.
LRUCache
();
let
result
=
pro
.
createDefault
(
50
);
```
### entries<sup>9+</sup>
entries(): IterableIterator
<
[K,V]
>
允许迭代包含在这个对象中的所有键值对。
**系统能力:**
SystemCapability.Utils.Lang
**返回值:**
| 类型 | 说明 |
| ----------- | -------------------- |
| [K,
V] | 返回一个可迭代数组。 |
**示例:**
```
js
let
pro
=
new
util
.
LRUCache
();
pro
.
put
(
2
,
10
);
let
result
=
pro
.
entries
();
```
### [Symbol.iterator]<sup>9+</sup>
[Symbol.iterator]
\(
): IterableIterator
<
[K, V]
>
返回一个键值对形式的二维数组。
**系统能力:**
SystemCapability.Utils.Lang
**返回值:**
| 类型 | 说明 |
| ----------- | ------------------------------ |
| [K,
V] | 返回一个键值对形式的二维数组。 |
**示例:**
```
js
let
pro
=
new
util
.
LRUCache
();
pro
.
put
(
2
,
10
);
let
result
=
pro
[
Symbol
.
iterator
]();
```
## LruBuffer<sup>8+(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[LRUCache9+](#lrucache9)替代。
### 属性
**系统能力:**
以下各项对应的系统能力均为SystemCapability.Utils.Lang。
| 名称 | 类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| length | number | 是 | 否 | 当前缓冲区中值的总数。 |
**示例:**
```
js
let
pro
=
new
util
.
LruBuffer
();
pro
.
put
(
2
,
10
);
pro
.
put
(
1
,
8
);
let
result
=
pro
.
length
;
```
### constructor<sup>8+(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[constructor9+](#constructor9)替代。
constructor(capacity?: number)
默认构造函数用于创建一个新的LruBuffer实例,默认容量为64。
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| capacity | number | 否 | 指示要为缓冲区自定义的容量。 |
**示例:**
```
js
let
lrubuffer
=
new
util
.
LruBuffer
();
```
### updateCapacity<sup>8+(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[updateCapacity9+](#updatecapacity9)替代。
updateCapacity(newCapacity: number): void
将缓冲区容量更新为指定容量,如果newCapacity小于或等于0,则抛出异常。
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| newCapacity | number | 是 | 指示要为缓冲区自定义的容量。 |
**示例:**
```
js
let
pro
=
new
util
.
LruBuffer
();
let
result
=
pro
.
updateCapacity
(
100
);
```
### toString<sup>8+(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[toString9+](#tostring9)替代。
toString(): string
返回对象的字符串表示形式。
**系统能力:**
SystemCapability.Utils.Lang
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| string | 返回对象的字符串表示形式。 |
**示例:**
```
js
let
pro
=
new
util
.
LruBuffer
();
pro
.
put
(
2
,
10
);
pro
.
get
(
2
);
pro
.
remove
(
20
);
let
result
=
pro
.
toString
();
```
### getCapacity<sup>8+(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[getCapacity9+](#getcapacity9)替代。
getCapacity(): number
获取当前缓冲区的容量。
**系统能力:**
SystemCapability.Utils.Lang
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| number | 返回当前缓冲区的容量。 |
**示例:**
```
js
let
pro
=
new
util
.
LruBuffer
();
let
result
=
pro
.
getCapacity
();
```
### clear<sup>8+(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[clear9+](#clear9)替代。
clear(): void
从当前缓冲区清除键值对。后续会调用afterRemoval()方法执行后续操作。
**系统能力:**
SystemCapability.Utils.Lang
**示例:**
```
js
let
pro
=
new
util
.
LruBuffer
();
pro
.
put
(
2
,
10
);
let
result
=
pro
.
length
;
pro
.
clear
();
```
### getCreateCount<sup>8+(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[getCreateCount9+](#getcreatecount9)替代。
getCreateCount(): number
获取createDefault()返回值的次数。
**系统能力:**
SystemCapability.Utils.Lang
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| number | 返回createDefault()返回值的次数。 |
**示例:**
```
js
let
pro
=
new
util
.
LruBuffer
();
pro
.
put
(
1
,
8
);
let
result
=
pro
.
getCreateCount
();
```
### getMissCount<sup>8+(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[getMissCount9+](#getmisscount9)替代。
getMissCount(): number
获取查询值不匹配的次数。
**系统能力:**
SystemCapability.Utils.Lang
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| number | 返回查询值不匹配的次数。 |
**示例:**
```
js
let
pro
=
new
util
.
LruBuffer
();
pro
.
put
(
2
,
10
);
pro
.
get
(
2
);
let
result
=
pro
.
getMissCount
();
```
### getRemovalCount<sup>8+(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[getRemovalCount9+](#getremovalcount9)替代。
getRemovalCount(): number
获取从缓冲区中逐出值的次数。
**系统能力:**
SystemCapability.Utils.Lang
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| number | 返回从缓冲区中驱逐的次数。 |
**示例:**
```
js
let
pro
=
new
util
.
LruBuffer
();
pro
.
put
(
2
,
10
);
pro
.
updateCapacity
(
2
);
pro
.
put
(
50
,
22
);
let
result
=
pro
.
getRemovalCount
();
```
### getMatchCount<sup>8+(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[getMatchCount9+](#getmatchcount9)替代。
getMatchCount(): number
获取查询值匹配成功的次数。
**系统能力:**
SystemCapability.Utils.Lang
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| number | 返回查询值匹配成功的次数。 |
**示例:**
```
js
let
pro
=
new
util
.
LruBuffer
();
pro
.
put
(
2
,
10
);
pro
.
get
(
2
);
let
result
=
pro
.
getMatchCount
();
```
### getPutCount<sup>8+(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[getPutCount9+](#getputcount9)替代。
getPutCount(): number
获取将值添加到缓冲区的次数。
**系统能力:**
SystemCapability.Utils.Lang
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| number | 返回将值添加到缓冲区的次数。 |
**示例:**
```
js
let
pro
=
new
util
.
LruBuffer
();
pro
.
put
(
2
,
10
);
let
result
=
pro
.
getPutCount
();
```
### isEmpty<sup>8+(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[isEmpty9+](#isempty9)替代。
isEmpty(): boolean
检查当前缓冲区是否为空。
**系统能力:**
SystemCapability.Utils.Lang
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| boolean | 如果当前缓冲区不包含任何值,则返回true。 |
**示例:**
```
js
let
pro
=
new
util
.
LruBuffer
();
pro
.
put
(
2
,
10
);
let
result
=
pro
.
isEmpty
();
```
### get<sup>8+(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[get9+](#get9)替代。
get(key: K): V | undefined
表示要查询的键。
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| key | K | 是 | 要查询的键。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| V
\|
undefined | 如果指定的键存在于缓冲区中,则返回与键关联的值;否则返回undefined。 |
**示例:**
```
js
let
pro
=
new
util
.
LruBuffer
();
pro
.
put
(
2
,
10
);
let
result
=
pro
.
get
(
2
);
```
### put<sup>8+(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[put9+](#put9)替代。
put(key: K,value: V): V
将键值对添加到缓冲区。
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| key | K | 是 | 要添加的密钥。 |
| value | V | 是 | 指示与要添加的键关联的值。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| V | 返回与添加的键关联的值;如果要添加的键已经存在,则返回原始值,如果键或值为空,则抛出此异常。 |
**示例:**
```
js
let
pro
=
new
util
.
LruBuffer
();
let
result
=
pro
.
put
(
2
,
10
);
```
### values<sup>8+(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[values9+](#values9)替代。
values(): V[]
获取当前缓冲区中所有值从最近访问到最近最少访问的顺序列表 。
**系统能力:**
SystemCapability.Utils.Lang
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| V
[] | 按从最近访问到最近最少访问的顺序返回当前缓冲区中所有值的列表。 |
**示例:**
```
js
let
pro
=
new
util
.
LruBuffer
();
pro
.
put
(
2
,
10
);
pro
.
put
(
2
,
"
anhu
"
);
pro
.
put
(
"
afaf
"
,
"
grfb
"
);
let
result
=
pro
.
values
();
```
### keys<sup>8+(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[keys9+](#keys9)替代。
keys(): K[]
获取当前缓冲区中所有键从最近访问到最近最少访问的升序列表。
**系统能力:**
SystemCapability.Utils.Lang
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| K
[] | 按升序返回当前缓冲区中所有键的列表,从最近访问到最近最少访问。 |
**示例:**
```
js
let
pro
=
new
util
.
LruBuffer
();
pro
.
put
(
2
,
10
);
let
result
=
pro
.
keys
();
```
### remove<sup>8+(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[remove9+](#remove9)替代。
remove(key: K): V | undefined
从当前缓冲区中删除指定的键及其关联的值。
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| key | K | 是 | 要删除的密钥。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| V
\|
undefined | 返回一个包含已删除键值对的Optional对象;如果key不存在,则返回一个空的Optional对象,如果key为null,则抛出异常。 |
**示例:**
```
js
let
pro
=
new
util
.
LruBuffer
();
pro
.
put
(
2
,
10
);
let
result
=
pro
.
remove
(
20
);
```
### afterRemoval<sup>8+(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[afterRemoval9+](#afterremoval9)替代。
afterRemoval(isEvict: boolean,key: K,value: V,newValue: V): void
删除值后执行后续操作。
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| isEvict | boolean | 否 | 因容量不足而调用该方法时,参数值为true,其他情况为false。 |
| key | K | 是 | 表示删除的键。 |
| value | V | 是 | 表示删除的值。 |
| newValue | V | 否 | 如果已调用put方法并且要添加的键已经存在,则参数值是关联的新值。其他情况下参数值为空。 |
**示例:**
```
js
let
arr
=
[];
class
ChildLruBuffer
<
K
,
V
>
extends
util
.
LruBuffer
<
K
,
V
>
{
constructor
()
{
super
();
}
afterRemoval
(
isEvict
,
key
,
value
,
newValue
)
{
if
(
isEvict
===
false
)
{
arr
=
[
key
,
value
,
newValue
];
}
}
}
let
lru
=
new
ChildLruBuffer
();
lru
.
afterRemoval
(
false
,
10
,
30
,
null
);
```
### contains<sup>8+(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[contains9+](#contains9)替代。
contains(key: K): boolean
检查当前缓冲区是否包含指定的键。
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| key | K | 是 | 表示要检查的键。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| boolean | 如果缓冲区包含指定的键,则返回
true。 |
**示例:**
```
js
let
pro
=
new
util
.
LruBuffer
();
pro
.
put
(
2
,
10
);
let
result
=
pro
.
contains
(
20
);
```
### createDefault<sup>8+(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[createDefault9+](#createdefault9)替代。
createDefault(key: K): V
如果未计算特定键的值,则执行后续操作,参数表示丢失的键,返回与键关联的值。
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| key | K | 是 | 表示丢失的键。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| V | 返回与键关联的值。 |
**示例:**
```
js
let
pro
=
new
util
.
LruBuffer
();
let
result
=
pro
.
createDefault
(
50
);
```
### entries<sup>8+(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[entries9+](#entries9)替代。
entries(): IterableIterator
<
[K,V]
>
允许迭代包含在这个对象中的所有键值对。
**系统能力:**
SystemCapability.Utils.Lang
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| [K,
V] | 返回一个可迭代数组。 |
**示例:**
```
js
let
pro
=
new
util
.
LruBuffer
();
pro
.
put
(
2
,
10
);
let
result
=
pro
.
entries
();
```
### [Symbol.iterator]<sup>8+(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[Symbol.iterator9+](#symboliterator9)替代。
[Symbol.iterator]
\(
): IterableIterator
<
[K, V]
>
返回一个键值对形式的二维数组。
**系统能力:**
SystemCapability.Utils.Lang
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| [K,
V] | 返回一个键值对形式的二维数组。 |
**示例:**
```
js
let
pro
=
new
util
.
LruBuffer
();
pro
.
put
(
2
,
10
);
let
result
=
pro
[
Symbol
.
iterator
]();
```
### ScopeType<sup>8+</sup>
用于表示范围中的值的类型。该类型的值,类型可以为ScopeComparable或number。
ScopeComparable类型的值需要实现compareTo方法,确保传入的数据具有可比性。
```
js
interface
ScopeComparable
{
compareTo
(
other
:
ScopeComparable
):
boolean
;
}
type
ScopeType
=
ScopeComparable
|
number
;
```
构造新类,实现compareTo方法。后续示例代码中,均通过Temperature,获取
[
ScopeType
](
#scopetype8
)
的实例化对象。
示例:
```
js
class
Temperature
{
constructor
(
value
){
// 当使用ts语言开发时,需要补充以下代码:
// private readonly _temp: Temperature;
this
.
_temp
=
value
;
}
compareTo
(
value
){
return
this
.
_temp
>=
value
.
getTemp
();
}
getTemp
(){
return
this
.
_temp
;
}
toString
(){
return
this
.
_temp
.
toString
();
}
}
```
## ScopeHelper<sup>9+</sup>
### constructor<sup>9+</sup>
constructor(lowerObj: ScopeType, upperObj: ScopeType)
用于创建指定下限和上限的作用域实例的构造函数,返回一个ScopeHelper对象。
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------ | ---- | ---------------------- |
| lowerObj |
[
ScopeType
](
#scopetype8
)
| 是 | 指定作用域实例的下限。 |
| upperObj |
[
ScopeType
](
#scopetype8
)
| 是 | 指定作用域实例的上限。 |
**示例:**
```
js
let
tempLower
=
new
Temperature
(
30
);
let
tempUpper
=
new
Temperature
(
40
);
let
range
=
new
util
.
ScopeHelper
(
tempLower
,
tempUpper
);
```
### toString<sup>9+</sup>
toString(): string
该字符串化方法返回一个包含当前范围的字符串表示形式。
**系统能力:**
SystemCapability.Utils.Lang
**返回值:**
| 类型 | 说明 |
| ------ | -------------------------------------- |
| string | 返回包含当前范围对象的字符串表示形式。 |
**示例:**
```
js
let
tempLower
=
new
Temperature
(
30
);
let
tempUpper
=
new
Temperature
(
40
);
let
range
=
new
util
.
ScopeHelper
(
tempLower
,
tempUpper
);
let
result
=
range
.
toString
();
```
### intersect<sup>9+</sup>
intersect(range: ScopeHelper): ScopeHelper
获取给定范围和当前范围的交集。
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------------------------ | ---- | ------------------ |
| range |
[
ScopeHelper9+
](
#scopehelper9
)
| 是 | 传入一个给定范围。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------ | ------------------------------ |
|
[
ScopeHelper9+
](
#scopehelper9
)
| 返回给定范围和当前范围的交集。 |
**示例:**
```
js
let
tempLower
=
new
Temperature
(
30
);
let
tempUpper
=
new
Temperature
(
40
);
let
range
=
new
util
.
ScopeHelper
(
tempLower
,
tempUpper
);
let
tempMiDF
=
new
Temperature
(
35
);
let
tempMidS
=
new
Temperature
(
39
);
let
rangeFir
=
new
util
.
ScopeHelper
(
tempMiDF
,
tempMidS
);
range
.
intersect
(
rangeFir
);
```
### intersect<sup>9+</sup>
intersect(lowerObj:ScopeType,upperObj:ScopeType):ScopeHelper
获取当前范围与给定下限和上限范围的交集。
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------ | ---- | ---------------- |
| lowerObj |
[
ScopeType
](
#scopetype8
)
| 是 | 给定范围的下限。 |
| upperObj |
[
ScopeType
](
#scopetype8
)
| 是 | 给定范围的上限。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------ | ---------------------------------------- |
|
[
ScopeHelper9+
](
#scopehelper9
)
| 返回当前范围与给定下限和上限范围的交集。 |
**示例:**
```
js
let
tempLower
=
new
Temperature
(
30
);
let
tempUpper
=
new
Temperature
(
40
);
let
tempMiDF
=
new
Temperature
(
35
);
let
tempMidS
=
new
Temperature
(
39
);
let
range
=
new
util
.
ScopeHelper
(
tempLower
,
tempUpper
);
let
result
=
range
.
intersect
(
tempMiDF
,
tempMidS
);
```
### getUpper<sup>9+</sup>
getUpper(): ScopeType
获取当前范围的上限。
**系统能力:**
SystemCapability.Utils.Lang
**返回值:**
| 类型 | 说明 |
| ------------------------ | ---------------------- |
|
[
ScopeType
](
#scopetype8
)
| 返回当前范围的上限值。 |
**示例:**
```
js
let
tempLower
=
new
Temperature
(
30
);
let
tempUpper
=
new
Temperature
(
40
);
let
range
=
new
util
.
ScopeHelper
(
tempLower
,
tempUpper
);
let
result
=
range
.
getUpper
();
```
### getLower<sup>9+</sup>
getLower(): ScopeType
获取当前范围的下限。
**系统能力:**
SystemCapability.Utils.Lang
**返回值:**
| 类型 | 说明 |
| ------------------------ | ---------------------- |
|
[
ScopeType
](
#scopetype8
)
| 返回当前范围的下限值。 |
**示例:**
```
js
let
tempLower
=
new
Temperature
(
30
);
let
tempUpper
=
new
Temperature
(
40
);
let
range
=
new
util
.
ScopeHelper
(
tempLower
,
tempUpper
);
let
result
=
range
.
getLower
();
```
### expand<sup>9+</sup>
expand(lowerObj: ScopeType,upperObj: ScopeType): ScopeHelper
创建并返回包括当前范围和给定下限和上限的并集。
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------ | ---- | ---------------- |
| lowerObj |
[
ScopeType
](
#scopetype8
)
| 是 | 给定范围的下限。 |
| upperObj |
[
ScopeType
](
#scopetype8
)
| 是 | 给定范围的上限。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------ | ------------------------------------ |
|
[
ScopeHelper9+
](
#scopehelper9
)
| 返回当前范围和给定下限和上限的并集。 |
**示例:**
```
js
let
tempLower
=
new
Temperature
(
30
);
let
tempUpper
=
new
Temperature
(
40
);
let
tempMiDF
=
new
Temperature
(
35
);
let
tempMidS
=
new
Temperature
(
39
);
let
range
=
new
util
.
ScopeHelper
(
tempLower
,
tempUpper
);
let
result
=
range
.
expand
(
tempMiDF
,
tempMidS
);
```
### expand<sup>9+</sup>
expand(range: ScopeHelper): ScopeHelper
创建并返回包括当前范围和给定范围的并集。
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------------------------ | ---- | ------------------ |
| range |
[
ScopeHelper9+
](
#scopehelper9
)
| 是 | 传入一个给定范围。 |
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| --------
|
-------- |
| --------
---------------------- | --------------------------
-------- |
|
boolean | 如果缓冲区包含指定的键,则返回
true
。 |
|
[
ScopeHelper9+
](
#scopehelper9
)
| 返回包括当前范围和给定范围的并集
。 |
**示例:**
**示例:**
```
js
```
js
let
pro
=
new
util
.
LruBuffer
();
let
tempLower
=
new
Temperature
(
30
);
pro
.
put
(
2
,
10
);
let
tempUpper
=
new
Temperature
(
40
);
let
result
=
pro
.
contains
(
20
);
let
tempMiDF
=
new
Temperature
(
35
);
let
tempMidS
=
new
Temperature
(
39
);
let
range
=
new
util
.
ScopeHelper
(
tempLower
,
tempUpper
);
let
rangeFir
=
new
util
.
ScopeHelper
(
tempMiDF
,
tempMidS
);
let
result
=
range
.
expand
(
rangeFir
);
```
```
###
createDefault<sup>8
+</sup>
###
expand<sup>9
+</sup>
createDefault(key: K): V
expand(value: ScopeType): ScopeHelper
如果未计算特定键的值,则执行后续操作,参数表示丢失的键,返回与键关联的值
。
创建并返回包括当前范围和给定值的并集
。
**系统能力:**
SystemCapability.Utils.Lang
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
**参数:**
| 参数名 | 类型
| 必填 | 说明
|
| 参数名 | 类型
| 必填 | 说明
|
| ------
-- | -------- | -------- |
-------- |
| ------
| ------------------------ | ---- | --------
-------- |
|
key | K | 是 | 表示丢失的键
。 |
|
value |
[
ScopeType
](
#scopetype8
)
| 是 | 传入一个给定值
。 |
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| --------
|
-------- |
| --------
---------------------- | ------------------------
-------- |
|
V | 返回与键关联的值
。 |
|
[
ScopeHelper9+
](
#scopehelper9
)
| 返回包括当前范围和给定值的并集
。 |
**示例:**
**示例:**
```
js
```
js
let
pro
=
new
util
.
LruBuffer
();
let
tempLower
=
new
Temperature
(
30
);
let
result
=
pro
.
createDefault
(
50
);
let
tempUpper
=
new
Temperature
(
40
);
let
tempMiDF
=
new
Temperature
(
35
);
let
range
=
new
util
.
ScopeHelper
(
tempLower
,
tempUpper
);
let
result
=
range
.
expand
(
tempMiDF
);
```
```
###
entries<sup>8
+</sup>
###
contains<sup>9
+</sup>
entries(): IterableIterator
<
[K,V]
>
contains(value: ScopeType): boolean
允许迭代包含在这个对象中的所有键值对
。
检查给定value是否包含在当前范围内
。
**系统能力:**
SystemCapability.Utils.Lang
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------------------ | ---- | ---------------- |
| value |
[
ScopeType
](
#scopetype8
)
| 是 | 传入一个给定值。 |
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| -------
- |
-------- |
| -------
| -------------------------------------------
-------- |
|
[K,
V] | 返回一个可迭代数组
。 |
|
boolean | 如果给定值包含在当前范围内返回true,否则返回false
。 |
**示例:**
**示例:**
```
js
```
js
let
pro
=
new
util
.
LruBuffer
();
let
tempLower
=
new
Temperature
(
30
);
pro
.
put
(
2
,
10
);
let
tempUpper
=
new
Temperature
(
40
);
let
result
=
pro
.
entries
();
let
tempMiDF
=
new
Temperature
(
35
);
let
range
=
new
util
.
ScopeHelper
(
tempLower
,
tempUpper
);
range
.
contains
(
tempMiDF
);
```
```
###
[Symbol.iterator]<sup>8
+</sup>
###
contains<sup>9
+</sup>
[Symbol.iterator]
\(
): IterableIterator
<
[K, V]
>
contains(range: ScopeHelper): boolean
返回一个键值对形式的二维数组
。
检查给定range是否在当前范围内
。
**系统能力:**
SystemCapability.Utils.Lang
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------------------------ | ---- | ------------------ |
| range |
[
ScopeHelper9+
](
#scopehelper9
)
| 是 | 传入一个给定范围。 |
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| -------
- |
-------- |
| -------
| ---------------------------------------------
-------- |
|
[K,
V] | 返回一个键值对形式的二维数组
。 |
|
boolean | 如果给定范围包含在当前范围内返回true,否则返回false
。 |
**示例:**
**示例:**
```
js
```
js
let
pro
=
new
util
.
LruBuffer
();
let
tempLower
=
new
Temperature
(
30
);
pro
.
put
(
2
,
10
);
let
tempUpper
=
new
Temperature
(
40
);
let
result
=
pro
[
Symbol
.
iterator
]();
let
range
=
new
util
.
ScopeHelper
(
tempLower
,
tempUpper
);
let
tempLess
=
new
Temperature
(
20
);
let
tempMore
=
new
Temperature
(
45
);
let
rangeSec
=
new
util
.
ScopeHelper
(
tempLess
,
tempMore
);
let
result
=
range
.
contains
(
rangeSec
);
```
```
##
Scope<sup>8
+</sup>
##
# clamp<sup>9
+</sup>
clamp(value: ScopeType): ScopeType
### ScopeType<sup>8+</sup>
将给定值限定到当前范围内。
用于表示范围中的值的类型。该类型的值,类型可以为ScopeComparable或number。
**系统能力:**
SystemCapability.Utils.Lang
ScopeComparable类型的值需要实现compareTo方法,确保传入的数据具有可比性。
**参数:**
```
js
interface
ScopeComparable
{
compareTo
(
other
:
ScopeComparable
):
boolean
;
}
type
ScopeType
=
ScopeComparable
|
number
;
```
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------------------ | ---- | -------------- |
| value |
[
ScopeType
](
#scopetype8
)
| 是 | 传入的给定值。 |
构造新类,实现compareTo方法。后续示例代码中,均通过Temperature,获取
[
ScopeType
](
#scopetype8
)
的实例化对象。
**返回值:**
| 类型 | 说明 |
| ------------------------ | ------------------------------------------------------------ |
|
[
ScopeType
](
#scopetype8
)
| 如果传入的value小于下限,则返回lowerObj;如果大于上限值则返回upperObj;如果在当前范围内,则返回value。 |
示例:
**示例:**
```
js
class
Temperature
{
constructor
(
value
){
// 当使用ts语言开发时,需要补充以下代码:
// private readonly _temp: Temperature;
this
.
_temp
=
value
;
}
compareTo
(
value
){
return
this
.
_temp
>=
value
.
getTemp
();
}
getTemp
(){
return
this
.
_temp
;
}
toString
(){
return
this
.
_temp
.
toString
();
}
}
```
```
js
let
tempLower
=
new
Temperature
(
30
);
let
tempUpper
=
new
Temperature
(
40
);
let
tempMiDF
=
new
Temperature
(
35
);
let
range
=
new
util
.
ScopeHelper
(
tempLower
,
tempUpper
);
let
result
=
range
.
clamp
(
tempMiDF
);
```
### constructor<sup>8+</sup>
## Scope<sup>8+(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[ScopeHelper9+](#scopehelper9)替代。
### constructor<sup>8+(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[constructor9+](#constructor9)替代。
constructor(lowerObj: ScopeType, upperObj: ScopeType)
constructor(lowerObj: ScopeType, upperObj: ScopeType)
...
@@ -1325,8 +2522,10 @@ constructor(lowerObj: ScopeType, upperObj: ScopeType)
...
@@ -1325,8 +2522,10 @@ constructor(lowerObj: ScopeType, upperObj: ScopeType)
let
range
=
new
util
.
Scope
(
tempLower
,
tempUpper
);
let
range
=
new
util
.
Scope
(
tempLower
,
tempUpper
);
```
```
### toString<sup>8+(deprecated)</sup>
### toString<sup>8+</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[toString9+](#tostring9)替代。
toString(): string
toString(): string
...
@@ -1348,8 +2547,10 @@ toString(): string
...
@@ -1348,8 +2547,10 @@ toString(): string
let
result
=
range
.
toString
();
let
result
=
range
.
toString
();
```
```
### intersect<sup>8+(deprecated)</sup>
### intersect<sup>8+</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[intersect9+](#intersect9)替代。
intersect(range: Scope): Scope
intersect(range: Scope): Scope
...
@@ -1370,6 +2571,7 @@ intersect(range: Scope): Scope
...
@@ -1370,6 +2571,7 @@ intersect(range: Scope): Scope
|
[
Scope
](
#scope8
)
| 返回给定范围和当前范围的交集。 |
|
[
Scope
](
#scope8
)
| 返回给定范围和当前范围的交集。 |
**示例:**
**示例:**
```
js
```
js
let
tempLower
=
new
Temperature
(
30
);
let
tempLower
=
new
Temperature
(
30
);
let
tempUpper
=
new
Temperature
(
40
);
let
tempUpper
=
new
Temperature
(
40
);
...
@@ -1380,8 +2582,10 @@ intersect(range: Scope): Scope
...
@@ -1380,8 +2582,10 @@ intersect(range: Scope): Scope
range
.
intersect
(
rangeFir
);
range
.
intersect
(
rangeFir
);
```
```
### intersect<sup>8+(deprecated)</sup>
### intersect<sup>8+</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[intersect9+](#intersect9)替代。
intersect(lowerObj:ScopeType,upperObj:ScopeType):Scope
intersect(lowerObj:ScopeType,upperObj:ScopeType):Scope
...
@@ -1412,8 +2616,10 @@ intersect(lowerObj:ScopeType,upperObj:ScopeType):Scope
...
@@ -1412,8 +2616,10 @@ intersect(lowerObj:ScopeType,upperObj:ScopeType):Scope
let
result
=
range
.
intersect
(
tempMiDF
,
tempMidS
);
let
result
=
range
.
intersect
(
tempMiDF
,
tempMidS
);
```
```
### getUpper<sup>8+(deprecated)</sup>
### getUpper<sup>8+</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[getUpper9+](#getupper9)替代。
getUpper(): ScopeType
getUpper(): ScopeType
...
@@ -1435,8 +2641,10 @@ getUpper(): ScopeType
...
@@ -1435,8 +2641,10 @@ getUpper(): ScopeType
let
result
=
range
.
getUpper
();
let
result
=
range
.
getUpper
();
```
```
### getLower<sup>8+(deprecated)</sup>
### getLower<sup>8+</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[getLower9+](#getlower9)替代。
getLower(): ScopeType
getLower(): ScopeType
...
@@ -1458,8 +2666,10 @@ getLower(): ScopeType
...
@@ -1458,8 +2666,10 @@ getLower(): ScopeType
let
result
=
range
.
getLower
();
let
result
=
range
.
getLower
();
```
```
### expand<sup>8+(deprecated)</sup>
### expand<sup>8+</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[expand9+](#expand9)替代。
expand(lowerObj: ScopeType,upperObj: ScopeType): Scope
expand(lowerObj: ScopeType,upperObj: ScopeType): Scope
...
@@ -1491,8 +2701,10 @@ expand(lowerObj: ScopeType,upperObj: ScopeType): Scope
...
@@ -1491,8 +2701,10 @@ expand(lowerObj: ScopeType,upperObj: ScopeType): Scope
let
result
=
range
.
expand
(
tempMiDF
,
tempMidS
);
let
result
=
range
.
expand
(
tempMiDF
,
tempMidS
);
```
```
### expand<sup>8+(deprecated)</sup>
### expand<sup>8+</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[expand9+](#expand9)替代。
expand(range: Scope): Scope
expand(range: Scope): Scope
...
@@ -1523,8 +2735,10 @@ expand(range: Scope): Scope
...
@@ -1523,8 +2735,10 @@ expand(range: Scope): Scope
let
result
=
range
.
expand
(
rangeFir
);
let
result
=
range
.
expand
(
rangeFir
);
```
```
### expand<sup>8+(deprecated)</sup>
### expand<sup>8+</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[expand9+](#expand9)替代。
expand(value: ScopeType): Scope
expand(value: ScopeType): Scope
...
@@ -1553,8 +2767,10 @@ expand(value: ScopeType): Scope
...
@@ -1553,8 +2767,10 @@ expand(value: ScopeType): Scope
let
result
=
range
.
expand
(
tempMiDF
);
let
result
=
range
.
expand
(
tempMiDF
);
```
```
### contains<sup>8+(deprecated)</sup>
### contains<sup>8+</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[contains9+](#contains9)替代。
contains(value: ScopeType): boolean
contains(value: ScopeType): boolean
...
@@ -1583,8 +2799,10 @@ contains(value: ScopeType): boolean
...
@@ -1583,8 +2799,10 @@ contains(value: ScopeType): boolean
range
.
contains
(
tempMiDF
);
range
.
contains
(
tempMiDF
);
```
```
### contains<sup>8+(deprecated)</sup>
### contains<sup>8+</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[contains9+](#contains9)替代。
contains(range: Scope): boolean
contains(range: Scope): boolean
...
@@ -1605,6 +2823,7 @@ contains(range: Scope): boolean
...
@@ -1605,6 +2823,7 @@ contains(range: Scope): boolean
| boolean | 如果给定范围包含在当前范围内返回true,否则返回false。 |
| boolean | 如果给定范围包含在当前范围内返回true,否则返回false。 |
**示例:**
**示例:**
```
js
```
js
let
tempLower
=
new
Temperature
(
30
);
let
tempLower
=
new
Temperature
(
30
);
let
tempUpper
=
new
Temperature
(
40
);
let
tempUpper
=
new
Temperature
(
40
);
...
@@ -1615,8 +2834,10 @@ contains(range: Scope): boolean
...
@@ -1615,8 +2834,10 @@ contains(range: Scope): boolean
let
result
=
range
.
contains
(
rangeSec
);
let
result
=
range
.
contains
(
rangeSec
);
```
```
### clamp<sup>8+(deprecated)</sup>
### clamp<sup>8+</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[clamp9+](#clamp9)替代。
clamp(value: ScopeType): ScopeType
clamp(value: ScopeType): ScopeType
...
@@ -1645,11 +2866,217 @@ clamp(value: ScopeType): ScopeType
...
@@ -1645,11 +2866,217 @@ clamp(value: ScopeType): ScopeType
let
result
=
range
.
clamp
(
tempMiDF
);
let
result
=
range
.
clamp
(
tempMiDF
);
```
```
## Base64Helper<sup>9+</sup>
##
Base64<sup>8
+</sup>
##
# constructor<sup>9
+</sup>
constructor()
### constructor<sup>8+</sup>
Base64Helper的构造函数。
**系统能力:**
SystemCapability.Utils.Lang
**示例:**
```
js
let
base64
=
new
util
.
Base64Helper
();
```
### encodeSync<sup>9+</sup>
encodeSync(src: Uint8Array): Uint8Array
通过输入参数编码后输出对应文本。
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ---------- | ---- | ------------------- |
| src | Uint8Array | 是 | 编码输入Uint8数组。 |
**返回值:**
| 类型 | 说明 |
| ---------- | ----------------------------- |
| Uint8Array | 返回编码后新分配的Uint8数组。 |
**示例:**
```
js
let
that
=
new
util
.
Base64Helper
();
let
array
=
new
Uint8Array
([
115
,
49
,
51
]);
let
result
=
that
.
encodeSync
(
array
);
```
### encodeToStringSync<sup>9+</sup>
encodeToStringSync(src: Uint8Array): string
通过输入参数编码后输出对应文本。
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ---------- | ---- | ------------------- |
| src | Uint8Array | 是 | 编码输入Uint8数组。 |
**返回值:**
| 类型 | 说明 |
| ------ | -------------------- |
| string | 返回编码后的字符串。 |
**示例:**
```
js
let
that
=
new
util
.
Base64Helper
();
let
array
=
new
Uint8Array
([
115
,
49
,
51
]);
let
result
=
that
.
encodeToStringSync
(
array
);
```
### decodeSync<sup>9+</sup>
decodeSync(src: Uint8Array | string): Uint8Array
通过输入参数解码后输出对应文本。
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------------------------ | ---- | ----------------------------- |
| src | Uint8Array
\|
string | 是 | 解码输入Uint8数组或者字符串。 |
**返回值:**
| 类型 | 说明 |
| ---------- | ----------------------------- |
| Uint8Array | 返回解码后新分配的Uint8数组。 |
**示例:**
```
js
let
that
=
new
util
.
Base64Helper
();
let
buff
=
'
czEz
'
;
let
result
=
that
.
decodeSync
(
buff
);
```
### encode<sup>9+</sup>
encode(src: Uint8Array): Promise
<
Uint8Array
>
通过输入参数异步编码后输出对应文本。
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ---------- | ---- | ----------------------- |
| src | Uint8Array | 是 | 异步编码输入Uint8数组。 |
**返回值:**
| 类型 | 说明 |
| ------------------------- | --------------------------------- |
| Promise
<
Uint8Array
>
| 返回异步编码后新分配的Uint8数组。 |
**示例:**
```
js
let
that
=
new
util
.
Base64Helper
();
let
array
=
new
Uint8Array
([
115
,
49
,
51
]);
let
rarray
=
new
Uint8Array
([
99
,
122
,
69
,
122
]);
that
.
encode
(
array
).
then
(
val
=>
{
for
(
var
i
=
0
;
i
<
rarray
.
length
;
i
++
)
{
console
.
log
(
val
[
i
].
toString
())
}
})
```
### encodeToString<sup>9+</sup>
encodeToString(src: Uint8Array): Promise
<
string
>
通过输入参数异步编码后输出对应文本。
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ---------- | ---- | ----------------------- |
| src | Uint8Array | 是 | 异步编码输入Uint8数组。 |
**返回值:**
| 类型 | 说明 |
| --------------------- | ------------------------ |
| Promise
<
string
>
| 返回异步编码后的字符串。 |
**示例:**
```
js
let
that
=
new
util
.
Base64Helper
();
let
array
=
new
Uint8Array
([
115
,
49
,
51
]);
that
.
encodeToString
(
array
).
then
(
val
=>
{
console
.
log
(
val
)
})
```
### decode<sup>9+</sup>
decode(src: Uint8Array | string): Promise
<
Uint8Array
>
通过输入参数异步解码后输出对应文本。
**系统能力:**
SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------------------------ | ---- | --------------------------------- |
| src | Uint8Array
\|
string | 是 | 异步解码输入Uint8数组或者字符串。 |
**返回值:**
| 类型 | 说明 |
| ------------------------- | --------------------------------- |
| Promise
<
Uint8Array
>
| 返回异步解码后新分配的Uint8数组。 |
**示例:**
```
js
let
that
=
new
util
.
Base64Helper
();
let
array
=
new
Uint8Array
([
99
,
122
,
69
,
122
]);
let
rarray
=
new
Uint8Array
([
115
,
49
,
51
]);
that
.
decode
(
array
).
then
(
val
=>
{
for
(
var
i
=
0
;
i
<
rarray
.
length
;
i
++
)
{
console
.
log
(
val
[
i
].
toString
())
}
})
```
## Base64<sup>8+(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[Base64Helper9+](#base64helper9)替代。
### constructor<sup>8+(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[constructor9+](#constructor9)替代。
constructor()
constructor()
...
@@ -1662,8 +3089,10 @@ Base64的构造函数。
...
@@ -1662,8 +3089,10 @@ Base64的构造函数。
let
base64
=
new
util
.
Base64
();
let
base64
=
new
util
.
Base64
();
```
```
### encodeSync<sup>8+(deprecated)</sup>
### encodeSync<sup>8+</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[encodeSync9+](#encodesync9)替代。
encodeSync(src: Uint8Array): Uint8Array
encodeSync(src: Uint8Array): Uint8Array
...
@@ -1684,14 +3113,17 @@ encodeSync(src: Uint8Array): Uint8Array
...
@@ -1684,14 +3113,17 @@ encodeSync(src: Uint8Array): Uint8Array
| Uint8Array | 返回编码后新分配的Uint8数组。 |
| Uint8Array | 返回编码后新分配的Uint8数组。 |
**示例:**
**示例:**
```
js
```
js
let
that
=
new
util
.
Base64
();
let
that
=
new
util
.
Base64
();
let
array
=
new
Uint8Array
([
115
,
49
,
51
]);
let
array
=
new
Uint8Array
([
115
,
49
,
51
]);
let
result
=
that
.
encodeSync
(
array
);
let
result
=
that
.
encodeSync
(
array
);
```
```
### encodeToStringSync<sup>8+(deprecated)</sup>
### encodeToStringSync<sup>8+</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[encodeToStringSync9+](#encodetostringsync9)替代。
encodeToStringSync(src: Uint8Array): string
encodeToStringSync(src: Uint8Array): string
...
@@ -1718,8 +3150,10 @@ encodeToStringSync(src: Uint8Array): string
...
@@ -1718,8 +3150,10 @@ encodeToStringSync(src: Uint8Array): string
let
result
=
that
.
encodeToStringSync
(
array
);
let
result
=
that
.
encodeToStringSync
(
array
);
```
```
### decodeSync<sup>8+(deprecated)</sup>
### decodeSync<sup>8+</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[decodeSync9+](#decodesync9)替代。
decodeSync(src: Uint8Array | string): Uint8Array
decodeSync(src: Uint8Array | string): Uint8Array
...
@@ -1746,8 +3180,10 @@ decodeSync(src: Uint8Array | string): Uint8Array
...
@@ -1746,8 +3180,10 @@ decodeSync(src: Uint8Array | string): Uint8Array
let
result
=
that
.
decodeSync
(
buff
);
let
result
=
that
.
decodeSync
(
buff
);
```
```
### encode<sup>8+(deprecated)</sup>
### encode<sup>8+</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[encode9+](#encode9)替代。
encode(src: Uint8Array): Promise
<
Uint8Array
>
encode(src: Uint8Array): Promise
<
Uint8Array
>
...
@@ -1779,8 +3215,10 @@ encode(src: Uint8Array): Promise<Uint8Array>
...
@@ -1779,8 +3215,10 @@ encode(src: Uint8Array): Promise<Uint8Array>
})
})
```
```
### encodeToString<sup>8+(deprecated)</sup>
### encodeToString<sup>8+</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[encodeToString9+](#encodetostring9)替代。
encodeToString(src: Uint8Array): Promise
<
string
>
encodeToString(src: Uint8Array): Promise
<
string
>
...
@@ -1809,8 +3247,10 @@ encodeToString(src: Uint8Array): Promise<string>
...
@@ -1809,8 +3247,10 @@ encodeToString(src: Uint8Array): Promise<string>
})
})
```
```
### decode<sup>8+(deprecated)</sup>
### decode<sup>8+</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[decode9+](#decode9)替代。
decode(src: Uint8Array | string): Promise
<
Uint8Array
>
decode(src: Uint8Array | string): Promise
<
Uint8Array
>
...
@@ -1842,7 +3282,6 @@ decode(src: Uint8Array | string): Promise<Uint8Array>
...
@@ -1842,7 +3282,6 @@ decode(src: Uint8Array | string): Promise<Uint8Array>
})
})
```
```
## types<sup>8+</sup>
## types<sup>8+</sup>
...
@@ -2926,4 +4365,5 @@ isSharedArrayBuffer(value: Object): boolean
...
@@ -2926,4 +4365,5 @@ isSharedArrayBuffer(value: Object): boolean
```
js
```
js
let
that
=
new
util
.
types
();
let
that
=
new
util
.
types
();
let
result
=
that
.
isSharedArrayBuffer
(
new
SharedArrayBuffer
(
0
));
let
result
=
that
.
isSharedArrayBuffer
(
new
SharedArrayBuffer
(
0
));
```
```
\ No newline at end of file
<!--no_check-->
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录