1/* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17import {assertDefined} from 'common/assert_utils'; 18import {Operation} from 'trace/tree_node/operations/operation'; 19import {OperationChain} from 'trace/tree_node/operations/operation_chain'; 20import {PropertyTreeNode} from 'trace/tree_node/property_tree_node'; 21import { 22 LazyPropertiesStrategyType, 23 PropertiesProvider, 24} from './properties_provider'; 25 26export class PropertiesProviderBuilder { 27 private eagerProperties: PropertyTreeNode | undefined; 28 private lazyPropertiesStrategy: LazyPropertiesStrategyType | undefined; 29 private commonOperations = OperationChain.emptyChain<PropertyTreeNode>(); 30 private eagerOperations = OperationChain.emptyChain<PropertyTreeNode>(); 31 private lazyOperations = OperationChain.emptyChain<PropertyTreeNode>(); 32 33 setEagerProperties(value: PropertyTreeNode): this { 34 this.eagerProperties = value; 35 return this; 36 } 37 38 setLazyPropertiesStrategy(value: LazyPropertiesStrategyType): this { 39 this.lazyPropertiesStrategy = value; 40 return this; 41 } 42 43 setCommonOperations(operations: Array<Operation<PropertyTreeNode>>): this { 44 this.commonOperations = new OperationChain<PropertyTreeNode>(operations); 45 return this; 46 } 47 48 setEagerOperations(operations: Array<Operation<PropertyTreeNode>>): this { 49 this.eagerOperations = new OperationChain<PropertyTreeNode>(operations); 50 return this; 51 } 52 53 setLazyOperations(operations: Array<Operation<PropertyTreeNode>>): this { 54 this.lazyOperations = new OperationChain<PropertyTreeNode>(operations); 55 return this; 56 } 57 58 build(): PropertiesProvider { 59 return new PropertiesProvider( 60 assertDefined(this.eagerProperties), 61 this.lazyPropertiesStrategy, 62 this.commonOperations, 63 this.eagerOperations, 64 this.lazyOperations, 65 ); 66 } 67} 68