1 /* <lambda>null2 * Copyright (C) 2023 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 17 package android.tools.traces.component 18 19 import android.tools.traces.surfaceflinger.Layer 20 import android.tools.traces.wm.Activity 21 import android.tools.traces.wm.WindowContainer 22 import java.util.function.Predicate 23 24 class OrComponentMatcher(private val componentMatchers: Collection<IComponentMatcher>) : 25 IComponentMatcher { 26 27 /** {@inheritDoc} */ 28 override fun windowMatchesAnyOf(window: WindowContainer): Boolean { 29 return componentMatchers.any { it.windowMatchesAnyOf(window) } 30 } 31 32 /** {@inheritDoc} */ 33 override fun windowMatchesAnyOf(windows: Collection<WindowContainer>): Boolean { 34 return componentMatchers.any { it.windowMatchesAnyOf(windows) } 35 } 36 37 /** {@inheritDoc} */ 38 override fun activityMatchesAnyOf(activity: Activity): Boolean { 39 return componentMatchers.any { it.activityMatchesAnyOf(activity) } 40 } 41 42 /** {@inheritDoc} */ 43 override fun activityMatchesAnyOf(activities: Collection<Activity>): Boolean { 44 return componentMatchers.any { it.activityMatchesAnyOf(activities) } 45 } 46 47 /** {@inheritDoc} */ 48 override fun layerMatchesAnyOf(layer: Layer): Boolean { 49 return componentMatchers.any { it.layerMatchesAnyOf(layer) } 50 } 51 52 /** {@inheritDoc} */ 53 override fun layerMatchesAnyOf(layers: Collection<Layer>): Boolean { 54 return componentMatchers.any { it.layerMatchesAnyOf(layers) } 55 } 56 57 /** {@inheritDoc} */ 58 override fun check( 59 layers: Collection<Layer>, 60 condition: Predicate<Collection<Layer>>, 61 ): Boolean { 62 return componentMatchers.any { oredComponent -> 63 oredComponent.check(layers) { condition.test(it) } 64 } 65 } 66 67 /** {@inheritDoc} */ 68 override fun toActivityIdentifier(): String = 69 componentMatchers.joinToString(" or ") { it.toActivityIdentifier() } 70 71 /** {@inheritDoc} */ 72 override fun toWindowIdentifier(): String = 73 componentMatchers.joinToString(" or ") { it.toWindowIdentifier() } 74 75 /** {@inheritDoc} */ 76 override fun toLayerIdentifier(): String = 77 componentMatchers.joinToString(" or ") { it.toLayerIdentifier() } 78 } 79