1/* 2* Copyright (c) 2023 Hunan OpenValley Digital Industry Development 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 16import TreeSet from '@ohos.util.TreeSet'; 17import ArrayList from '@ohos.util.ArrayList'; 18import { BaseDataSource } from '@ohos/common/src/main/ets/components/BaseDataSource'; 19 20export class TreeSetDataSource extends BaseDataSource { 21 private dataArr: TreeSet<string> = new TreeSet(); 22 private arr: ArrayList<string> = new ArrayList(); 23 24 public totalCount(): number { 25 return this.dataArr.length; 26 } 27 28 public getData(index: number): string { 29 return this.arr[index]; 30 } 31 32 public addData(value: string): void { 33 this.dataArr.add(value); 34 this.arr.add(value); 35 this.notifyDataAdd(this.dataArr.length - 1); 36 this.notifyDataReload(); 37 } 38 39 public deleteData(value: string, index: number): void { 40 this.dataArr.remove(value); 41 this.arr.removeByIndex(index); 42 this.notifyDataDelete(index); 43 this.notifyDataReload(); 44 } 45}