• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * Copyright (C) 2021 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 com.android.server.wm.traces.common
18 
19 /**
20  * The utility class to validate a set of conditions
21  *
22  * This class is used to easily integrate multiple conditions into a single
23  * verification, for example, during [WaitCondition], while keeping the individual
24  * conditions separate for better reuse
25  *
26  * @param conditions conditions to be checked
27  */
28 class ConditionList<T>(
29     val conditions: List<Condition<T>>
30 ) : Condition<T>("", { false }) {
31     constructor(vararg conditions: Condition<T>): this(listOf(*conditions))
32 
33     override val message: String
<lambda>null34         get() = conditions.joinToString(" and ") { it.toString() }
35 
36     override val condition: (T) -> Boolean
<lambda>null37         get() = {
38             conditions.all { condition -> condition.isSatisfied(it) }
39         }
40 
getMessagenull41     override fun getMessage(value: T): String = conditions
42         .joinToString(" and ") { it.getMessage(value) }
43 }