1/*
2 * Copyright (c) 2022-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16let nextId: number = 0
17class ObservedArray<T> extends Array<T> {}
18
19let arr1 = new ObservedArray<number>(1, 2, 3)
20console.log(arr1[0])
21console.log(arr1[nextId])
22
23class NumberArray extends Array<number> {}
24let arr2 = new NumberArray(4, 5, 6)
25console.log(arr2[0])
26console.log(arr2[nextId])
27
28class NumberTypedArray extends Uint32Array {}
29let arr3 = new NumberTypedArray([7, 8, 9])
30console.log(arr3[0])
31console.log(arr3[nextId])
32
33class A extends Uint32Array {}
34class B extends A {}
35class C extends B {}
36let arr4 = new C([10, 11, 12])
37console.log(arr4[0])
38console.log(arr4[nextId])
39
40class Point<T> extends Array<T> {
41    constructor(x: T, y: T) {
42        super(x, y)
43    }
44    
45    public add(rhs: Point<T>): Point<T> {
46        this[0] = this.compare(this[0], rhs[0], true);
47        return this;
48    }
49    
50    private compare(left: T, right: T, flag:boolean): T {
51        return flag ? left : right
52    }
53}
54    
55class PointNumber extends Array<number> {
56    constructor(x: number, y: number) {
57        super(x, y)
58    }
59    
60    public add(rhs: PointNumber): PointNumber {
61        this[0] = this.compare(this[0], rhs[0], true);
62        return this;
63    }
64    
65    private compare(left: number, right: number, flag: boolean): number {
66        return flag ? left : right
67    }
68}
69