未验证 提交 16dfd9df 编写于 作者: O openharmony_ci 提交者: Gitee

!18154 翻译完成:17259+17901 Problems in modifying docs data

Merge pull request !18154 from wusongqing/TR17259
# @ohos.util.ArrayList (Linear Container ArrayList)
> **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**ArrayList** is a linear data structure that is implemented based on arrays. **ArrayList** can dynamically adjust the capacity based on project requirements. It increases the capacity by 50% each time.
Similar to **ArrayList**, **[Vector](js-apis-vector.md)** is also implemented based on arrays and can dynamically adjust the capacity. It increases the capability by 100% each time.
......@@ -14,6 +11,11 @@ When compared with **[LinkedList](js-apis-linkedlist.md)**, **ArrayList** is mor
This topic uses the following to identify the use of generics:
- T: Type
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```ts
......@@ -160,9 +162,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
```ts
let arrayList = new ArrayList();
let result = arrayList.has("squirrel");
arrayList.add("squirrel");
let result1 = arrayList.has("squirrel");
let result = arrayList.has("squirrel");
```
### getIndexOf
......@@ -535,9 +536,7 @@ arrayList.add(2);
arrayList.add(4);
arrayList.add(5);
arrayList.add(4);
let result1 = arrayList.subArrayList(2, 4);
let result2 = arrayList.subArrayList(4, 3);
let result3 = arrayList.subArrayList(2, 6);
let result = arrayList.subArrayList(2, 4);
```
### clear
......
......@@ -156,9 +156,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
```ts
let deque = new Deque();
let result = deque.has("squirrel");
deque.insertFront("squirrel");
let result1 = deque.has("squirrel");
let result = deque.has("squirrel");
```
### popFirst
......
......@@ -119,9 +119,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
```ts
let hashMap = new HashMap();
let result = hashMap.hasKey("squirrel");
hashMap.set("squirrel", 123);
let result1 = hashMap.hasKey("squirrel");
let result = hashMap.hasKey("squirrel");
```
......@@ -157,9 +156,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
```ts
let hashMap = new HashMap();
let result = hashMap.hasValue(123);
hashMap.set("squirrel", 123);
let result1 = hashMap.hasValue(123);
let result = hashMap.hasValue(123);
```
......@@ -230,6 +228,7 @@ let hashMap = new HashMap();
hashMap.set("squirrel", 123);
hashMap.set("sparrow", 356);
let newHashMap = new HashMap();
newHashMap.set("newMap", 99);
hashMap.setAll(newHashMap);
```
......
# @ohos.util.HashSet (Nonlinear Container HashSet)
> **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**HashSet** is implemented based on [HashMap](js-apis-hashmap.md). In **HashSet**, only the **value** object is processed.
Unlike [TreeSet](js-apis-treeset.md), which stores and accesses data in sorted order, **HashSet** stores data in a random order. This means that **HashSet** may use a different order when storing and accessing elements. Both of them allows only unique elements. However, null values are allowed in **HashSet**, but not allowed in **TreeSet**.
......@@ -12,6 +9,11 @@ Unlike [TreeSet](js-apis-treeset.md), which stores and accesses data in sorted o
This topic uses the following to identify the use of generics:
- T: Type
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```ts
......@@ -125,9 +127,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
```ts
let hashSet = new HashSet();
let result = hashSet.has("squirrel");
hashSet.add("squirrel");
let result1 = hashSet.has("squirrel");
let result = hashSet.has("squirrel");
```
......
# @ohos.util.LightWeightMap (Nonlinear Container LightWeightMap)
> **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**LightWeightMap** stores key-value (KV) pairs. Each key must be unique and have only one value.
**LightWeightMap** is based on generics and uses a lightweight structure. Its default initial capacity is 8, and it has the capacity doubled in each expansion.
......@@ -17,6 +14,11 @@ This topic uses the following to identify the use of generics:
- K: Key
- V: Value
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```ts
......@@ -197,9 +199,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
```ts
let lightWeightMap = new LightWeightMap();
let result = lightWeightMap.hasValue(123);
lightWeightMap.set("squirrel", 123);
let result1 = lightWeightMap.hasValue(123);
let result = lightWeightMap.hasValue(123);
```
......
# @ohos.util.LightWeightSet (Nonlinear Container LightWeightSet)
> **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**LightWeightSet** stores a set of values, each of which must be unique.
**LightWeightSet** is based on generics and uses a lightweight structure. Its default initial capacity is 8, and it has the capacity doubled in each expansion.
......@@ -16,6 +13,11 @@ Compared with **[HashSet](js-apis-hashset.md)**, which can also store values, **
This topic uses the following to identify the use of generics:
- T: Type
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```ts
......@@ -227,9 +229,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
```ts
let lightWeightSet = new LightWeightSet();
let result = lightWeightSet.has(123);
lightWeightSet.add(123);
result = lightWeightSet.has(123);
let result = lightWeightSet.has(123);
```
......@@ -267,7 +268,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
let lightWeightSet = new LightWeightSet();
lightWeightSet.add("squirrel");
lightWeightSet.add("sparrow");
let obj = ["squirrel", "sparrow"];
let obj = ["sparrow", "squirrel"];
let result = lightWeightSet.equal(obj);
```
......
......@@ -198,7 +198,6 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
```ts
let linkedList = new LinkedList();
let result1 = linkedList.has("squirrel");
linkedList.add("squirrel");
let result = linkedList.has("squirrel");
```
......@@ -802,7 +801,7 @@ linkedList.add(2);
linkedList.add(4);
linkedList.add(5);
linkedList.add(4);
linkedList.getLast();
let result = linkedList.getLast();
```
### [Symbol.iterator]
......
......@@ -13,6 +13,7 @@ This topic uses the following to identify the use of generics:
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```ts
......@@ -160,9 +161,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
```ts
let list = new List();
let result = list.has("squirrel");
list.add("squirrel");
let result1 = list.has("squirrel");
let result = list.has("squirrel");
```
### get
......@@ -288,7 +288,6 @@ list.add(2);
list.add(1);
list.add(2);
list.add(4);
list.getIndexOf(2);
let result = list.getIndexOf(2);
```
......@@ -327,14 +326,11 @@ let list = new List();
list.add(2);
list.add(4);
list.add(5);
list.add(2);
let obj1 = new List();
obj1.add(2);
obj1.add(4);
obj1.add(5);
list.equal(obj1);
let obj2 = {name : "Dylon", age : "13"};
let result = list.equal(obj2);
let obj = new List();
obj.add(2);
obj.add(4);
obj.add(5);
let result = list.equal(obj);
```
### removeByIndex
......@@ -457,11 +453,9 @@ list.add(2);
list.add(4);
list.add(5);
list.add(4);
list.replaceAllElements((value: number, index: number) => {
return value = 2 * value;
});
list.replaceAllElements((value: number, index: number) => {
return value = value - 2;
list.replaceAllElements((value) => {
// Add the user operation logic based on the actual scenario.
return value;
});
```
......@@ -589,9 +583,7 @@ list.add(2);
list.add(4);
list.add(5);
list.add(4);
let result = list.getSubList(2, 4);
let result1 = list.getSubList(4, 3);
let result2 = list.getSubList(2, 6);
let result = list.getSubList(1, 3);
```
### clear
......@@ -659,7 +651,7 @@ list.add(2);
list.add(4);
list.add(5);
list.add(4);
list.set(2, "b");
let result = list.set(2, "b");
```
### convertToArray
......
# @ohos.util.PlainArray (Nonlinear Container PlainArray)
> **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**PlainArray** stores key-value (KV) pairs. Each key must be unique, be of the number type, and have only one value.
**PlainArray** is based on generics and uses a lightweight structure. Keys in the array are searched using binary search and are mapped to values in other arrays.
......@@ -14,6 +11,11 @@ Both **PlainArray** and **[LightWeightMap](js-apis-lightweightmap.md)** are used
This topic uses the following to identify the use of generics:
- T: Type
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```ts
......@@ -21,7 +23,6 @@ import PlainArray from '@ohos.util.PlainArray';
```
## PlainArray
### Attributes
......@@ -118,9 +119,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
```ts
let plainArray = new PlainArray();
plainArray.has(1);
plainArray.add(1, "squirrel");
let result1 = plainArray.has(1);
let result = plainArray.has(1);
```
......
# @ohos.util.Queue (Linear Container Queue)
> **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**Queue** follows the principle of First In First Out (FIFO). It supports insertion of elements at the end and removal from the front of the queue. **Queue** is implemented based on the queue data structure.
Unlike **[Deque](js-apis-deque.md)**, which supports insertion and removal at both the ends, **Queue** supports insertion at one end and removal at the other end.
......@@ -12,6 +9,11 @@ Unlike **[Deque](js-apis-deque.md)**, which supports insertion and removal at bo
This topic uses the following to identify the use of generics:
- T: Type
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```ts
......
# @ohos.util.Stack (Linear Container Stack)
> **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**Stack** is implemented based on the array data structure. It follows the principle Last Out First In (LOFI) and supports data insertion and removal at one end.
Unlike **[Queue](js-apis-queue.md)**, which is implemented based on the queue data structure and supports insertion at one end and removal at the other end, **Stack** supports insertion and removal at the same end.
......@@ -12,6 +9,11 @@ Unlike **[Queue](js-apis-queue.md)**, which is implemented based on the queue da
This topic uses the following to identify the use of generics:
- T: Type
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```ts
......
......@@ -18,6 +18,7 @@ This topic uses the following to identify the use of generics:
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```ts
......@@ -126,9 +127,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
```ts
let treeMap = new TreeMap();
let result = treeMap.hasKey("squirrel");
treeMap.set("squirrel", 123);
let result1 = treeMap.hasKey("squirrel");
let result = treeMap.hasKey("squirrel");
```
......@@ -164,9 +164,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
```ts
let treeMap = new TreeMap();
let result = treeMap.hasValue(123);
treeMap.set("squirrel", 123);
let result1 = treeMap.hasValue(123);
let result = treeMap.hasValue(123);
```
......@@ -304,7 +303,7 @@ let map = new TreeMap();
map.set("demo", 12);
map.setAll(treeMap); // Add all elements in the treeMap to the map.
map.forEach((value, key) => {
console.log("test" + value, key); // Print result: 12 demo, 356 sparrow, and 123 squirrel
console.log("value" + value, "key" + key); // Print result: 12 demo, 356 sparrow, and 123 squirrel
})
```
......@@ -380,7 +379,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
let treeMap = new TreeMap();
treeMap.set("squirrel", 123);
treeMap.set("sparrow", 356);
treeMap.remove("sparrow");
let result = treeMap.remove("sparrow");
```
......
......@@ -14,6 +14,7 @@ This topic uses the following to identify the use of generics:
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```ts
......@@ -122,9 +123,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
```ts
let treeSet = new TreeSet();
treeSet.has(123);
treeSet.add(123);
let result1 = treeSet.has(123);
let result = treeSet.has(123);
```
......
......@@ -145,7 +145,7 @@ Obtains the query string applicable to this URI.
```js
const result = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
result.toString()
let result1 = result.toString();
```
......@@ -205,7 +205,7 @@ Checks whether this URI is the same as another URI object.
```js
const uriInstance = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
const uriInstance1 = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
uriInstance.equalsTo(uriInstance1);
let result = uriInstance.equalsTo(uriInstance1);
```
### checkIsAbsolute
......
......@@ -225,7 +225,7 @@ Checks whether a key has a value.
```js
let urlObject = Url.URL.parseURL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsObject = new Url.URLParams(urlObject.search.slice(1));
paramsObject.has('bard') === true;
let result = paramsObject.has('bard');
```
......@@ -336,7 +336,7 @@ Obtains an ES6 iterator. Each item of the iterator is a JavaScript array, and th
```js
const paramsObject = new Url.URLParams('fod=bay&edg=bap');
for (const [name, value] of paramsObject) {
for (const [name, value] of paramsObject[Symbol.iterator]()) {
console.log(name, value);
}
```
......@@ -460,7 +460,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
```js
let mm = 'https://username:password@host:8080';
let url = Url.URL.parseURL(mm);
url.toString(); // Output 'https://username:password@host:8080/';
let result = url.toString(); // Output 'https://username:password@host:8080/'
```
### tostring
......@@ -481,7 +481,7 @@ Converts the parsed URL into a string.
```js
const url = Url.URL.parseURL('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
url.toString();
let result = url.toString();
```
### toJSON
......@@ -501,7 +501,7 @@ Converts the parsed URL into a JSON string.
**Example**
```js
const url = Url.URL.parseURL('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
url.toJSON();
let result = url.toJSON();
```
## URLSearchParams<sup>(deprecated)</sup>
......
# @ohos.util (util)
The **util** module provides common utility functions, such as **TextEncoder** and **TextDecoder** for string encoding and decoding, **RationalNumber** for rational number operations, **LruBuffer** for buffer management, **Scope** for range determination, **Base64** for Base64 encoding and decoding, and **Types** for checks of built-in object types.
The **util** module provides common utility functions, such as [TextEncoder](#textencoder) and [TextDecoder](#textdecoder) for string encoding and decoding, [RationalNumber<sup>8+</sup>](#rationalnumber8) for rational number operations, [LRUCache<sup>9+</sup>](#lrucache9) for cache management, [ScopeHelper<sup>9+</sup>](#scopehelper9) for range determination, [Base64Helper<sup>9+</sup>](#base64helper9) for Base64 encoding and decoding, and [types<sup>8+</sup>](#types8) for built-in object type check.
> **NOTE**
>
......@@ -337,6 +337,8 @@ Processes an asynchronous function and returns a promise.
## TextDecoder
Provides APIs to decode byte arrays into strings. It supports multiple formats, including UTF-8, UTF-16LE, UTF-16BE, ISO-8859, and Windows-1251.
### Attributes
**System capability**: SystemCapability.Utils.Lang
......@@ -367,15 +369,15 @@ Creates a **TextDecoder** object. It provides the same function as the deprecate
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------ |
| encoding | string | No | Encoding format. |
| encoding | string | No | Encoding format. The default format is **'utf-8'**. |
| options | Object | No | Encoding-related options, which include **fatal** and **ignoreBOM**.|
**Table 1.1** options
| Name | Type| Mandatory| Description |
| --------- | -------- | ---- | ------------------ |
| fatal | boolean | No | Whether to display fatal errors.|
| ignoreBOM | boolean | No | Whether to ignore the BOM. |
| fatal | boolean | No | Whether to display fatal errors. The default value is **false**.|
| ignoreBOM | boolean | No | Whether to ignore the BOM. The default value is **false**. |
**Example**
......@@ -443,15 +445,15 @@ A constructor used to create a **TextDecoder** object.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| encoding | string | No| Encoding format.|
| encoding | string | No| Encoding format. The default format is **'utf-8'**.|
| options | Object | No| Encoding-related options, which include **fatal** and **ignoreBOM**.|
**Table 1** options
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| fatal | boolean | No| Whether to display fatal errors.|
| ignoreBOM | boolean | No| Whether to ignore the BOM.|
| fatal | boolean | No| Whether to display fatal errors. The default value is **false**.|
| ignoreBOM | boolean | No| Whether to ignore the BOM. The default value is **false**.|
**Example**
......@@ -508,13 +510,15 @@ Decodes the input content.
## TextEncoder
Provides APIs to encode strings into byte arrays. It supports multiple formats, including UTF-8, UTF-16LE, and UTF-16BE. When **TextEncoder** is used for encoding, the number of bytes occupied by a character varies according to the encoding format. For example, a Chinese character usually occupies three bytes in UTF-8 encoding format but two bytes in UTF-16LE or UTF-16BE encoding format. Therefore, when using **TextEncoder**, you must explicitly specify the encoding format to obtain the required encoding result.
### Attributes
**System capability**: SystemCapability.Utils.Lang
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| encoding | string | Yes| No| Encoding format. The default format is **utf-8**.|
| encoding | string | Yes| No| Encoding format. The default format is **'utf-8'**.|
### constructor
......@@ -679,6 +683,8 @@ Encodes the input content.
## RationalNumber<sup>8+</sup>
Provides APIs to compare rational numbers and obtain numerators and denominators. For example, the **toString()** API can be used to convert a rational number into a strings.
### constructor<sup>9+</sup>
constructor()
......@@ -1063,6 +1069,8 @@ let result = util.RationalNumber.getCommonDivisor(4,6);
## LRUCache<sup>9+</sup>
Provides APIs to discard the least recently used data to make rooms for new elements when the cache is full. This class uses the Least Recently Used (LRU) algorithm, which believes that the recently used data may be accessed again in the near future and the least accessed data is the least valuable data and should be removed from the cache.
### Attributes
**System capability**: SystemCapability.Utils.Lang
......@@ -1119,7 +1127,7 @@ Changes the **LruCache** capacity. If the new capacity is less than or equal to
```js
let pro = new util.LRUCache();
let result = pro.updateCapacity(100);
pro.updateCapacity(100);
```
......@@ -1668,6 +1676,8 @@ Defines the type of values in a **Scope** object.
## ScopeHelper<sup>9+</sup>
Provides APIs to define the valid range of a field. The constructor of this class creates comparable objects with lower and upper limits.
### constructor<sup>9+</sup>
constructor(lowerObj: ScopeType, upperObj: ScopeType)
......@@ -1954,7 +1964,7 @@ let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let tempMiDF = new Temperature(35);
let range = new util.ScopeHelper(tempLower, tempUpper);
range.contains(tempMiDF);
let result = range.contains(tempMiDF);
```
......@@ -2023,6 +2033,8 @@ let result = range.clamp(tempMiDF);
## Base64Helper<sup>9+</sup>
The Base64 encoding table contains 62 characters, which are the uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), and the special characters plus sign (+) and slash (/). During encoding, the original data is divided into groups of three bytes, and each group contains a 6-bit number. Then, the corresponding characters in the Base64 encoding table are used to represent these numbers. If the last group contains only one or two bytes, the equal sign (=) is used for padding.
### constructor<sup>9+</sup>
constructor()
......@@ -2224,6 +2236,8 @@ that.decode(array).then(val=>{
## types<sup>8+</sup>
Provides APIs to check different types of built-in objects, such as ArrayBuffer, Map, and Set, so as to avoid exceptions or crashes caused by type errors.
### constructor<sup>8+</sup>
constructor()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册