未验证 提交 8a2879ac 编写于 作者: O openharmony_ci 提交者: Gitee

!11779 翻译完成:10993 add containers exception information

Merge pull request !11779 from wusongqing/TR10993
...@@ -40,10 +40,23 @@ A constructor used to create an **ArrayList** instance. ...@@ -40,10 +40,23 @@ A constructor used to create an **ArrayList** instance.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200012 | The ArrayList's constructor cannot be directly invoked. |
**Example** **Example**
```ts ```ts
let arrayList = new ArrayList(); let arrayList = new ArrayList();
try {
let arrayList2 = ArrayList();
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -67,6 +80,14 @@ Adds an element at the end of this container. ...@@ -67,6 +80,14 @@ Adds an element at the end of this container.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the element is added successfully; returns **false** otherwise.| | boolean | Returns **true** if the element is added successfully; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The add method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -76,7 +97,13 @@ Adds an element at the end of this container. ...@@ -76,7 +97,13 @@ Adds an element at the end of this container.
let b = [1, 2, 3]; let b = [1, 2, 3];
let result2 = arrayList.add(b); let result2 = arrayList.add(b);
let c = {name: "Dylon", age: "13"}; let c = {name: "Dylon", age: "13"};
let result3 = arrayList.add(false); let result3 = arrayList.add(c);
let result4 = arrayList.add(false);
try {
arrayList.add.bind({}, "b")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### insert ### insert
...@@ -94,6 +121,15 @@ Inserts an element at the specified position in this container. ...@@ -94,6 +121,15 @@ Inserts an element at the specified position in this container.
| element | T | Yes| Target element.| | element | T | Yes| Target element.|
| index | number | Yes| Index of the position where the element is to be inserted.| | index | number | Yes| Index of the position where the element is to be inserted.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The insert method cannot be bound. |
| 10200001 | The value of parameters are out of range. |
**Example** **Example**
```ts ```ts
...@@ -101,6 +137,21 @@ let arrayList = new ArrayList(); ...@@ -101,6 +137,21 @@ let arrayList = new ArrayList();
arrayList.insert("A", 0); arrayList.insert("A", 0);
arrayList.insert(0, 1); arrayList.insert(0, 1);
arrayList.insert(true, 2); arrayList.insert(true, 2);
try {
arrayList.insert.bind({}, 1, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
try {
let res = arrayList.insert (8, 11); // Trigger an out-of-bounds exception.
} catch (err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
try {
let res = arrayList.insert("a", "b"); // Trigger a type exception.
} catch (err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### has ### has
...@@ -123,6 +174,14 @@ Checks whether this container has the specified element. ...@@ -123,6 +174,14 @@ Checks whether this container has the specified element.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the specified element is contained; returns **false** otherwise.| | boolean | Returns **true** if the specified element is contained; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The has method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -130,6 +189,11 @@ let arrayList = new ArrayList(); ...@@ -130,6 +189,11 @@ let arrayList = new ArrayList();
let result = arrayList.has("squirrel"); let result = arrayList.has("squirrel");
arrayList.add("squirrel"); arrayList.add("squirrel");
let result1 = arrayList.has("squirrel"); let result1 = arrayList.has("squirrel");
try {
arrayList.has.bind({}, "squirrel")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### getIndexOf ### getIndexOf
...@@ -152,6 +216,14 @@ Obtains the index of the first occurrence of the specified element in this conta ...@@ -152,6 +216,14 @@ Obtains the index of the first occurrence of the specified element in this conta
| -------- | -------- | | -------- | -------- |
| number | Returns the position index if obtained; returns **-1** if the specified element is not found.| | number | Returns the position index if obtained; returns **-1** if the specified element is not found.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getIndexOf method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -164,6 +236,11 @@ arrayList.add(1); ...@@ -164,6 +236,11 @@ arrayList.add(1);
arrayList.add(2); arrayList.add(2);
arrayList.add(4); arrayList.add(4);
let result = arrayList.getIndexOf(2); let result = arrayList.getIndexOf(2);
try {
arrayList.getIndexOf.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### getLastIndexOf ### getLastIndexOf
...@@ -186,6 +263,14 @@ Obtains the index of the last occurrence of the specified element in this contai ...@@ -186,6 +263,14 @@ Obtains the index of the last occurrence of the specified element in this contai
| -------- | -------- | | -------- | -------- |
| number | Returns the position index if obtained; returns **-1** if the specified element is not found.| | number | Returns the position index if obtained; returns **-1** if the specified element is not found.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getLastIndexOf method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -198,6 +283,11 @@ arrayList.add(1); ...@@ -198,6 +283,11 @@ arrayList.add(1);
arrayList.add(2); arrayList.add(2);
arrayList.add(4); arrayList.add(4);
let result = arrayList.getLastIndexOf(2); let result = arrayList.getLastIndexOf(2);
try {
arrayList.getLastIndexOf.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### removeByIndex ### removeByIndex
...@@ -220,6 +310,15 @@ Removes an element with the specified position from this container. ...@@ -220,6 +310,15 @@ Removes an element with the specified position from this container.
| -------- | -------- | | -------- | -------- |
| T | Element removed.| | T | Element removed.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The removeByIndex method cannot be bound. |
| 10200001 | The value of parameters are out of range. |
**Example** **Example**
```ts ```ts
...@@ -230,6 +329,21 @@ arrayList.add(5); ...@@ -230,6 +329,21 @@ arrayList.add(5);
arrayList.add(2); arrayList.add(2);
arrayList.add(4); arrayList.add(4);
let result = arrayList.removeByIndex(2); let result = arrayList.removeByIndex(2);
try {
arrayList.removeByIndex.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
try {
arrayList.removeByIndex("a"); // Trigger a type exception.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
try {
arrayList.removeByIndex(8); // Trigger an out-of-bounds exception.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### remove ### remove
...@@ -252,6 +366,14 @@ Removes the first occurrence of the specified element from this container. ...@@ -252,6 +366,14 @@ Removes the first occurrence of the specified element from this container.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the element is removed successfully; returns **false** otherwise.| | boolean | Returns **true** if the element is removed successfully; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The remove method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -261,6 +383,11 @@ arrayList.add(4); ...@@ -261,6 +383,11 @@ arrayList.add(4);
arrayList.add(5); arrayList.add(5);
arrayList.add(4); arrayList.add(4);
let result = arrayList.remove(2); let result = arrayList.remove(2);
try {
arrayList.remove.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### removeByRange ### removeByRange
...@@ -278,6 +405,15 @@ Removes from this container all of the elements within a range, including the el ...@@ -278,6 +405,15 @@ Removes from this container all of the elements within a range, including the el
| fromIndex | number | Yes| Index of the start position.| | fromIndex | number | Yes| Index of the start position.|
| toIndex | number | Yes| Index of the end position.| | toIndex | number | Yes| Index of the end position.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The removeByRange method cannot be bound. |
| 10200001 | The value of parameters are out of range. |
**Example** **Example**
```ts ```ts
...@@ -287,8 +423,16 @@ arrayList.add(4); ...@@ -287,8 +423,16 @@ arrayList.add(4);
arrayList.add(5); arrayList.add(5);
arrayList.add(4); arrayList.add(4);
arrayList.removeByRange(2, 4); arrayList.removeByRange(2, 4);
arrayList.removeByRange(4, 3); try {
arrayList.removeByRange(2, 6); arrayList.removeByRange.bind({}, 2, 4)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
try {
arrayList.removeByRange(8, 4); // Trigger an out-of-bounds exception.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### replaceAllElements ### replaceAllElements
...@@ -315,6 +459,14 @@ callbackfn ...@@ -315,6 +459,14 @@ callbackfn
| index | number | No| Position index of the element that is currently traversed.| | index | number | No| Position index of the element that is currently traversed.|
| arrlist | ArrayList<T> | No| Instance that invokes the **replaceAllElements** method.| | arrlist | ArrayList<T> | No| Instance that invokes the **replaceAllElements** method.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The replaceAllElements method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -329,6 +481,13 @@ arrayList.replaceAllElements((value: number, index: number)=> { ...@@ -329,6 +481,13 @@ arrayList.replaceAllElements((value: number, index: number)=> {
arrayList.replaceAllElements((value: number, index: number) => { arrayList.replaceAllElements((value: number, index: number) => {
return value = value - 2; return value = value - 2;
}); });
try {
arrayList.replaceAllElements.bind({}, (value: number, index: number)=> {
return value = 2 * value;
})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### forEach ### forEach
...@@ -355,6 +514,14 @@ callbackfn ...@@ -355,6 +514,14 @@ callbackfn
| index | number | No| Position index of the element that is currently traversed.| | index | number | No| Position index of the element that is currently traversed.|
| arrlist | ArrayList<T> | No| Instance that invokes the **forEach** method.| | arrlist | ArrayList<T> | No| Instance that invokes the **forEach** method.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The forEach method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -366,6 +533,13 @@ arrayList.add(4); ...@@ -366,6 +533,13 @@ arrayList.add(4);
arrayList.forEach((value, index) => { arrayList.forEach((value, index) => {
console.log(`value:${value}`, index); console.log(`value:${value}`, index);
}); });
try {
arrayList.forEach.bind({}, (value, index) => {
console.log(`value:${value}`, index);
})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### sort ### sort
...@@ -389,6 +563,14 @@ comparator ...@@ -389,6 +563,14 @@ comparator
| firstValue | T | Yes| Previous element.| | firstValue | T | Yes| Previous element.|
| secondValue | T | Yes| Next element.| | secondValue | T | Yes| Next element.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The sort method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -400,6 +582,11 @@ arrayList.add(4); ...@@ -400,6 +582,11 @@ arrayList.add(4);
arrayList.sort((a: number, b: number) => a - b); arrayList.sort((a: number, b: number) => a - b);
arrayList.sort((a: number, b: number) => b - a); arrayList.sort((a: number, b: number) => b - a);
arrayList.sort(); arrayList.sort();
try {
arrayList.sort.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### subArrayList ### subArrayList
...@@ -423,6 +610,15 @@ Obtains elements within a range in this container, including the element at the ...@@ -423,6 +610,15 @@ Obtains elements within a range in this container, including the element at the
| -------- | -------- | | -------- | -------- |
| ArrayList<T> | New **ArrayList** instance obtained.| | ArrayList<T> | New **ArrayList** instance obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The subArrayList method cannot be bound. |
| 10200001 | The value of parameters are out of range. |
**Example** **Example**
```ts ```ts
...@@ -434,6 +630,16 @@ arrayList.add(4); ...@@ -434,6 +630,16 @@ arrayList.add(4);
let result1 = arrayList.subArrayList(2, 4); let result1 = arrayList.subArrayList(2, 4);
let result2 = arrayList.subArrayList(4, 3); let result2 = arrayList.subArrayList(4, 3);
let result3 = arrayList.subArrayList(2, 6); let result3 = arrayList.subArrayList(2, 6);
try {
arrayList.subArrayList.bind({}, 2, 4)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
try {
arrayList.subArrayList(6, 4);
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### clear ### clear
...@@ -444,6 +650,14 @@ Clears this container and sets its length to **0**. ...@@ -444,6 +650,14 @@ Clears this container and sets its length to **0**.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The clear method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -453,6 +667,11 @@ arrayList.add(4); ...@@ -453,6 +667,11 @@ arrayList.add(4);
arrayList.add(5); arrayList.add(5);
arrayList.add(4); arrayList.add(4);
arrayList.clear(); arrayList.clear();
try {
arrayList.clear.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### clone ### clone
...@@ -470,6 +689,14 @@ Clones this container and returns a copy. The modification to the copy does not ...@@ -470,6 +689,14 @@ Clones this container and returns a copy. The modification to the copy does not
| -------- | -------- | | -------- | -------- |
| ArrayList<T> | New **ArrayList** instance obtained.| | ArrayList<T> | New **ArrayList** instance obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The clone method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -479,6 +706,11 @@ arrayList.add(4); ...@@ -479,6 +706,11 @@ arrayList.add(4);
arrayList.add(5); arrayList.add(5);
arrayList.add(4); arrayList.add(4);
let result = arrayList.clone(); let result = arrayList.clone();
try {
arrayList.clone.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### getCapacity ### getCapacity
...@@ -495,6 +727,14 @@ Obtains the capacity of this container. ...@@ -495,6 +727,14 @@ Obtains the capacity of this container.
| -------- | -------- | | -------- | -------- |
| number | Capacity obtained.| | number | Capacity obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getCapacity method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -504,6 +744,11 @@ arrayList.add(4); ...@@ -504,6 +744,11 @@ arrayList.add(4);
arrayList.add(5); arrayList.add(5);
arrayList.add(4); arrayList.add(4);
let result = arrayList.getCapacity(); let result = arrayList.getCapacity();
try {
arrayList.getCapacity.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### convertToArray ### convertToArray
...@@ -520,6 +765,14 @@ Converts this container into an array. ...@@ -520,6 +765,14 @@ Converts this container into an array.
| -------- | -------- | | -------- | -------- |
| Array<T> | Array obtained.| | Array<T> | Array obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The convertToArray method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -529,6 +782,11 @@ arrayList.add(4); ...@@ -529,6 +782,11 @@ arrayList.add(4);
arrayList.add(5); arrayList.add(5);
arrayList.add(4); arrayList.add(4);
let result = arrayList.convertToArray(); let result = arrayList.convertToArray();
try {
arrayList.convertToArray.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### isEmpty ### isEmpty
...@@ -545,6 +803,14 @@ Checks whether this container is empty (contains no element). ...@@ -545,6 +803,14 @@ Checks whether this container is empty (contains no element).
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the container is empty; returns **false** otherwise.| | boolean | Returns **true** if the container is empty; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The isEmpty method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -554,6 +820,11 @@ arrayList.add(4); ...@@ -554,6 +820,11 @@ arrayList.add(4);
arrayList.add(5); arrayList.add(5);
arrayList.add(4); arrayList.add(4);
let result = arrayList.isEmpty(); let result = arrayList.isEmpty();
try {
arrayList.isEmpty.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### increaseCapacityTo ### increaseCapacityTo
...@@ -570,6 +841,14 @@ Increases the capacity of this container. ...@@ -570,6 +841,14 @@ Increases the capacity of this container.
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| newCapacity | number | Yes| New capacity.| | newCapacity | number | Yes| New capacity.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The increaseCapacityTo method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -580,6 +859,11 @@ arrayList.add(5); ...@@ -580,6 +859,11 @@ arrayList.add(5);
arrayList.add(4); arrayList.add(4);
arrayList.increaseCapacityTo(2); arrayList.increaseCapacityTo(2);
arrayList.increaseCapacityTo(8); arrayList.increaseCapacityTo(8);
try {
arrayList.increaseCapacityTo.bind({}, 5)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### trimToCurrentLength ### trimToCurrentLength
...@@ -590,6 +874,14 @@ Trims the capacity of this container to its current length. ...@@ -590,6 +874,14 @@ Trims the capacity of this container to its current length.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The trimToCurrentLength method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -599,6 +891,11 @@ arrayList.add(4); ...@@ -599,6 +891,11 @@ arrayList.add(4);
arrayList.add(5); arrayList.add(5);
arrayList.add(4); arrayList.add(4);
arrayList.trimToCurrentLength(); arrayList.trimToCurrentLength();
try {
arrayList.trimToCurrentLength.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### [Symbol.iterator] ### [Symbol.iterator]
...@@ -615,6 +912,14 @@ Obtains an iterator, each item of which is a JavaScript object. ...@@ -615,6 +912,14 @@ Obtains an iterator, each item of which is a JavaScript object.
| -------- | -------- | | -------- | -------- |
| IterableIterator<T> | Iterator obtained.| | IterableIterator<T> | Iterator obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The Symbol.iterator method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -636,4 +941,9 @@ while(temp != undefined) { ...@@ -636,4 +941,9 @@ while(temp != undefined) {
console.log(`value:${temp}`); console.log(`value:${temp}`);
temp = iter.next().value; temp = iter.next().value;
} }
try {
arrayList[Symbol.iterator].bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -39,10 +39,23 @@ A constructor used to create a **Deque** instance. ...@@ -39,10 +39,23 @@ A constructor used to create a **Deque** instance.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200012 | The Deque's constructor cannot be directly invoked. |
**Example** **Example**
```ts ```ts
let deque = new Deque(); let deque = new Deque();
try {
let deque2 = Deque();
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### insertFront ### insertFront
...@@ -59,6 +72,14 @@ Inserts an element at the front of this container. ...@@ -59,6 +72,14 @@ Inserts an element at the front of this container.
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| element | T | Yes| Target element.| | element | T | Yes| Target element.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The insertFront method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -68,7 +89,13 @@ deque.insertFront(1); ...@@ -68,7 +89,13 @@ deque.insertFront(1);
let b = [1, 2, 3]; let b = [1, 2, 3];
deque.insertFront(b); deque.insertFront(b);
let c = {name : "Dylon", age : "13"}; let c = {name : "Dylon", age : "13"};
deque.insertFront(c);
deque.insertFront(false); deque.insertFront(false);
try {
deque.insertFront.bind({}, "b")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### insertEnd ### insertEnd
...@@ -85,6 +112,14 @@ Inserts an element at the end of this container. ...@@ -85,6 +112,14 @@ Inserts an element at the end of this container.
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| element | T | Yes| Target element.| | element | T | Yes| Target element.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The insertEnd method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -94,7 +129,13 @@ deque.insertEnd(1); ...@@ -94,7 +129,13 @@ deque.insertEnd(1);
let b = [1, 2, 3]; let b = [1, 2, 3];
deque.insertEnd(b); deque.insertEnd(b);
let c = {name : "Dylon", age : "13"}; let c = {name : "Dylon", age : "13"};
deque.insertEnd(c);
deque.insertEnd(false); deque.insertEnd(false);
try {
deque.insertEnd.bind({}, "b")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### has ### has
...@@ -117,6 +158,14 @@ Checks whether this container has the specified element. ...@@ -117,6 +158,14 @@ Checks whether this container has the specified element.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the specified element is contained; returns **false** otherwise.| | boolean | Returns **true** if the specified element is contained; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The has method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -124,6 +173,11 @@ let deque = new Deque(); ...@@ -124,6 +173,11 @@ let deque = new Deque();
let result = deque.has("squirrel"); let result = deque.has("squirrel");
deque.insertFront("squirrel"); deque.insertFront("squirrel");
let result1 = deque.has("squirrel"); let result1 = deque.has("squirrel");
try {
deque.has.bind({}, "b")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### popFirst ### popFirst
...@@ -140,6 +194,14 @@ Removes the first element of this container. ...@@ -140,6 +194,14 @@ Removes the first element of this container.
| -------- | -------- | | -------- | -------- |
| T | Element removed.| | T | Element removed.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The popFirst method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -150,6 +212,11 @@ deque.insertEnd(5); ...@@ -150,6 +212,11 @@ deque.insertEnd(5);
deque.insertFront(2); deque.insertFront(2);
deque.insertFront(4); deque.insertFront(4);
let result = deque.popFirst(); let result = deque.popFirst();
try {
deque.popFirst.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### popLast ### popLast
...@@ -166,6 +233,14 @@ Removes the last element of this container. ...@@ -166,6 +233,14 @@ Removes the last element of this container.
| -------- | -------- | | -------- | -------- |
| T | Element removed.| | T | Element removed.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The popLast method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -176,6 +251,11 @@ deque.insertFront(5); ...@@ -176,6 +251,11 @@ deque.insertFront(5);
deque.insertFront(2); deque.insertFront(2);
deque.insertFront(4); deque.insertFront(4);
let result = deque.popLast(); let result = deque.popLast();
try {
deque.popLast.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### forEach ### forEach
...@@ -202,6 +282,14 @@ callbackfn ...@@ -202,6 +282,14 @@ callbackfn
| index | number | No| Position index of the element that is currently traversed.| | index | number | No| Position index of the element that is currently traversed.|
| deque | Deque<T> | No| Instance that invokes the **forEach** method.| | deque | Deque<T> | No| Instance that invokes the **forEach** method.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The forEach method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -213,6 +301,13 @@ deque.insertEnd(4); ...@@ -213,6 +301,13 @@ deque.insertEnd(4);
deque.forEach((value, index) => { deque.forEach((value, index) => {
console.log("value:" + value, index); console.log("value:" + value, index);
}); });
try {
deque.forEach.bind({}, (value, index) => {
console.log("value:" + value, index);
})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### getFirst ### getFirst
...@@ -229,6 +324,14 @@ Obtains the first element of this container. ...@@ -229,6 +324,14 @@ Obtains the first element of this container.
| -------- | -------- | | -------- | -------- |
| T | Element obtained.| | T | Element obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getFirst method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -238,6 +341,11 @@ deque.insertEnd(4); ...@@ -238,6 +341,11 @@ deque.insertEnd(4);
deque.insertFront(5); deque.insertFront(5);
deque.insertFront(4); deque.insertFront(4);
let result = deque.getFirst(); let result = deque.getFirst();
try {
deque.getFirst.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### getLast ### getLast
...@@ -254,6 +362,14 @@ Obtains the last element of this container. ...@@ -254,6 +362,14 @@ Obtains the last element of this container.
| -------- | -------- | | -------- | -------- |
| T | Element obtained.| | T | Element obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getLast method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -263,6 +379,11 @@ deque.insertFront(4); ...@@ -263,6 +379,11 @@ deque.insertFront(4);
deque.insertFront(5); deque.insertFront(5);
deque.insertFront(4); deque.insertFront(4);
let result = deque.getLast(); let result = deque.getLast();
try {
deque.getLast.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### [Symbol.iterator] ### [Symbol.iterator]
...@@ -279,6 +400,14 @@ Obtains an iterator, each item of which is a JavaScript object. ...@@ -279,6 +400,14 @@ Obtains an iterator, each item of which is a JavaScript object.
| -------- | -------- | | -------- | -------- |
| IterableIterator<T> | Iterator obtained.| | IterableIterator<T> | Iterator obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The Symbol.iterator method cannot be bound. |
**Example** **Example**
```ts ```ts
let deque = new Deque(); let deque = new Deque();
...@@ -299,4 +428,9 @@ while(temp != undefined) { ...@@ -299,4 +428,9 @@ while(temp != undefined) {
console.log("value:" + temp); console.log("value:" + temp);
temp = iter.next().value; temp = iter.next().value;
} }
try {
deque[Symbol.iterator].bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -41,10 +41,23 @@ A constructor used to create a **HashMap** instance. ...@@ -41,10 +41,23 @@ A constructor used to create a **HashMap** instance.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200012 | The HashMap's constructor cannot be directly invoked. |
**Example** **Example**
```ts ```ts
let hashMap = new HashMap(); let hashMap = new HashMap();
try {
let hashMap2 = HashMap();
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -62,11 +75,24 @@ Checks whether this container is empty (contains no element). ...@@ -62,11 +75,24 @@ Checks whether this container is empty (contains no element).
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the container is empty; returns **false** otherwise.| | boolean | Returns **true** if the container is empty; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The isEmpty method cannot be bound. |
**Example** **Example**
```ts ```ts
const hashMap = new HashMap(); const hashMap = new HashMap();
let result = hashMap.isEmpty(); let result = hashMap.isEmpty();
try {
hashMap.isEmpty.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -90,6 +116,14 @@ Checks whether this container contains the specified key. ...@@ -90,6 +116,14 @@ Checks whether this container contains the specified key.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the specified key is contained; returns **false** otherwise.| | boolean | Returns **true** if the specified key is contained; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The hasKey method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -97,6 +131,11 @@ let hashMap = new HashMap(); ...@@ -97,6 +131,11 @@ let hashMap = new HashMap();
let result = hashMap.hasKey("squirrel"); let result = hashMap.hasKey("squirrel");
hashMap.set("squirrel", 123); hashMap.set("squirrel", 123);
let result1 = hashMap.hasKey("squirrel"); let result1 = hashMap.hasKey("squirrel");
try {
hashMap.hasKey.bind({}, "squirrel")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -120,6 +159,14 @@ Checks whether this container contains the specified value. ...@@ -120,6 +159,14 @@ Checks whether this container contains the specified value.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the specified value is contained; returns **false** otherwise.| | boolean | Returns **true** if the specified value is contained; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The hasValue method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -127,6 +174,11 @@ let hashMap = new HashMap(); ...@@ -127,6 +174,11 @@ let hashMap = new HashMap();
let result = hashMap.hasValue(123); let result = hashMap.hasValue(123);
hashMap.set("squirrel", 123); hashMap.set("squirrel", 123);
let result1 = hashMap.hasValue(123); let result1 = hashMap.hasValue(123);
try {
hashMap.hasValue.bind({}, 123)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -150,6 +202,14 @@ Obtains the value of the specified key in this container. ...@@ -150,6 +202,14 @@ Obtains the value of the specified key in this container.
| -------- | -------- | | -------- | -------- |
| V | Value obtained.| | V | Value obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The get method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -157,6 +217,11 @@ let hashMap = new HashMap(); ...@@ -157,6 +217,11 @@ let hashMap = new HashMap();
hashMap.set("squirrel", 123); hashMap.set("squirrel", 123);
hashMap.set("sparrow", 356); hashMap.set("sparrow", 356);
let result = hashMap.get("sparrow"); let result = hashMap.get("sparrow");
try {
hashMap.get.bind({}, "sparrow")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -174,6 +239,14 @@ Adds all elements in a **HashMap** instance to this container. ...@@ -174,6 +239,14 @@ Adds all elements in a **HashMap** instance to this container.
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| map | HashMap<K, V> | Yes| **HashMap** instance whose elements are to be added to the current container.| | map | HashMap<K, V> | Yes| **HashMap** instance whose elements are to be added to the current container.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The setAll method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -182,6 +255,11 @@ hashMap.set("squirrel", 123); ...@@ -182,6 +255,11 @@ hashMap.set("squirrel", 123);
hashMap.set("sparrow", 356); hashMap.set("sparrow", 356);
let newHashMap = new HashMap(); let newHashMap = new HashMap();
hashMap.setAll(newHashMap); hashMap.setAll(newHashMap);
try {
hashMap.setAll.bind({}, newHashMap)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -206,11 +284,24 @@ Adds an element to this container. ...@@ -206,11 +284,24 @@ Adds an element to this container.
| -------- | -------- | | -------- | -------- |
| Object | Container that contains the new element.| | Object | Container that contains the new element.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The set method cannot be bound. |
**Example** **Example**
```ts ```ts
let hashMap = new HashMap(); let hashMap = new HashMap();
let result = hashMap.set("squirrel", 123); let result = hashMap.set("squirrel", 123);
try {
hashMap.set.bind({}, "squirrel", 123)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -234,6 +325,14 @@ Removes an element with the specified key from this container. ...@@ -234,6 +325,14 @@ Removes an element with the specified key from this container.
| -------- | -------- | | -------- | -------- |
| V | Value of the element.| | V | Value of the element.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The remove method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -241,6 +340,11 @@ let hashMap = new HashMap(); ...@@ -241,6 +340,11 @@ let hashMap = new HashMap();
hashMap.set("squirrel", 123); hashMap.set("squirrel", 123);
hashMap.set("sparrow", 356); hashMap.set("sparrow", 356);
let result = hashMap.remove("sparrow"); let result = hashMap.remove("sparrow");
try {
hashMap.remove.bind({}, "sparrow")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -252,6 +356,14 @@ Clears this container and sets its length to **0**. ...@@ -252,6 +356,14 @@ Clears this container and sets its length to **0**.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The clear method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -259,6 +371,11 @@ let hashMap = new HashMap(); ...@@ -259,6 +371,11 @@ let hashMap = new HashMap();
hashMap.set("squirrel", 123); hashMap.set("squirrel", 123);
hashMap.set("sparrow", 356); hashMap.set("sparrow", 356);
hashMap.clear(); hashMap.clear();
try {
hashMap.clear.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -276,6 +393,14 @@ Obtains an iterator that contains all the elements in this container. ...@@ -276,6 +393,14 @@ Obtains an iterator that contains all the elements in this container.
| -------- | -------- | | -------- | -------- |
| IterableIterator&lt;K&gt; | Iterator obtained.| | IterableIterator&lt;K&gt; | Iterator obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The keys method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -288,6 +413,11 @@ while(temp != undefined) { ...@@ -288,6 +413,11 @@ while(temp != undefined) {
console.log("value:" + temp); console.log("value:" + temp);
temp = iter.next().value; temp = iter.next().value;
} }
try {
hashMap.keys.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -305,6 +435,14 @@ Obtains an iterator that contains all the values in this container. ...@@ -305,6 +435,14 @@ Obtains an iterator that contains all the values in this container.
| -------- | -------- | | -------- | -------- |
| IterableIterator&lt;V&gt; | Iterator obtained.| | IterableIterator&lt;V&gt; | Iterator obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The values method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -317,6 +455,11 @@ while(temp != undefined) { ...@@ -317,6 +455,11 @@ while(temp != undefined) {
console.log("value:" + temp); console.log("value:" + temp);
temp = iter.next().value; temp = iter.next().value;
} }
try {
hashMap.values.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -341,12 +484,25 @@ Replaces an element in this container. ...@@ -341,12 +484,25 @@ Replaces an element in this container.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the element is replaced successfully; returns **false** otherwise.| | boolean | Returns **true** if the element is replaced successfully; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The replace method cannot be bound. |
**Example** **Example**
```ts ```ts
let hashMap = new HashMap(); let hashMap = new HashMap();
hashMap.set("sparrow", 123); hashMap.set("sparrow", 123);
let result = hashMap.replace("sparrow", 357); let result = hashMap.replace("sparrow", 357);
try {
hashMap.replace.bind({}, "sparrow", 357)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -372,6 +528,14 @@ callbackfn ...@@ -372,6 +528,14 @@ callbackfn
| key | K | No| Key of the element that is currently traversed.| | key | K | No| Key of the element that is currently traversed.|
| map | HashMap<K, V> | No| Instance that invokes the **forEach** method.| | map | HashMap<K, V> | No| Instance that invokes the **forEach** method.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The forEach method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -381,6 +545,13 @@ hashMap.set("gull", 357); ...@@ -381,6 +545,13 @@ hashMap.set("gull", 357);
hashMap.forEach((value, key) => { hashMap.forEach((value, key) => {
console.log("value:" + value, key); console.log("value:" + value, key);
}); });
try {
hashMap.forEach.bind({}, (value, key) => {
console.log("value:" + value, key);
})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -398,6 +569,14 @@ Obtains an iterator that contains all the elements in this container. ...@@ -398,6 +569,14 @@ Obtains an iterator that contains all the elements in this container.
| -------- | -------- | | -------- | -------- |
| IterableIterator&lt;[K, V]&gt; | Iterator obtained.| | IterableIterator&lt;[K, V]&gt; | Iterator obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The entries method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -411,6 +590,11 @@ while(temp != undefined) { ...@@ -411,6 +590,11 @@ while(temp != undefined) {
console.log("value:" + temp[1]); console.log("value:" + temp[1]);
temp = iter.next().value; temp = iter.next().value;
} }
try {
hashMap.entries.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -428,6 +612,14 @@ Obtains an iterator, each item of which is a JavaScript object. ...@@ -428,6 +612,14 @@ Obtains an iterator, each item of which is a JavaScript object.
| -------- | -------- | | -------- | -------- |
| IterableIterator&lt;[K, V]&gt; | Iterator obtained.| | IterableIterator&lt;[K, V]&gt; | Iterator obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The Symbol.iterator method cannot be bound. |
**Example** **Example**
```ts ```ts
let hashMap = new HashMap(); let hashMap = new HashMap();
...@@ -448,4 +640,9 @@ while(temp != undefined) { ...@@ -448,4 +640,9 @@ while(temp != undefined) {
console.log("value:" + temp[1]); console.log("value:" + temp[1]);
temp = iter.next().value; temp = iter.next().value;
} }
try {
hashMap[Symbol.iterator].bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -49,10 +49,23 @@ A constructor used to create a **HashSet** instance. ...@@ -49,10 +49,23 @@ A constructor used to create a **HashSet** instance.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200012 | The HashSet's constructor cannot be directly invoked. |
**Example** **Example**
```ts ```ts
let hashSet = new HashSet(); let hashSet = new HashSet();
try {
let hashSet2 = HashSet();
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -70,11 +83,24 @@ Checks whether this container is empty (contains no element). ...@@ -70,11 +83,24 @@ Checks whether this container is empty (contains no element).
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the container is empty; returns **false** otherwise.| | boolean | Returns **true** if the container is empty; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The isEmpty method cannot be bound. |
**Example** **Example**
```ts ```ts
const hashSet = new HashSet(); const hashSet = new HashSet();
let result = hashSet.isEmpty(); let result = hashSet.isEmpty();
try {
hashSet.isEmpty.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -98,6 +124,14 @@ Checks whether this container contains the specified element. ...@@ -98,6 +124,14 @@ Checks whether this container contains the specified element.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the specified element is contained; returns **false** otherwise.| | boolean | Returns **true** if the specified element is contained; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The has method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -105,6 +139,11 @@ let hashSet = new HashSet(); ...@@ -105,6 +139,11 @@ let hashSet = new HashSet();
let result = hashSet.has("squirrel"); let result = hashSet.has("squirrel");
hashSet.add("squirrel"); hashSet.add("squirrel");
let result1 = hashSet.has("squirrel"); let result1 = hashSet.has("squirrel");
try {
hashSet.has.bind({}, "squirrel")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -128,11 +167,24 @@ Adds an element to this container. ...@@ -128,11 +167,24 @@ Adds an element to this container.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the element is added successfully; returns **false** otherwise.| | boolean | Returns **true** if the element is added successfully; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The add method cannot be bound. |
**Example** **Example**
```ts ```ts
let hashSet = new HashSet(); let hashSet = new HashSet();
let result = hashSet.add("squirrel"); let result = hashSet.add("squirrel");
try {
hashSet.add.bind({}, "squirrel")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -156,6 +208,14 @@ Removes an element from this container. ...@@ -156,6 +208,14 @@ Removes an element from this container.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the element is removed successfully; returns **false** otherwise.| | boolean | Returns **true** if the element is removed successfully; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The remove method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -163,6 +223,11 @@ let hashSet = new HashSet(); ...@@ -163,6 +223,11 @@ let hashSet = new HashSet();
hashSet.add("squirrel"); hashSet.add("squirrel");
hashSet.add("sparrow"); hashSet.add("sparrow");
let result = hashSet.remove("sparrow"); let result = hashSet.remove("sparrow");
try {
hashSet.remove.bind({}, "sparrow")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -174,6 +239,14 @@ Clears this container and sets its length to **0**. ...@@ -174,6 +239,14 @@ Clears this container and sets its length to **0**.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The clear method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -181,6 +254,11 @@ let hashSet = new HashSet(); ...@@ -181,6 +254,11 @@ let hashSet = new HashSet();
hashSet.add("squirrel"); hashSet.add("squirrel");
hashSet.add("sparrow"); hashSet.add("sparrow");
hashSet.clear(); hashSet.clear();
try {
hashSet.remove.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -198,6 +276,14 @@ Obtains an iterator that contains all the values in this container. ...@@ -198,6 +276,14 @@ Obtains an iterator that contains all the values in this container.
| -------- | -------- | | -------- | -------- |
| IterableIterator&lt;T&gt; | Iterator obtained.| | IterableIterator&lt;T&gt; | Iterator obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The values method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -209,7 +295,12 @@ let temp = iter.next().value; ...@@ -209,7 +295,12 @@ let temp = iter.next().value;
while(temp != undefined) { while(temp != undefined) {
console.log("value:" + temp); console.log("value:" + temp);
temp = iter.next().value; temp = iter.next().value;
} }
try {
hashSet.values.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -235,6 +326,14 @@ callbackfn ...@@ -235,6 +326,14 @@ callbackfn
| key | T | No| Key of the element that is currently traversed (same as **value**).| | key | T | No| Key of the element that is currently traversed (same as **value**).|
| set | HashSet&lt;T&gt; | No| Instance that invokes the **forEach** method.| | set | HashSet&lt;T&gt; | No| Instance that invokes the **forEach** method.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The forEach method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -244,6 +343,13 @@ hashSet.add("squirrel"); ...@@ -244,6 +343,13 @@ hashSet.add("squirrel");
hashSet.forEach((value, key) => { hashSet.forEach((value, key) => {
console.log("value:" + value, key); console.log("value:" + value, key);
}); });
try {
hashSet.forEach.bind({}, (value, key) => {
console.log("value:" + value, key);
})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -260,6 +366,14 @@ Obtains an iterator that contains all the elements in this container. ...@@ -260,6 +366,14 @@ Obtains an iterator that contains all the elements in this container.
| -------- | -------- | | -------- | -------- |
| IterableIterator<[T, T]> | Iterator obtained.| | IterableIterator<[T, T]> | Iterator obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The entries method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -273,6 +387,11 @@ while(temp != undefined) { ...@@ -273,6 +387,11 @@ while(temp != undefined) {
console.log("value:" + temp[1]); console.log("value:" + temp[1]);
temp = iter.next().value; temp = iter.next().value;
} }
try {
hashSet.entries.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -290,6 +409,14 @@ Obtains an iterator, each item of which is a JavaScript object. ...@@ -290,6 +409,14 @@ Obtains an iterator, each item of which is a JavaScript object.
| -------- | -------- | | -------- | -------- |
| IterableIterator&lt;T&gt; | Iterator obtained.| | IterableIterator&lt;T&gt; | Iterator obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The Symbol.iterator method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -309,4 +436,9 @@ while(temp != undefined) { ...@@ -309,4 +436,9 @@ while(temp != undefined) {
console.log("value: " + temp); console.log("value: " + temp);
temp = iter.next().value; temp = iter.next().value;
} }
try {
hashSet[Symbol.iterator].bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -44,10 +44,23 @@ A constructor used to create a **LightWeightSet** instance. ...@@ -44,10 +44,23 @@ A constructor used to create a **LightWeightSet** instance.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200012 | The LightWeightSet's constructor cannot be directly invoked. |
**Example** **Example**
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
try {
let lightWeightSet2 = LightWeightSet();
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -65,11 +78,24 @@ Checks whether this container is empty (contains no element). ...@@ -65,11 +78,24 @@ Checks whether this container is empty (contains no element).
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the container is empty; returns **false** otherwise.| | boolean | Returns **true** if the container is empty; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The isEmpty method cannot be bound. |
**Example** **Example**
```ts ```ts
const lightWeightSet = new LightWeightSet(); const lightWeightSet = new LightWeightSet();
let result = lightWeightSet.isEmpty(); let result = lightWeightSet.isEmpty();
try {
lightWeightSet.isEmpty.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### add ### add
...@@ -92,11 +118,24 @@ Adds an element to this container. ...@@ -92,11 +118,24 @@ Adds an element to this container.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the element is added successfully; returns **false** otherwise.| | boolean | Returns **true** if the element is added successfully; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The add method cannot be bound. |
**Example** **Example**
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
let result = lightWeightSet.add("squirrel"); let result = lightWeightSet.add("squirrel");
try {
lightWeightSet.add.bind({}, "squirrel")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -114,6 +153,14 @@ Adds all elements in a **LightWeightSet** instance to this container. ...@@ -114,6 +153,14 @@ Adds all elements in a **LightWeightSet** instance to this container.
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| set | LightWeightSet&lt;T&gt; | Yes| **LightWeightSet** instance whose elements are to be added to the current container.| | set | LightWeightSet&lt;T&gt; | Yes| **LightWeightSet** instance whose elements are to be added to the current container.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The addAll method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -123,6 +170,11 @@ lightWeightSet.add("sparrow"); ...@@ -123,6 +170,11 @@ lightWeightSet.add("sparrow");
let set = new LightWeightSet(); let set = new LightWeightSet();
set.add("gull"); set.add("gull");
let result = lightWeightSet.addAll(set); let result = lightWeightSet.addAll(set);
try {
lightWeightSet.addAll.bind({}, set)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -146,6 +198,14 @@ Checks whether this container contains all elements of the specified **LightWeig ...@@ -146,6 +198,14 @@ Checks whether this container contains all elements of the specified **LightWeig
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if all the elements in the specified **LightWeightSet** instance are contained; returns **false** otherwise.| | boolean | Returns **true** if all the elements in the specified **LightWeightSet** instance are contained; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The hasAll method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -155,6 +215,11 @@ lightWeightSet.add("sparrow"); ...@@ -155,6 +215,11 @@ lightWeightSet.add("sparrow");
let set = new LightWeightSet(); let set = new LightWeightSet();
set.add("sparrow"); set.add("sparrow");
let result = lightWeightSet.hasAll(set); let result = lightWeightSet.hasAll(set);
try {
lightWeightSet.hasAll.bind({}, set)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -178,6 +243,14 @@ Checks whether this container has the specified key. ...@@ -178,6 +243,14 @@ Checks whether this container has the specified key.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the specified key is contained; returns **false** otherwise.| | boolean | Returns **true** if the specified key is contained; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The has method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -185,6 +258,11 @@ let lightWeightSet = new LightWeightSet(); ...@@ -185,6 +258,11 @@ let lightWeightSet = new LightWeightSet();
let result = lightWeightSet.has(123); let result = lightWeightSet.has(123);
lightWeightSet.add(123); lightWeightSet.add(123);
result = lightWeightSet.has(123); result = lightWeightSet.has(123);
try {
lightWeightSet.has.bind({}, 123)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -208,6 +286,14 @@ Checks whether this container contains objects of the same type as the specified ...@@ -208,6 +286,14 @@ Checks whether this container contains objects of the same type as the specified
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the container contains objects of the same type as the specified **obj**; returns **false** otherwise.| | boolean | Returns **true** if the container contains objects of the same type as the specified **obj**; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The equal method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -216,6 +302,11 @@ lightWeightSet.add("squirrel"); ...@@ -216,6 +302,11 @@ lightWeightSet.add("squirrel");
lightWeightSet.add("sparrow"); lightWeightSet.add("sparrow");
let obj = ["squirrel", "sparrow"]; let obj = ["squirrel", "sparrow"];
let result = lightWeightSet.equal(obj); let result = lightWeightSet.equal(obj);
try {
lightWeightSet.equal.bind({}, obj)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -233,11 +324,30 @@ Increases the capacity of this container. ...@@ -233,11 +324,30 @@ Increases the capacity of this container.
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| minimumCapacity | number | Yes| Minimum number of elements to accommodate in the container.| | minimumCapacity | number | Yes| Minimum number of elements to accommodate in the container.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The increaseCapacityTo method cannot be bound. |
| 10200001 | The value of parameters are out of range. |
**Example** **Example**
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
lightWeightSet.increaseCapacityTo(10); lightWeightSet.increaseCapacityTo(10);
try {
lightWeightSet.increaseCapacityTo.bind({}, 10)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
try {
lightWeightSet.increaseCapacityTo(2);
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -261,6 +371,14 @@ Obtains the position index of the element with the specified key in this contain ...@@ -261,6 +371,14 @@ Obtains the position index of the element with the specified key in this contain
| -------- | -------- | | -------- | -------- |
| number | Position index of the element.| | number | Position index of the element.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getIndexOf method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -268,6 +386,11 @@ let lightWeightSet = new LightWeightSet(); ...@@ -268,6 +386,11 @@ let lightWeightSet = new LightWeightSet();
lightWeightSet.add("squirrel"); lightWeightSet.add("squirrel");
lightWeightSet.add("sparrow"); lightWeightSet.add("sparrow");
let result = lightWeightSet.getIndexOf("sparrow"); let result = lightWeightSet.getIndexOf("sparrow");
try {
lightWeightSet.getIndexOf.bind({}, "sparrow")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -291,6 +414,14 @@ Removes an element of the specified key from this container. ...@@ -291,6 +414,14 @@ Removes an element of the specified key from this container.
| -------- | -------- | | -------- | -------- |
| T | Value of the element removed.| | T | Value of the element removed.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The remove method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -298,6 +429,11 @@ let lightWeightSet = new LightWeightSet(); ...@@ -298,6 +429,11 @@ let lightWeightSet = new LightWeightSet();
lightWeightSet.add("squirrel"); lightWeightSet.add("squirrel");
lightWeightSet.add("sparrow"); lightWeightSet.add("sparrow");
let result = lightWeightSet.remove("sparrow"); let result = lightWeightSet.remove("sparrow");
try {
lightWeightSet.remove.bind({}, "sparrow")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -321,6 +457,14 @@ Removes the element at the specified position from this container. ...@@ -321,6 +457,14 @@ Removes the element at the specified position from this container.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the element is removed successfully; returns **false** otherwise.| | boolean | Returns **true** if the element is removed successfully; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The removeAt method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -328,6 +472,11 @@ let lightWeightSet = new LightWeightSet(); ...@@ -328,6 +472,11 @@ let lightWeightSet = new LightWeightSet();
lightWeightSet.add("squirrel"); lightWeightSet.add("squirrel");
lightWeightSet.add("sparrow"); lightWeightSet.add("sparrow");
let result = lightWeightSet.removeAt(1); let result = lightWeightSet.removeAt(1);
try {
lightWeightSet.removeAt.bind({}, 1)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -351,6 +500,14 @@ Obtains the value of the element at the specified position in this container. ...@@ -351,6 +500,14 @@ Obtains the value of the element at the specified position in this container.
| -------- | -------- | | -------- | -------- |
| T | Value obtained.| | T | Value obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getValueAt method cannot be bound. |
**Parameters** **Parameters**
```ts ```ts
...@@ -358,6 +515,11 @@ let lightWeightSet = new LightWeightSet(); ...@@ -358,6 +515,11 @@ let lightWeightSet = new LightWeightSet();
lightWeightSet.add("squirrel"); lightWeightSet.add("squirrel");
lightWeightSet.add("sparrow"); lightWeightSet.add("sparrow");
let result = lightWeightSet.getValueAt(1); let result = lightWeightSet.getValueAt(1);
try {
lightWeightSet.getValueAt.bind({}, 1)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -369,6 +531,14 @@ Clears this container and sets its length to **0**. ...@@ -369,6 +531,14 @@ Clears this container and sets its length to **0**.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The clear method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -376,6 +546,11 @@ let lightWeightSet = new LightWeightSet(); ...@@ -376,6 +546,11 @@ let lightWeightSet = new LightWeightSet();
lightWeightSet.add("squirrel"); lightWeightSet.add("squirrel");
lightWeightSet.add("sparrow"); lightWeightSet.add("sparrow");
lightWeightSet.clear(); lightWeightSet.clear();
try {
lightWeightSet.clear.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -393,6 +568,14 @@ Obtains a string that contains all elements in this container. ...@@ -393,6 +568,14 @@ Obtains a string that contains all elements in this container.
| -------- | -------- | | -------- | -------- |
| String | String obtained.| | String | String obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The toString method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -400,6 +583,11 @@ let lightWeightSet = new LightWeightSet(); ...@@ -400,6 +583,11 @@ let lightWeightSet = new LightWeightSet();
lightWeightSet.add("squirrel"); lightWeightSet.add("squirrel");
lightWeightSet.add("sparrow"); lightWeightSet.add("sparrow");
let result = lightWeightSet.toString(); let result = lightWeightSet.toString();
try {
lightWeightSet.toString.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -417,6 +605,14 @@ Obtains an array that contains all objects in this container. ...@@ -417,6 +605,14 @@ Obtains an array that contains all objects in this container.
| -------- | -------- | | -------- | -------- |
| Array&lt;T&gt; | Array obtained.| | Array&lt;T&gt; | Array obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The toArray method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -424,6 +620,11 @@ let lightWeightSet = new LightWeightSet(); ...@@ -424,6 +620,11 @@ let lightWeightSet = new LightWeightSet();
lightWeightSet.add("squirrel"); lightWeightSet.add("squirrel");
lightWeightSet.add("sparrow"); lightWeightSet.add("sparrow");
let result = lightWeightSet.toArray(); let result = lightWeightSet.toArray();
try {
lightWeightSet.toArray.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -441,6 +642,14 @@ Obtains an iterator that contains all the values in this container. ...@@ -441,6 +642,14 @@ Obtains an iterator that contains all the values in this container.
| -------- | -------- | | -------- | -------- |
| IterableIterator&lt;T&gt; | Iterator obtained.| | IterableIterator&lt;T&gt; | Iterator obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The values method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -453,6 +662,11 @@ while(index < lightWeightSet.length) { ...@@ -453,6 +662,11 @@ while(index < lightWeightSet.length) {
console.log(JSON.stringify(iter.next().value)); console.log(JSON.stringify(iter.next().value));
index++; index++;
} }
try {
lightWeightSet.values.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -478,6 +692,14 @@ callbackfn ...@@ -478,6 +692,14 @@ callbackfn
| key| T | No| Key of the element that is currently traversed (same as **value**).| | key| T | No| Key of the element that is currently traversed (same as **value**).|
| set | LightWeightSet&lt;T&gt; | No| Instance that invokes the **forEach** method.| | set | LightWeightSet&lt;T&gt; | No| Instance that invokes the **forEach** method.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The forEach method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -487,6 +709,13 @@ lightWeightSet.add("gull"); ...@@ -487,6 +709,13 @@ lightWeightSet.add("gull");
lightWeightSet.forEach((value, key) => { lightWeightSet.forEach((value, key) => {
console.log("value:" + value, key); console.log("value:" + value, key);
}); });
try {
lightWeightSet.forEach.bind({}, (value, key) => {
console.log("value:" + value, key);
})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -504,6 +733,14 @@ Obtains an iterator that contains all the elements in this container. ...@@ -504,6 +733,14 @@ Obtains an iterator that contains all the elements in this container.
| -------- | -------- | | -------- | -------- |
| IterableIterator<[T, T]> | Iterator obtained.| | IterableIterator<[T, T]> | Iterator obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The entries method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -516,6 +753,11 @@ while(index < lightWeightSet.length) { ...@@ -516,6 +753,11 @@ while(index < lightWeightSet.length) {
console.log(JSON.stringify(iter.next().value)); console.log(JSON.stringify(iter.next().value));
index++; index++;
} }
try {
lightWeightSet.entries.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -533,6 +775,14 @@ Obtains an iterator, each item of which is a JavaScript object. ...@@ -533,6 +775,14 @@ Obtains an iterator, each item of which is a JavaScript object.
| -------- | -------- | | -------- | -------- |
| IterableIterator&lt;T&gt; | Iterator obtained.| | IterableIterator&lt;T&gt; | Iterator obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The Symbol.iterator method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -552,4 +802,9 @@ while(temp != undefined) { ...@@ -552,4 +802,9 @@ while(temp != undefined) {
console.log("value:" + temp); console.log("value:" + temp);
temp = iter.next().value; temp = iter.next().value;
} }
try {
lightWeightSet[Symbol.iterator].bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -43,11 +43,24 @@ A constructor used to create a **LinkedList** instance. ...@@ -43,11 +43,24 @@ A constructor used to create a **LinkedList** instance.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200012 | The LinkedList's constructor cannot be directly invoked. |
**Example** **Example**
```ts ```ts
let linkedList = new LinkedList(); let linkedList = new LinkedList();
try {
let linkedList2 = LinkedList();
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -71,6 +84,14 @@ Adds an element at the end of this container. ...@@ -71,6 +84,14 @@ Adds an element at the end of this container.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the element is added successfully; returns **false** otherwise.| | boolean | Returns **true** if the element is added successfully; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The add method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -78,9 +99,15 @@ let linkedList = new LinkedList(); ...@@ -78,9 +99,15 @@ let linkedList = new LinkedList();
let result = linkedList.add("a"); let result = linkedList.add("a");
let result1 = linkedList.add(1); let result1 = linkedList.add(1);
let b = [1, 2, 3]; let b = [1, 2, 3];
linkedList.add(b); let result2 = linkedList.add(b);
let c = {name : "Dylon", age : "13"}; let c = {name : "Dylon", age : "13"};
let result3 = linkedList.add(false); let result3 = linkedList.add(c);
let result4 = linkedList.add(false);
try {
linkedList.add.bind({}, "b")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### addFirst ### addFirst
...@@ -97,6 +124,14 @@ Adds an element at the top of this container. ...@@ -97,6 +124,14 @@ Adds an element at the top of this container.
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| element | T | Yes| Target element.| | element | T | Yes| Target element.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The addFirst method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -106,7 +141,13 @@ linkedList.addFirst(1); ...@@ -106,7 +141,13 @@ linkedList.addFirst(1);
let b = [1, 2, 3]; let b = [1, 2, 3];
linkedList.addFirst(b); linkedList.addFirst(b);
let c = {name : "Dylon", age : "13"}; let c = {name : "Dylon", age : "13"};
linkedList.addFirst(c);
linkedList.addFirst(false); linkedList.addFirst(false);
try {
linkedList.addFirst.bind({}, "b")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### insert ### insert
...@@ -124,6 +165,15 @@ Inserts an element at the specified position in this container. ...@@ -124,6 +165,15 @@ Inserts an element at the specified position in this container.
| element | T | Yes| Target element.| | element | T | Yes| Target element.|
| index | number | Yes| Index of the position where the element is to be inserted.| | index | number | Yes| Index of the position where the element is to be inserted.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The insert method cannot be bound. |
| 10200001 | The value of parameters are out of range. |
**Example** **Example**
```ts ```ts
...@@ -131,6 +181,16 @@ let linkedList = new LinkedList(); ...@@ -131,6 +181,16 @@ let linkedList = new LinkedList();
linkedList.insert(0, "A"); linkedList.insert(0, "A");
linkedList.insert(1, 0); linkedList.insert(1, 0);
linkedList.insert(2, true); linkedList.insert(2, true);
try {
linkedList.insert.bind({}, 3, "b")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
try {
linkedList.insert(6, "b");
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### has ### has
...@@ -153,6 +213,14 @@ Checks whether this container has the specified element. ...@@ -153,6 +213,14 @@ Checks whether this container has the specified element.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the specified element is contained; returns **false** otherwise.| | boolean | Returns **true** if the specified element is contained; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The has method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -160,6 +228,11 @@ let linkedList = new LinkedList(); ...@@ -160,6 +228,11 @@ let linkedList = new LinkedList();
let result1 = linkedList.has("squirrel"); let result1 = linkedList.has("squirrel");
linkedList.add("squirrel"); linkedList.add("squirrel");
let result = linkedList.has("squirrel"); let result = linkedList.has("squirrel");
try {
linkedList.has.bind({}, "squirrel")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### get ### get
...@@ -182,6 +255,14 @@ Obtains an element at the specified position in this container. ...@@ -182,6 +255,14 @@ Obtains an element at the specified position in this container.
| -------- | -------- | | -------- | -------- |
| T | Element obtained.| | T | Element obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The get method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -194,6 +275,11 @@ linkedList.add(1); ...@@ -194,6 +275,11 @@ linkedList.add(1);
linkedList.add(2); linkedList.add(2);
linkedList.add(4); linkedList.add(4);
let result = linkedList.get(2); let result = linkedList.get(2);
try {
linkedList.get.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### getLastIndexOf ### getLastIndexOf
...@@ -216,6 +302,14 @@ Obtains the index of the last occurrence of the specified element in this contai ...@@ -216,6 +302,14 @@ Obtains the index of the last occurrence of the specified element in this contai
| -------- | -------- | | -------- | -------- |
| number | Returns the position index if obtained; returns **-1** otherwise.| | number | Returns the position index if obtained; returns **-1** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getLastIndexOf method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -228,6 +322,11 @@ linkedList.add(1); ...@@ -228,6 +322,11 @@ linkedList.add(1);
linkedList.add(2); linkedList.add(2);
linkedList.add(4); linkedList.add(4);
let result = linkedList.getLastIndexOf(2); let result = linkedList.getLastIndexOf(2);
try {
linkedList.getLastIndexOf.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### getIndexOf ### getIndexOf
...@@ -250,6 +349,14 @@ Obtains the index of the first occurrence of the specified element in this conta ...@@ -250,6 +349,14 @@ Obtains the index of the first occurrence of the specified element in this conta
| -------- | -------- | | -------- | -------- |
| number | Returns the position index if obtained; returns **-1** otherwise.| | number | Returns the position index if obtained; returns **-1** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getIndexOf method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -262,6 +369,11 @@ linkedList.add(1); ...@@ -262,6 +369,11 @@ linkedList.add(1);
linkedList.add(2); linkedList.add(2);
linkedList.add(4); linkedList.add(4);
let result = linkedList.getIndexOf(2); let result = linkedList.getIndexOf(2);
try {
linkedList.getIndexOf.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### removeByIndex ### removeByIndex
...@@ -284,6 +396,15 @@ Removes an element at the specified position from this container. ...@@ -284,6 +396,15 @@ Removes an element at the specified position from this container.
| -------- | -------- | | -------- | -------- |
| T | Element removed.| | T | Element removed.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The removeByIndex method cannot be bound. |
| 10200001 | The value of parameters are out of range. |
**Example** **Example**
```ts ```ts
...@@ -294,6 +415,16 @@ linkedList.add(5); ...@@ -294,6 +415,16 @@ linkedList.add(5);
linkedList.add(2); linkedList.add(2);
linkedList.add(4); linkedList.add(4);
let result = linkedList.removeByIndex(2); let result = linkedList.removeByIndex(2);
try {
linkedList.removeByIndex.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
try {
linkedList.removeByIndex(8);
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### removeFirst ### removeFirst
...@@ -310,16 +441,35 @@ Removes the first element from this container. ...@@ -310,16 +441,35 @@ Removes the first element from this container.
| -------- | -------- | | -------- | -------- |
| T | Element removed.| | T | Element removed.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The removeFirst method cannot be bound. |
| 10200010 | Container is empty. |
**Example** **Example**
```ts ```ts
let linkedList = new LinkedList(); let linkedList = new LinkedList();
try {
linkedList.removeFirst();
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
linkedList.add(2); linkedList.add(2);
linkedList.add(4); linkedList.add(4);
linkedList.add(5); linkedList.add(5);
linkedList.add(2); linkedList.add(2);
linkedList.add(4); linkedList.add(4);
let result = linkedList.removeFirst(); let result = linkedList.removeFirst();
try {
linkedList.removeFirst.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### removeLast ### removeLast
...@@ -336,16 +486,35 @@ Removes the last element from this container. ...@@ -336,16 +486,35 @@ Removes the last element from this container.
| -------- | -------- | | -------- | -------- |
| T | Element removed.| | T | Element removed.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The removeLast method cannot be bound. |
| 10200010 | Container is empty. |
**Example** **Example**
```ts ```ts
let linkedList = new LinkedList(); let linkedList = new LinkedList();
try {
linkedList.removeLast();
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
linkedList.add(2); linkedList.add(2);
linkedList.add(4); linkedList.add(4);
linkedList.add(5); linkedList.add(5);
linkedList.add(2); linkedList.add(2);
linkedList.add(4); linkedList.add(4);
let result = linkedList.removeLast(); let result = linkedList.removeLast();
try {
linkedList.removeLast.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### remove ### remove
...@@ -368,6 +537,14 @@ Removes the first occurrence of the specified element from this container. ...@@ -368,6 +537,14 @@ Removes the first occurrence of the specified element from this container.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the element is removed successfully; returns **false** otherwise.| | boolean | Returns **true** if the element is removed successfully; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The remove method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -377,6 +554,11 @@ linkedList.add(4); ...@@ -377,6 +554,11 @@ linkedList.add(4);
linkedList.add(5); linkedList.add(5);
linkedList.add(4); linkedList.add(4);
let result = linkedList.remove(2); let result = linkedList.remove(2);
try {
linkedList.remove.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### removeFirstFound ### removeFirstFound
...@@ -399,15 +581,34 @@ Removes the first occurrence of the specified element from this container. ...@@ -399,15 +581,34 @@ Removes the first occurrence of the specified element from this container.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the element is removed successfully; returns **false** otherwise.| | boolean | Returns **true** if the element is removed successfully; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The removeFirstFound method cannot be bound. |
| 10200010 | Container is empty. |
**Example** **Example**
```ts ```ts
let linkedList = new LinkedList(); let linkedList = new LinkedList();
try {
linkedList.removeFirstFound(4);
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
linkedList.add(2); linkedList.add(2);
linkedList.add(4); linkedList.add(4);
linkedList.add(5); linkedList.add(5);
linkedList.add(4); linkedList.add(4);
let result = linkedList.removeFirstFound(4); let result = linkedList.removeFirstFound(4);
try {
linkedList.removeFirstFound.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### removeLastFound ### removeLastFound
...@@ -430,15 +631,34 @@ Removes the last occurrence of the specified element from this container. ...@@ -430,15 +631,34 @@ Removes the last occurrence of the specified element from this container.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the element is removed successfully; returns **false** otherwise.| | boolean | Returns **true** if the element is removed successfully; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The removeLastFound method cannot be bound. |
| 10200010 | Container is empty. |
**Example** **Example**
```ts ```ts
let linkedList = new LinkedList(); let linkedList = new LinkedList();
try {
linkedList.removeLastFound();
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
linkedList.add(2); linkedList.add(2);
linkedList.add(4); linkedList.add(4);
linkedList.add(5); linkedList.add(5);
linkedList.add(4); linkedList.add(4);
let result = linkedList.removeLastFound(4); let result = linkedList.removeLastFound(4);
try {
linkedList.removeLastFound.bind({}, 4)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### clone ### clone
...@@ -455,6 +675,14 @@ Clones this container and returns a copy. The modification to the copy does not ...@@ -455,6 +675,14 @@ Clones this container and returns a copy. The modification to the copy does not
| -------- | -------- | | -------- | -------- |
| LinkedList&lt;T&gt; | New **LinkedList** instance obtained.| | LinkedList&lt;T&gt; | New **LinkedList** instance obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The clone method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -464,6 +692,11 @@ linkedList.add(4); ...@@ -464,6 +692,11 @@ linkedList.add(4);
linkedList.add(5); linkedList.add(5);
linkedList.add(4); linkedList.add(4);
let result = linkedList.clone(); let result = linkedList.clone();
try {
linkedList.clone.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### forEach ### forEach
...@@ -490,6 +723,14 @@ callbackfn ...@@ -490,6 +723,14 @@ callbackfn
| index | number | No| Position index of the element that is currently traversed.| | index | number | No| Position index of the element that is currently traversed.|
| LinkedList | LinkedList&lt;T&gt; | No| Instance that invokes the **forEach** API.| | LinkedList | LinkedList&lt;T&gt; | No| Instance that invokes the **forEach** API.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The forEach method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -501,6 +742,13 @@ linkedList.add(4); ...@@ -501,6 +742,13 @@ linkedList.add(4);
linkedList.forEach((value, index) => { linkedList.forEach((value, index) => {
console.log("value:" + value, index); console.log("value:" + value, index);
}); });
try {
linkedList.forEach.bind({}, (value, index) => {
console.log("value:" + value, index);
})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### clear ### clear
...@@ -511,6 +759,14 @@ Clears this container and sets its length to **0**. ...@@ -511,6 +759,14 @@ Clears this container and sets its length to **0**.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The clear method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -520,6 +776,11 @@ linkedList.add(4); ...@@ -520,6 +776,11 @@ linkedList.add(4);
linkedList.add(5); linkedList.add(5);
linkedList.add(4); linkedList.add(4);
linkedList.clear(); linkedList.clear();
try {
linkedList.clear.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### set ### set
...@@ -543,6 +804,15 @@ Replaces an element at the specified position in this container with a given ele ...@@ -543,6 +804,15 @@ Replaces an element at the specified position in this container with a given ele
| -------- | -------- | | -------- | -------- |
| T | New element.| | T | New element.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The set method cannot be bound. |
| 10200001 | The value of parameters are out of range. |
**Example** **Example**
```ts ```ts
...@@ -552,6 +822,16 @@ linkedList.add(4); ...@@ -552,6 +822,16 @@ linkedList.add(4);
linkedList.add(5); linkedList.add(5);
linkedList.add(4); linkedList.add(4);
let result = linkedList.set(2, "b"); let result = linkedList.set(2, "b");
try {
linkedList.set.bind({}, 2, "b")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
try {
linkedList.set(8, "b");
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### convertToArray ### convertToArray
...@@ -568,6 +848,14 @@ Converts this container into an array. ...@@ -568,6 +848,14 @@ Converts this container into an array.
| -------- | -------- | | -------- | -------- |
| Array&lt;T&gt; | Array obtained.| | Array&lt;T&gt; | Array obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The convertToArray method cannot be bound. |
**Example** **Example**
```ts ```ts
let linkedList = new LinkedList(); let linkedList = new LinkedList();
...@@ -576,6 +864,11 @@ linkedList.add(4); ...@@ -576,6 +864,11 @@ linkedList.add(4);
linkedList.add(5); linkedList.add(5);
linkedList.add(4); linkedList.add(4);
let result = linkedList.convertToArray(); let result = linkedList.convertToArray();
try {
linkedList.convertToArray.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### getFirst ### getFirst
...@@ -592,6 +885,14 @@ Obtains the first element in this container. ...@@ -592,6 +885,14 @@ Obtains the first element in this container.
| -------- | -------- | | -------- | -------- |
| T | Returns the element if obtained; returns **undefined** otherwise.| | T | Returns the element if obtained; returns **undefined** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getFirst method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -601,6 +902,11 @@ linkedList.add(4); ...@@ -601,6 +902,11 @@ linkedList.add(4);
linkedList.add(5); linkedList.add(5);
linkedList.add(4); linkedList.add(4);
let result = linkedList.getFirst(); let result = linkedList.getFirst();
try {
linkedList.getFirst.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### getLast ### getLast
...@@ -617,6 +923,14 @@ Obtains the last element in this container. ...@@ -617,6 +923,14 @@ Obtains the last element in this container.
| -------- | -------- | | -------- | -------- |
| T | Returns the element if obtained; returns **undefined** otherwise.| | T | Returns the element if obtained; returns **undefined** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getLast method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -626,6 +940,11 @@ linkedList.add(4); ...@@ -626,6 +940,11 @@ linkedList.add(4);
linkedList.add(5); linkedList.add(5);
linkedList.add(4); linkedList.add(4);
linkedList.getLast(); linkedList.getLast();
try {
linkedList.getLast.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### [Symbol.iterator] ### [Symbol.iterator]
...@@ -642,6 +961,14 @@ Obtains an iterator, each item of which is a JavaScript object. ...@@ -642,6 +961,14 @@ Obtains an iterator, each item of which is a JavaScript object.
| -------- | -------- | | -------- | -------- |
| IterableIterator&lt;T&gt; | Iterator obtained.| | IterableIterator&lt;T&gt; | Iterator obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The Symbol.iterator method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -663,4 +990,9 @@ while(temp != undefined) { ...@@ -663,4 +990,9 @@ while(temp != undefined) {
console.log("value:" + temp); console.log("value:" + temp);
temp = iter.next().value; temp = iter.next().value;
} }
try {
linkedList[Symbol.iterator].bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -26,7 +26,7 @@ import List from '@ohos.util.List'; ...@@ -26,7 +26,7 @@ import List from '@ohos.util.List';
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
| Name| Type| Readable| Writable| Description| | Name| Type | Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| length | number | Yes| No| Number of elements in a list (called container later).| | length | number | Yes| No| Number of elements in a list (called container later).|
...@@ -39,11 +39,23 @@ A constructor used to create a **List** instance. ...@@ -39,11 +39,23 @@ A constructor used to create a **List** instance.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200012 | The List's constructor cannot be directly invoked. |
**Example** **Example**
```ts ```ts
let list = new List(); let list = new List();
try {
let list2 = List();
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -67,16 +79,30 @@ Adds an element at the end of this container. ...@@ -67,16 +79,30 @@ Adds an element at the end of this container.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the element is added successfully; returns **false** otherwise.| | boolean | Returns **true** if the element is added successfully; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The add method cannot be bound. |
**Example** **Example**
```ts ```ts
let list = new List(); let list = new List();
let result = list.add("a"); let result1 = list.add("a");
let result1 = list.add(1); let result2 = list.add(1);
let b = [1, 2, 3]; let b = [1, 2, 3];
list.add(b); let result3 = list.add(b);
let c = {name : "Dylon", age : "13"}; let c = {name : "Dylon", age : "13"};
let result3 = list.add(false); let result4 = list.add(c);
let result5 = list.add(false);
try {
list.add.bind({}, "b")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### insert ### insert
...@@ -94,6 +120,15 @@ Inserts an element at the specified position in this container. ...@@ -94,6 +120,15 @@ Inserts an element at the specified position in this container.
| element | T | Yes| Target element.| | element | T | Yes| Target element.|
| index | number | Yes| Index of the position where the element is to be inserted.| | index | number | Yes| Index of the position where the element is to be inserted.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The insert method cannot be bound. |
| 10200001 | The value of parameters are out of range. |
**Example** **Example**
```ts ```ts
...@@ -101,6 +136,16 @@ let list = new List(); ...@@ -101,6 +136,16 @@ let list = new List();
list.insert("A", 0); list.insert("A", 0);
list.insert(0, 1); list.insert(0, 1);
list.insert(true, 2); list.insert(true, 2);
try {
list.insert.bind({}, "b", 3)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
try {
list.insert("b", 6);
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### has ### has
...@@ -123,6 +168,14 @@ Checks whether this container has the specified element. ...@@ -123,6 +168,14 @@ Checks whether this container has the specified element.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the specified element is contained; returns **false** otherwise.| | boolean | Returns **true** if the specified element is contained; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The has method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -130,6 +183,11 @@ let list = new List(); ...@@ -130,6 +183,11 @@ let list = new List();
let result = list.has("squirrel"); let result = list.has("squirrel");
list.add("squirrel"); list.add("squirrel");
let result1 = list.has("squirrel"); let result1 = list.has("squirrel");
try {
list.has.bind({}, "squirrel")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### get ### get
...@@ -152,6 +210,14 @@ Obtains the element at the specified position in this container. ...@@ -152,6 +210,14 @@ Obtains the element at the specified position in this container.
| -------- | -------- | | -------- | -------- |
| T | Element obtained.| | T | Element obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The get method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -164,6 +230,11 @@ list.add(1); ...@@ -164,6 +230,11 @@ list.add(1);
list.add(2); list.add(2);
list.add(4); list.add(4);
let result = list.get(2); let result = list.get(2);
try {
list.get.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### getLastIndexOf ### getLastIndexOf
...@@ -186,6 +257,14 @@ Obtains the index of the last occurrence of the specified element in this contai ...@@ -186,6 +257,14 @@ Obtains the index of the last occurrence of the specified element in this contai
| -------- | -------- | | -------- | -------- |
| number | Returns the index if obtained; returns **-1** otherwise.| | number | Returns the index if obtained; returns **-1** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getLastIndexOf method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -198,6 +277,11 @@ list.add(1); ...@@ -198,6 +277,11 @@ list.add(1);
list.add(2); list.add(2);
list.add(4); list.add(4);
let result = list.getLastIndexOf(2); let result = list.getLastIndexOf(2);
try {
list.getLastIndexOf.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### getIndexOf ### getIndexOf
...@@ -220,6 +304,14 @@ Obtains the index of the first occurrence of the specified element in this conta ...@@ -220,6 +304,14 @@ Obtains the index of the first occurrence of the specified element in this conta
| -------- | -------- | | -------- | -------- |
| number | Returns the position index if obtained; returns **-1** otherwise.| | number | Returns the position index if obtained; returns **-1** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getIndexOf method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -233,6 +325,11 @@ list.add(2); ...@@ -233,6 +325,11 @@ list.add(2);
list.add(4); list.add(4);
list.getIndexOf(2); list.getIndexOf(2);
let result = list.getIndexOf(2); let result = list.getIndexOf(2);
try {
list.getIndexOf.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### equal ### equal
...@@ -255,6 +352,14 @@ Compares whether a specified object is equal to this container. ...@@ -255,6 +352,14 @@ Compares whether a specified object is equal to this container.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the two are equal; returns **false** otherwise.| | boolean | Returns **true** if the two are equal; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The equal method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -270,6 +375,11 @@ obj1.add(5); ...@@ -270,6 +375,11 @@ obj1.add(5);
list.equal(obj1); list.equal(obj1);
let obj2 = {name : "Dylon", age : "13"}; let obj2 = {name : "Dylon", age : "13"};
let result = list.equal(obj2); let result = list.equal(obj2);
try {
list.equal.bind({}, obj2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### removeByIndex ### removeByIndex
...@@ -292,6 +402,15 @@ Removes an element at the specified position from this container. ...@@ -292,6 +402,15 @@ Removes an element at the specified position from this container.
| -------- | -------- | | -------- | -------- |
| T | Element removed.| | T | Element removed.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The removeByIndex method cannot be bound. |
| 10200001 | The value of parameters are out of range. |
**Example** **Example**
```ts ```ts
...@@ -302,6 +421,16 @@ list.add(5); ...@@ -302,6 +421,16 @@ list.add(5);
list.add(2); list.add(2);
list.add(4); list.add(4);
let result = list.removeByIndex(2); let result = list.removeByIndex(2);
try {
list.removeByIndex.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
try {
list.removeByIndex(8);
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### remove ### remove
...@@ -324,6 +453,14 @@ Removes the first occurrence of the specified element from this container. ...@@ -324,6 +453,14 @@ Removes the first occurrence of the specified element from this container.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the element is removed successfully; returns **false** otherwise.| | boolean | Returns **true** if the element is removed successfully; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The remove method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -333,6 +470,11 @@ list.add(4); ...@@ -333,6 +470,11 @@ list.add(4);
list.add(5); list.add(5);
list.add(4); list.add(4);
let result = list.remove(2); let result = list.remove(2);
try {
list.remove.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### replaceAllElements ### replaceAllElements
...@@ -359,6 +501,14 @@ callbackfn ...@@ -359,6 +501,14 @@ callbackfn
| index | number | No| Position index of the element that is currently traversed.| | index | number | No| Position index of the element that is currently traversed.|
| list | List&lt;T&gt; | No| Instance that invokes the **replaceAllElements** method.| | list | List&lt;T&gt; | No| Instance that invokes the **replaceAllElements** method.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The replaceAllElements method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -373,6 +523,13 @@ list.replaceAllElements((value: number, index: number) => { ...@@ -373,6 +523,13 @@ list.replaceAllElements((value: number, index: number) => {
list.replaceAllElements((value: number, index: number) => { list.replaceAllElements((value: number, index: number) => {
return value = value - 2; return value = value - 2;
}); });
try {
list.replaceAllElements.bind({}, (value: number, index: number) => {
return value = 2 * value;
})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### forEach ### forEach
...@@ -399,6 +556,14 @@ callbackfn ...@@ -399,6 +556,14 @@ callbackfn
| index | number | No| Position index of the element that is currently traversed.| | index | number | No| Position index of the element that is currently traversed.|
| List | List&lt;T&gt; | No| Instance that invokes the **forEach** method.| | List | List&lt;T&gt; | No| Instance that invokes the **forEach** method.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The forEach method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -410,6 +575,13 @@ list.add(4); ...@@ -410,6 +575,13 @@ list.add(4);
list.forEach((value, index) => { list.forEach((value, index) => {
console.log("value: " + value, index); console.log("value: " + value, index);
}); });
try {
list.forEach.bind({}, (value, index) => {
console.log("value: " + value, index);
})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -434,6 +606,14 @@ comparator ...@@ -434,6 +606,14 @@ comparator
| firstValue | T | Yes| Previous element.| | firstValue | T | Yes| Previous element.|
| secondValue | T | Yes| Next element.| | secondValue | T | Yes| Next element.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The sort method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -444,6 +624,11 @@ list.add(5); ...@@ -444,6 +624,11 @@ list.add(5);
list.add(4); list.add(4);
list.sort((a: number, b: number) => a - b); list.sort((a: number, b: number) => a - b);
list.sort((a: number, b: number) => b - a); list.sort((a: number, b: number) => b - a);
try {
list.sort.bind({}, (a: number, b: number) => b - a)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### getSubList ### getSubList
...@@ -467,6 +652,15 @@ Obtains elements within a range in this container, including the element at the ...@@ -467,6 +652,15 @@ Obtains elements within a range in this container, including the element at the
| -------- | -------- | | -------- | -------- |
| List&lt;T&gt; | New **List** instance obtained.| | List&lt;T&gt; | New **List** instance obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getSubList method cannot be bound. |
| 10200001 | The value of parameters are out of range. |
**Example** **Example**
```ts ```ts
...@@ -478,6 +672,16 @@ list.add(4); ...@@ -478,6 +672,16 @@ list.add(4);
let result = list.getSubList(2, 4); let result = list.getSubList(2, 4);
let result1 = list.getSubList(4, 3); let result1 = list.getSubList(4, 3);
let result2 = list.getSubList(2, 6); let result2 = list.getSubList(2, 6);
try {
list.getSubList.bind({}, 2, 4)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
try {
list.getSubList(2, 10);
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### clear ### clear
...@@ -488,6 +692,14 @@ Clears this container and sets its length to **0**. ...@@ -488,6 +692,14 @@ Clears this container and sets its length to **0**.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The clear method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -497,6 +709,11 @@ list.add(4); ...@@ -497,6 +709,11 @@ list.add(4);
list.add(5); list.add(5);
list.add(4); list.add(4);
list.clear(); list.clear();
try {
list.clear.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### set ### set
...@@ -520,6 +737,15 @@ Replaces an element at the specified position in this container with a given ele ...@@ -520,6 +737,15 @@ Replaces an element at the specified position in this container with a given ele
| -------- | -------- | | -------- | -------- |
| T | New element.| | T | New element.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The set method cannot be bound. |
| 10200001 | The value of parameters are out of range. |
**Example** **Example**
```ts ```ts
...@@ -529,7 +755,16 @@ list.add(4); ...@@ -529,7 +755,16 @@ list.add(4);
list.add(5); list.add(5);
list.add(4); list.add(4);
list.set(2, "b"); list.set(2, "b");
try {
list.set.bind({}, 3, "b")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
try {
list.set(8, "b");
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### convertToArray ### convertToArray
...@@ -546,6 +781,14 @@ Converts this container into an array. ...@@ -546,6 +781,14 @@ Converts this container into an array.
| -------- | -------- | | -------- | -------- |
| Array&lt;T&gt; | Array obtained.| | Array&lt;T&gt; | Array obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The convertToArray method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -555,6 +798,11 @@ list.add(4); ...@@ -555,6 +798,11 @@ list.add(4);
list.add(5); list.add(5);
list.add(4); list.add(4);
let result = list.convertToArray(); let result = list.convertToArray();
try {
list.convertToArray.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### isEmpty ### isEmpty
...@@ -571,6 +819,14 @@ Checks whether this container is empty (contains no element). ...@@ -571,6 +819,14 @@ Checks whether this container is empty (contains no element).
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the container is empty; returns **false** otherwise.| | boolean | Returns **true** if the container is empty; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The isEmpty method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -580,6 +836,11 @@ list.add(4); ...@@ -580,6 +836,11 @@ list.add(4);
list.add(5); list.add(5);
list.add(4); list.add(4);
let result = list.isEmpty(); let result = list.isEmpty();
try {
list.isEmpty.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### getFirst ### getFirst
...@@ -596,6 +857,14 @@ Obtains the first element in this container. ...@@ -596,6 +857,14 @@ Obtains the first element in this container.
| -------- | -------- | | -------- | -------- |
| T | The first element obtained.| | T | The first element obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getFirst method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -605,6 +874,11 @@ list.add(4); ...@@ -605,6 +874,11 @@ list.add(4);
list.add(5); list.add(5);
list.add(4); list.add(4);
let result = list.getFirst(); let result = list.getFirst();
try {
list.getFirst.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### getLast ### getLast
...@@ -621,6 +895,14 @@ Obtains the last element in this container. ...@@ -621,6 +895,14 @@ Obtains the last element in this container.
| -------- | -------- | | -------- | -------- |
| T | The last element obtained.| | T | The last element obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getLast method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -630,6 +912,11 @@ list.add(4); ...@@ -630,6 +912,11 @@ list.add(4);
list.add(5); list.add(5);
list.add(4); list.add(4);
let result = list.getLast(); let result = list.getLast();
try {
list.getLast.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### [Symbol.iterator] ### [Symbol.iterator]
...@@ -646,6 +933,14 @@ Obtains an iterator, each item of which is a JavaScript object. ...@@ -646,6 +933,14 @@ Obtains an iterator, each item of which is a JavaScript object.
| -------- | -------- | | -------- | -------- |
| IterableIterator&lt;T&gt; | Iterator obtained.| | IterableIterator&lt;T&gt; | Iterator obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The Symbol.iterator method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -667,4 +962,9 @@ while(temp != undefined) { ...@@ -667,4 +962,9 @@ while(temp != undefined) {
console.log("value: " + temp); console.log("value: " + temp);
temp = iter.next().value; temp = iter.next().value;
} }
try {
list[Symbol.iterator].bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
**PlainArray** stores key-value (KV) pairs. Each key must be unique, be of the number type, and have only one value. **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, which map to values in other arrays. **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.
Both **PlainArray** and **[LightWeightMap](js-apis-lightweightmap.md)** are used to store KV pairs in the lightweight structure. However, the key type of **PlainArray** can only be **number**. Both **PlainArray** and **[LightWeightMap](js-apis-lightweightmap.md)** are used to store KV pairs in the lightweight structure. However, the key type of **PlainArray** can only be **number**.
...@@ -42,10 +42,23 @@ A constructor used to create a **PlainArray** instance. ...@@ -42,10 +42,23 @@ A constructor used to create a **PlainArray** instance.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200012 | The PlainArray's constructor cannot be directly invoked. |
**Example** **Example**
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
try {
let plainArray2 = PlainArray();
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -63,11 +76,24 @@ Checks whether this container is empty. ...@@ -63,11 +76,24 @@ Checks whether this container is empty.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the container is empty; returns **false** otherwise.| | boolean | Returns **true** if the container is empty; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The isEmpty method cannot be bound. |
**Example** **Example**
```ts ```ts
const plainArray = new PlainArray(); const plainArray = new PlainArray();
let result = plainArray.isEmpty(); let result = plainArray.isEmpty();
try {
plainArray.isEmpty.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -91,6 +117,14 @@ Checks whether this container contains the specified key. ...@@ -91,6 +117,14 @@ Checks whether this container contains the specified key.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the specified key is contained; returns **false** otherwise.| | boolean | Returns **true** if the specified key is contained; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The has method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -98,6 +132,11 @@ let plainArray = new PlainArray(); ...@@ -98,6 +132,11 @@ let plainArray = new PlainArray();
plainArray.has(1); plainArray.has(1);
plainArray.add(1, "squirrel"); plainArray.add(1, "squirrel");
let result1 = plainArray.has(1); let result1 = plainArray.has(1);
try {
plainArray.has.bind({}, 1)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -121,6 +160,14 @@ Obtains the value of the specified key in this container. ...@@ -121,6 +160,14 @@ Obtains the value of the specified key in this container.
| -------- | -------- | | -------- | -------- |
| T | Value of the key.| | T | Value of the key.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The get method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -128,6 +175,11 @@ let plainArray = new PlainArray(); ...@@ -128,6 +175,11 @@ let plainArray = new PlainArray();
plainArray.add(1, "squirrel"); plainArray.add(1, "squirrel");
plainArray.add(2, "sparrow"); plainArray.add(2, "sparrow");
let result = plainArray.get(1); let result = plainArray.get(1);
try {
plainArray.get.bind({}, 1)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -151,6 +203,14 @@ Obtains the index of the first occurrence of an element with the specified key i ...@@ -151,6 +203,14 @@ Obtains the index of the first occurrence of an element with the specified key i
| -------- | -------- | | -------- | -------- |
| number | Returns the position index if obtained; returns **-1** otherwise.| | number | Returns the position index if obtained; returns **-1** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getIndexOfKey method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -158,6 +218,11 @@ let plainArray = new PlainArray(); ...@@ -158,6 +218,11 @@ let plainArray = new PlainArray();
plainArray.add(1, "squirrel"); plainArray.add(1, "squirrel");
plainArray.add(2, "sparrow"); plainArray.add(2, "sparrow");
let result = plainArray.getIndexOfKey(2); let result = plainArray.getIndexOfKey(2);
try {
plainArray.getIndexOfKey.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -181,6 +246,14 @@ Obtains the index of the first occurrence of an element with the specified value ...@@ -181,6 +246,14 @@ Obtains the index of the first occurrence of an element with the specified value
| -------- | -------- | | -------- | -------- |
| number | Returns the position index if obtained; returns **-1** otherwise.| | number | Returns the position index if obtained; returns **-1** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getIndexOfValue method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -188,6 +261,11 @@ let plainArray = new PlainArray(); ...@@ -188,6 +261,11 @@ let plainArray = new PlainArray();
plainArray.add(1, "squirrel"); plainArray.add(1, "squirrel");
plainArray.add(2, "sparrow"); plainArray.add(2, "sparrow");
let result = plainArray.getIndexOfValue("squirrel"); let result = plainArray.getIndexOfValue("squirrel");
try {
plainArray.getIndexOfValue.bind({}, "squirrel")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -211,6 +289,14 @@ Obtains the key of the element at the specified position in this container. ...@@ -211,6 +289,14 @@ Obtains the key of the element at the specified position in this container.
| -------- | -------- | | -------- | -------- |
| number | Returns the key of the element if obtained; returns **-1** otherwise.| | number | Returns the key of the element if obtained; returns **-1** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getKeyAt method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -218,6 +304,11 @@ let plainArray = new PlainArray(); ...@@ -218,6 +304,11 @@ let plainArray = new PlainArray();
plainArray.add(1, "squirrel"); plainArray.add(1, "squirrel");
plainArray.add(2, "sparrow"); plainArray.add(2, "sparrow");
let result = plainArray.getKeyAt(1); let result = plainArray.getKeyAt(1);
try {
plainArray.getKeyAt.bind({}, 1)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### getValueAt ### getValueAt
...@@ -240,14 +331,33 @@ Obtains the value of an element at the specified position in this container. ...@@ -240,14 +331,33 @@ Obtains the value of an element at the specified position in this container.
| -------- | -------- | | -------- | -------- |
| T | Returns the value of the element if obtained; returns **undefined** otherwise.| | T | Returns the value of the element if obtained; returns **undefined** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getValueAt method cannot be bound. |
| 10200001 | The value of parameters are out of range. |
**Example** **Example**
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "squirrel"); plainArray.add(1, "squirrel");
plainArray.add(2, "sparrow"); plainArray.add(2, "sparrow");
let result = plainArray.getKeyAt(1); let result = plainArray.getValueAt(1);
``` try {
plainArray.getValueAt.bind({}, 1)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
try {
plainArray.getValueAt(10);
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
```
### clone ### clone
...@@ -263,6 +373,14 @@ Clones this container and returns a copy. The modification to the copy does not ...@@ -263,6 +373,14 @@ Clones this container and returns a copy. The modification to the copy does not
| -------- | -------- | | -------- | -------- |
| PlainArray&lt;T&gt; | New **PlainArray** instance obtained.| | PlainArray&lt;T&gt; | New **PlainArray** instance obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The clone method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -270,6 +388,11 @@ let plainArray = new PlainArray(); ...@@ -270,6 +388,11 @@ let plainArray = new PlainArray();
plainArray.add(1, "squirrel"); plainArray.add(1, "squirrel");
plainArray.add(2, "sparrow"); plainArray.add(2, "sparrow");
let newPlainArray = plainArray.clone(); let newPlainArray = plainArray.clone();
try {
plainArray.clone.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -288,11 +411,24 @@ Adds an element to this container. ...@@ -288,11 +411,24 @@ Adds an element to this container.
| key | number | Yes| Key of the target element.| | key | number | Yes| Key of the target element.|
| value | T | Yes| Value of the target element.| | value | T | Yes| Value of the target element.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The add method cannot be bound. |
**Example** **Example**
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "squirrel"); plainArray.add(1, "squirrel");
try {
plainArray.add.bind({}, "squirrel")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -316,14 +452,26 @@ Removes an element with the specified key from this container. ...@@ -316,14 +452,26 @@ Removes an element with the specified key from this container.
| -------- | -------- | | -------- | -------- |
| T | Value of the element removed.| | T | Value of the element removed.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The remove method cannot be bound. |
**Example** **Example**
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "squirrel"); plainArray.add(1, "squirrel");
plainArray.add(2, "sparrow"); plainArray.add(2, "sparrow");
plainArray.remove(2);
let result = plainArray.remove(2); let result = plainArray.remove(2);
try {
plainArray.remove.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -347,14 +495,26 @@ Removes an element at the specified position from this container. ...@@ -347,14 +495,26 @@ Removes an element at the specified position from this container.
| -------- | -------- | | -------- | -------- |
| T | Element removed.| | T | Element removed.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The removeAt method cannot be bound. |
**Example** **Example**
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "squirrel"); plainArray.add(1, "squirrel");
plainArray.add(2, "sparrow"); plainArray.add(2, "sparrow");
plainArray.removeAt(1);
let result = plainArray.removeAt(1); let result = plainArray.removeAt(1);
try {
plainArray.removeAt.bind({}, 1)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -379,6 +539,15 @@ Removes elements in a specified range from this container. ...@@ -379,6 +539,15 @@ Removes elements in a specified range from this container.
| -------- | -------- | | -------- | -------- |
| number | Number of elements removed.| | number | Number of elements removed.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The removeRangeFrom method cannot be bound. |
| 10200001 | The value of parameters are out of range. |
**Example** **Example**
```ts ```ts
...@@ -386,6 +555,16 @@ let plainArray = new PlainArray(); ...@@ -386,6 +555,16 @@ let plainArray = new PlainArray();
plainArray.add(1, "squirrel"); plainArray.add(1, "squirrel");
plainArray.add(2, "sparrow"); plainArray.add(2, "sparrow");
let result = plainArray.removeRangeFrom(1, 3); let result = plainArray.removeRangeFrom(1, 3);
try {
plainArray.removeRangeFrom.bind({}, 1, 3)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
try {
plainArray.removeRangeFrom(10, 3);
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -404,6 +583,15 @@ Sets a value for an element at the specified position in this container. ...@@ -404,6 +583,15 @@ Sets a value for an element at the specified position in this container.
| index | number | Yes| Position index of the target element.| | index | number | Yes| Position index of the target element.|
| value | T | Yes| Value of the target element.| | value | T | Yes| Value of the target element.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The setValueAt method cannot be bound. |
| 10200001 | The value of parameters are out of range. |
**Example** **Example**
```ts ```ts
...@@ -411,6 +599,16 @@ let plainArray = new PlainArray(); ...@@ -411,6 +599,16 @@ let plainArray = new PlainArray();
plainArray.add(1, "squirrel"); plainArray.add(1, "squirrel");
plainArray.add(2, "sparrow"); plainArray.add(2, "sparrow");
plainArray.setValueAt(1, 3546); plainArray.setValueAt(1, 3546);
try {
plainArray.setValueAt.bind({}, 1, 3546)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
try {
plainArray.setValueAt(10, 3);
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -428,6 +626,14 @@ Obtains a string that contains all elements in this container. ...@@ -428,6 +626,14 @@ Obtains a string that contains all elements in this container.
| -------- | -------- | | -------- | -------- |
| String | String obtained.| | String | String obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The toString method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -435,6 +641,11 @@ let plainArray = new PlainArray(); ...@@ -435,6 +641,11 @@ let plainArray = new PlainArray();
plainArray.add(1, "squirrel"); plainArray.add(1, "squirrel");
plainArray.add(2, "sparrow"); plainArray.add(2, "sparrow");
let result = plainArray.toString(); let result = plainArray.toString();
try {
plainArray.toString.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -446,6 +657,14 @@ Clears this container and sets its length to **0**. ...@@ -446,6 +657,14 @@ Clears this container and sets its length to **0**.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The clear method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -453,6 +672,11 @@ let plainArray = new PlainArray(); ...@@ -453,6 +672,11 @@ let plainArray = new PlainArray();
plainArray.add(1, "squirrel"); plainArray.add(1, "squirrel");
plainArray.add(2, "sparrow"); plainArray.add(2, "sparrow");
plainArray.clear(); plainArray.clear();
try {
plainArray.clear.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -478,6 +702,14 @@ callbackfn ...@@ -478,6 +702,14 @@ callbackfn
| index | number | No| Key of the element that is currently traversed.| | index | number | No| Key of the element that is currently traversed.|
| PlainArray | PlainArray&lt;T&gt;| No| Instance that invokes the **forEach** API.| | PlainArray | PlainArray&lt;T&gt;| No| Instance that invokes the **forEach** API.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The forEach method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -487,6 +719,13 @@ plainArray.add(2, "sparrow"); ...@@ -487,6 +719,13 @@ plainArray.add(2, "sparrow");
plainArray.forEach((value, index) => { plainArray.forEach((value, index) => {
console.log("value:" + value, index); console.log("value:" + value, index);
}); });
try {
plainArray.forEach.bind({}, (value, index) => {
console.log("value:" + value, index);
})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -504,6 +743,14 @@ Obtains an iterator object that contains key-value pairs, where the key is of th ...@@ -504,6 +743,14 @@ Obtains an iterator object that contains key-value pairs, where the key is of th
| -------- | -------- | | -------- | -------- |
| IterableIterator&lt;[number, T]&gt; | Iterator obtained.| | IterableIterator&lt;[number, T]&gt; | Iterator obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The Symbol.iterator method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -525,4 +772,9 @@ while(temp != undefined) { ...@@ -525,4 +772,9 @@ while(temp != undefined) {
console.log("value:" + temp[1]); console.log("value:" + temp[1]);
temp = iter.next().value; temp = iter.next().value;
} }
try {
plainArray[Symbol.iterator].bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -39,10 +39,23 @@ A constructor used to create a **Queue** instance. ...@@ -39,10 +39,23 @@ A constructor used to create a **Queue** instance.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200012 | The Queue's constructor cannot be directly invoked. |
**Example** **Example**
```ts ```ts
let queue = new Queue(); let queue = new Queue();
try {
let queue2 = Queue();
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -66,17 +79,29 @@ Adds an element at the end of this container. ...@@ -66,17 +79,29 @@ Adds an element at the end of this container.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the element is added successfully; returns **false** otherwise.| | boolean | Returns **true** if the element is added successfully; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The add method cannot be bound. |
**Example** **Example**
```ts ```ts
let queue = new Queue(); let queue = new Queue();
let result = queue.add("a"); let result = queue.add("a");
let result1 = queue.add(1); let result1 = queue.add(1);
queue.add(1);
let b = [1, 2, 3]; let b = [1, 2, 3];
queue.add(b); let result2 = queue.add(b);
let c = {name : "Dylon", age : "13"}; let c = {name : "Dylon", age : "13"};
let result3 = queue.add(c); let result3 = queue.add(c);
try {
queue.add.bind({}, "b")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### pop ### pop
...@@ -93,6 +118,14 @@ Removes the first element from this container. ...@@ -93,6 +118,14 @@ Removes the first element from this container.
| -------- | -------- | | -------- | -------- |
| T | Element removed.| | T | Element removed.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The pop method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -103,6 +136,11 @@ queue.add(5); ...@@ -103,6 +136,11 @@ queue.add(5);
queue.add(2); queue.add(2);
queue.add(4); queue.add(4);
let result = queue.pop(); let result = queue.pop();
try {
queue.pop.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### getFirst ### getFirst
...@@ -119,6 +157,14 @@ Obtains the first element of this container. ...@@ -119,6 +157,14 @@ Obtains the first element of this container.
| -------- | -------- | | -------- | -------- |
| T | The first element obtained.| | T | The first element obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getFirst method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -128,6 +174,11 @@ queue.add(4); ...@@ -128,6 +174,11 @@ queue.add(4);
queue.add(5); queue.add(5);
queue.add(2); queue.add(2);
let result = queue.getFirst(); let result = queue.getFirst();
try {
queue.getFirst.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### forEach ### forEach
...@@ -154,6 +205,14 @@ callbackfn ...@@ -154,6 +205,14 @@ callbackfn
| index | number | No| Position index of the element that is currently traversed.| | index | number | No| Position index of the element that is currently traversed.|
| Queue | Queue&lt;T&gt; | No| Instance that invokes the **forEach** method.| | Queue | Queue&lt;T&gt; | No| Instance that invokes the **forEach** method.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The forEach method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -165,7 +224,13 @@ queue.add(4); ...@@ -165,7 +224,13 @@ queue.add(4);
queue.forEach((value, index) => { queue.forEach((value, index) => {
console.log("value:" + value, index); console.log("value:" + value, index);
}); });
try {
queue.forEach.bind({}, (value, index) => {
console.log("value:" + value, index);
})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### [Symbol.iterator] ### [Symbol.iterator]
...@@ -182,8 +247,15 @@ Obtains an iterator, each item of which is a JavaScript object. ...@@ -182,8 +247,15 @@ Obtains an iterator, each item of which is a JavaScript object.
| -------- | -------- | | -------- | -------- |
| IterableIterator&lt;T&gt; | Iterator obtained.| | IterableIterator&lt;T&gt; | Iterator obtained.|
**Example** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The Symbol.iterator method cannot be bound. |
**Example**
```ts ```ts
let queue = new Queue(); let queue = new Queue();
queue.add(2); queue.add(2);
...@@ -203,4 +275,9 @@ while(temp != undefined) { ...@@ -203,4 +275,9 @@ while(temp != undefined) {
console.log("value:" + temp); console.log("value:" + temp);
temp = iter.next().value; temp = iter.next().value;
} }
try {
queue[Symbol.iterator].bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -41,10 +41,23 @@ A constructor used to create a **Stack** instance. ...@@ -41,10 +41,23 @@ A constructor used to create a **Stack** instance.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200012 | The Stack's constructor cannot be directly invoked. |
**Example** **Example**
```ts ```ts
let stack = new Stack(); let stack = new Stack();
try {
let stack2 = Stack();
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -68,6 +81,14 @@ Adds an element at the top of this container. ...@@ -68,6 +81,14 @@ Adds an element at the top of this container.
| -------- | -------- | | -------- | -------- |
| T | Element added.| | T | Element added.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The push method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -75,9 +96,14 @@ let stack = new Stack(); ...@@ -75,9 +96,14 @@ let stack = new Stack();
let result = stack.push("a"); let result = stack.push("a");
let result1 = stack.push(1); let result1 = stack.push(1);
let b = [1, 2, 3]; let b = [1, 2, 3];
stack.push(b); let result2 = stack.push(b);
let c = {name : "Dylon", age : "13"}; let c = {name : "Dylon", age : "13"};
let result3 = stack.push(c); let result3 = stack.push(c);
try {
stack.push.bind({}, "b")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### pop ### pop
...@@ -94,6 +120,14 @@ Removes the top element from this container. ...@@ -94,6 +120,14 @@ Removes the top element from this container.
| -------- | -------- | | -------- | -------- |
| T | Element removed.| | T | Element removed.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The pop method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -104,6 +138,11 @@ stack.push(5); ...@@ -104,6 +138,11 @@ stack.push(5);
stack.push(2); stack.push(2);
stack.push(4); stack.push(4);
let result = stack.pop(); let result = stack.pop();
try {
stack.pop.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### peek ### peek
...@@ -120,6 +159,14 @@ Obtains the top element of this container. ...@@ -120,6 +159,14 @@ Obtains the top element of this container.
| -------- | -------- | | -------- | -------- |
| T | Element obtained.| | T | Element obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The peek method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -129,6 +176,11 @@ stack.push(4); ...@@ -129,6 +176,11 @@ stack.push(4);
stack.push(5); stack.push(5);
stack.push(2); stack.push(2);
let result = stack.peek(); let result = stack.peek();
try {
stack.peek.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### locate ### locate
...@@ -151,6 +203,14 @@ Obtains the index of the first occurrence of the specified element in this conta ...@@ -151,6 +203,14 @@ Obtains the index of the first occurrence of the specified element in this conta
| -------- | -------- | | -------- | -------- |
| number | Returns the position index if obtained; returns **-1** otherwise.| | number | Returns the position index if obtained; returns **-1** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The locate method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -160,6 +220,11 @@ stack.push(4); ...@@ -160,6 +220,11 @@ stack.push(4);
stack.push(5); stack.push(5);
stack.push(2); stack.push(2);
let result = stack.locate(2); let result = stack.locate(2);
try {
stack.locate.bind({}, 2)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### forEach ### forEach
...@@ -186,6 +251,14 @@ callbackfn ...@@ -186,6 +251,14 @@ callbackfn
| index | number | No| Position index of the element that is currently traversed.| | index | number | No| Position index of the element that is currently traversed.|
| stack | Stack&lt;T&gt; | No| Instance that invokes the **forEach** method.| | stack | Stack&lt;T&gt; | No| Instance that invokes the **forEach** method.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The forEach method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -197,6 +270,13 @@ stack.push(4); ...@@ -197,6 +270,13 @@ stack.push(4);
stack.forEach((value, index) => { stack.forEach((value, index) => {
console.log("value:" + value, index); console.log("value:" + value, index);
}); });
try {
stack.forEach.bind({}, (value, index) => {
console.log("value:" + value, index);
})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### isEmpty ### isEmpty
...@@ -213,6 +293,14 @@ Checks whether this container is empty (contains no elements). ...@@ -213,6 +293,14 @@ Checks whether this container is empty (contains no elements).
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the container is empty; returns **false** otherwise.| | boolean | Returns **true** if the container is empty; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The isEmpty method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -222,6 +310,11 @@ stack.push(4); ...@@ -222,6 +310,11 @@ stack.push(4);
stack.push(5); stack.push(5);
stack.push(4); stack.push(4);
let result = stack.isEmpty(); let result = stack.isEmpty();
try {
stack.isEmpty.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
### [Symbol.iterator] ### [Symbol.iterator]
...@@ -238,6 +331,14 @@ Obtains an iterator, each item of which is a JavaScript object. ...@@ -238,6 +331,14 @@ Obtains an iterator, each item of which is a JavaScript object.
| -------- | -------- | | -------- | -------- |
| IterableIterator&lt;T&gt; | Iterator obtained.| | IterableIterator&lt;T&gt; | Iterator obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The Symbol.iterator method cannot be bound. |
**Example** **Example**
```ts ```ts
let stack = new Stack(); let stack = new Stack();
...@@ -258,4 +359,9 @@ while(temp != undefined) { ...@@ -258,4 +359,9 @@ while(temp != undefined) {
console.log("value:" + temp); console.log("value:" + temp);
temp = iter.next().value; temp = iter.next().value;
} }
try {
stack[Symbol.iterator].bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -44,10 +44,23 @@ A constructor used to create a **TreeSet** instance. ...@@ -44,10 +44,23 @@ A constructor used to create a **TreeSet** instance.
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| comparator | function | No| Custom comparator.| | comparator | function | No| Custom comparator.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200012 | The TreeSet's constructor cannot be directly invoked. |
**Example** **Example**
```ts ```ts
let treeSet = new TreeSet(); let treeSet = new TreeSet();
try {
let treeSet2 = TreeSet();
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -65,11 +78,24 @@ Checks whether this container is empty (contains no element). ...@@ -65,11 +78,24 @@ Checks whether this container is empty (contains no element).
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the container is empty; returns **false** otherwise.| | boolean | Returns **true** if the container is empty; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The isEmpty method cannot be bound. |
**Example** **Example**
```ts ```ts
const treeSet = new TreeSet(); const treeSet = new TreeSet();
let result = treeSet.isEmpty(); let result = treeSet.isEmpty();
try {
treeSet.isEmpty.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -93,6 +119,14 @@ Checks whether this container has the specified value. ...@@ -93,6 +119,14 @@ Checks whether this container has the specified value.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the specified value is contained; returns **false** otherwise.| | boolean | Returns **true** if the specified value is contained; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The has method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -100,6 +134,11 @@ let treeSet = new TreeSet(); ...@@ -100,6 +134,11 @@ let treeSet = new TreeSet();
treeSet.has(123); treeSet.has(123);
treeSet.add(123); treeSet.add(123);
let result1 = treeSet.has(123); let result1 = treeSet.has(123);
try {
treeSet.has.bind({}, 123)(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -117,6 +156,14 @@ Obtains the value of the first element in this container. ...@@ -117,6 +156,14 @@ Obtains the value of the first element in this container.
| -------- | -------- | | -------- | -------- |
| T | Value obtained.| | T | Value obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getFirstValue method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -124,6 +171,11 @@ let treeSet = new TreeSet(); ...@@ -124,6 +171,11 @@ let treeSet = new TreeSet();
treeSet.add("squirrel"); treeSet.add("squirrel");
treeSet.add("sparrow"); treeSet.add("sparrow");
let result = treeSet.getFirstValue(); let result = treeSet.getFirstValue();
try {
treeSet.getFirstValue.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -141,6 +193,14 @@ Obtains the value of the last element in this container. ...@@ -141,6 +193,14 @@ Obtains the value of the last element in this container.
| -------- | -------- | | -------- | -------- |
| T | Value obtained.| | T | Value obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getLastValue method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -148,6 +208,11 @@ let treeSet = new TreeSet(); ...@@ -148,6 +208,11 @@ let treeSet = new TreeSet();
treeSet.add("squirrel"); treeSet.add("squirrel");
treeSet.add("sparrow"); treeSet.add("sparrow");
let result = treeSet.getLastValue(); let result = treeSet.getLastValue();
try {
treeSet.getLastValue.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -171,11 +236,24 @@ Adds an element to this container. ...@@ -171,11 +236,24 @@ Adds an element to this container.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the element is added successfully; returns **false** otherwise.| | boolean | Returns **true** if the element is added successfully; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The add method cannot be bound. |
**Example** **Example**
```ts ```ts
let treeSet = new TreeSet(); let treeSet = new TreeSet();
let result = treeSet.add("squirrel"); let result = treeSet.add("squirrel");
try {
treeSet.add.bind({}, "squirrel")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -199,6 +277,14 @@ Removes the element with the specified key from this container. ...@@ -199,6 +277,14 @@ Removes the element with the specified key from this container.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the element is removed successfully; returns **false** otherwise.| | boolean | Returns **true** if the element is removed successfully; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The remove method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -206,6 +292,11 @@ let treeSet = new TreeSet(); ...@@ -206,6 +292,11 @@ let treeSet = new TreeSet();
treeSet.add("squirrel"); treeSet.add("squirrel");
treeSet.add("sparrow"); treeSet.add("sparrow");
let result = treeSet.remove("sparrow"); let result = treeSet.remove("sparrow");
try {
treeSet.remove.bind({}, "sparrow")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -229,6 +320,14 @@ Obtains the value that is placed in front of the input key in this container. ...@@ -229,6 +320,14 @@ Obtains the value that is placed in front of the input key in this container.
| -------- | -------- | | -------- | -------- |
| T | Value obtained.| | T | Value obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getLowerValue method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -237,6 +336,11 @@ treeSet.add("squirrel"); ...@@ -237,6 +336,11 @@ treeSet.add("squirrel");
treeSet.add("sparrow"); treeSet.add("sparrow");
treeSet.add("gander"); treeSet.add("gander");
let result = treeSet.getLowerValue("sparrow"); let result = treeSet.getLowerValue("sparrow");
try {
treeSet.getLowerValue.bind({}, "sparrow")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -260,6 +364,14 @@ Obtains the value that is placed next to the input key in this container. ...@@ -260,6 +364,14 @@ Obtains the value that is placed next to the input key in this container.
| -------- | -------- | | -------- | -------- |
| T | Value obtained.| | T | Value obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getHigherValue method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -268,6 +380,11 @@ treeSet.add("squirrel"); ...@@ -268,6 +380,11 @@ treeSet.add("squirrel");
treeSet.add("sparrow"); treeSet.add("sparrow");
treeSet.add("gander"); treeSet.add("gander");
let result = treeSet.getHigherValue("sparrow"); let result = treeSet.getHigherValue("sparrow");
try {
treeSet.getHigherValue.bind({}, "sparrow")(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -285,6 +402,14 @@ Removes the first element in this container. ...@@ -285,6 +402,14 @@ Removes the first element in this container.
| -------- | -------- | | -------- | -------- |
| T | Element removed.| | T | Element removed.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The popFirst method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -292,6 +417,11 @@ let treeSet = new TreeSet(); ...@@ -292,6 +417,11 @@ let treeSet = new TreeSet();
treeSet.add("squirrel"); treeSet.add("squirrel");
treeSet.add("sparrow"); treeSet.add("sparrow");
let result = treeSet.popFirst(); let result = treeSet.popFirst();
try {
treeSet.popFirst.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -309,6 +439,14 @@ Removes the last element in this container. ...@@ -309,6 +439,14 @@ Removes the last element in this container.
| -------- | -------- | | -------- | -------- |
| T | Element removed.| | T | Element removed.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The popLast method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -316,6 +454,11 @@ let treeSet = new TreeSet(); ...@@ -316,6 +454,11 @@ let treeSet = new TreeSet();
treeSet.add("squirrel"); treeSet.add("squirrel");
treeSet.add("sparrow"); treeSet.add("sparrow");
let result = treeSet.popLast(); let result = treeSet.popLast();
try {
treeSet.popLast.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -327,6 +470,14 @@ Clears this container and sets its length to **0**. ...@@ -327,6 +470,14 @@ Clears this container and sets its length to **0**.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The clear method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -334,6 +485,11 @@ let treeSet = new TreeSet(); ...@@ -334,6 +485,11 @@ let treeSet = new TreeSet();
treeSet.add("squirrel"); treeSet.add("squirrel");
treeSet.add("sparrow"); treeSet.add("sparrow");
treeSet.clear(); treeSet.clear();
try {
treeSet.clear.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -351,6 +507,14 @@ Obtains an iterator that contains all the values in this container. ...@@ -351,6 +507,14 @@ Obtains an iterator that contains all the values in this container.
| -------- | -------- | | -------- | -------- |
| IterableIterator&lt;T&gt; | Iterator obtained.| | IterableIterator&lt;T&gt; | Iterator obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The values method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -362,7 +526,12 @@ let temp = iter.next().value; ...@@ -362,7 +526,12 @@ let temp = iter.next().value;
while(temp != undefined) { while(temp != undefined) {
console.log("value:" + temp); console.log("value:" + temp);
temp = iter.next().value; temp = iter.next().value;
} }
try {
treeSet.values.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -388,6 +557,14 @@ callbackfn ...@@ -388,6 +557,14 @@ callbackfn
| key | T | No| Key of the element that is currently traversed (same as **value**).| | key | T | No| Key of the element that is currently traversed (same as **value**).|
| set | TreeSet&lt;T&gt; | No| Instance that invokes the **forEach** method.| | set | TreeSet&lt;T&gt; | No| Instance that invokes the **forEach** method.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The forEach method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -397,6 +574,13 @@ treeSet.add("gull"); ...@@ -397,6 +574,13 @@ treeSet.add("gull");
treeSet.forEach((value, key) => { treeSet.forEach((value, key) => {
console.log("value:" + value, key) console.log("value:" + value, key)
}); });
try {
treeSet.forEach.bind({}, (value, key) => {
console.log("value:" + value, key)
})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -414,6 +598,14 @@ Obtains an iterator that contains all the elements in this container. ...@@ -414,6 +598,14 @@ Obtains an iterator that contains all the elements in this container.
| -------- | -------- | | -------- | -------- |
| IterableIterator<[T, T]> | Iterator obtained.| | IterableIterator<[T, T]> | Iterator obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The entries method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -427,6 +619,11 @@ while(temp != undefined) { ...@@ -427,6 +619,11 @@ while(temp != undefined) {
console.log("value:" + temp[1]); console.log("value:" + temp[1]);
temp = iter.next().value; temp = iter.next().value;
} }
try {
treeSet.entries.bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -444,6 +641,14 @@ Obtains an iterator, each item of which is a JavaScript object. ...@@ -444,6 +641,14 @@ Obtains an iterator, each item of which is a JavaScript object.
| -------- | -------- | | -------- | -------- |
| IterableIterator&lt;T&gt; | Iterator obtained.| | IterableIterator&lt;T&gt; | Iterator obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The Symbol.iterator method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -463,4 +668,9 @@ while(temp != undefined) { ...@@ -463,4 +668,9 @@ while(temp != undefined) {
console.log("value:" + temp); console.log("value:" + temp);
temp = iter.next().value; temp = iter.next().value;
} }
try {
treeSet[Symbol.iterator].bind({})(); // bind() creates a new bound function that, when called, has its this keyword set to the provided value. It is used to test exception capture.
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
``` ```
...@@ -73,7 +73,7 @@ let vector = new Vector(); ...@@ -73,7 +73,7 @@ let vector = new Vector();
let result = vector.add("a"); let result = vector.add("a");
let result1 = vector.add(1); let result1 = vector.add(1);
let b = [1, 2, 3]; let b = [1, 2, 3];
vector.add(b); let result2 = vector.add(b);
let c = {name : "Dylon", age : "13"}; let c = {name : "Dylon", age : "13"};
let result3 = vector.add(c); let result3 = vector.add(c);
``` ```
...@@ -286,8 +286,6 @@ vector.add(4); ...@@ -286,8 +286,6 @@ vector.add(4);
vector.add(5); vector.add(5);
vector.add(4); vector.add(4);
vector.removeByRange(2,4); vector.removeByRange(2,4);
vector.removeByRange(4,3);
vector.removeByRange(2,6);
``` ```
### replaceAllElements ### replaceAllElements
...@@ -431,9 +429,10 @@ vector.add(2); ...@@ -431,9 +429,10 @@ vector.add(2);
vector.add(4); vector.add(4);
vector.add(5); vector.add(5);
vector.add(4); vector.add(4);
let result = vector.subVector(2,4); vector.add(6);
let result1 = vector.subVector(4,3); vector.add(8);
let result2 = vector.subVector(2,6); let result = vector.subVector(0,4);
let result1 = vector.subVector(2,4);
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
反馈
建议
客服 返回
顶部