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