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 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 verification, for 23 * example, during [WaitCondition], while keeping the individual conditions separate for better 24 * reuse 25 * 26 * @param conditions conditions to be checked 27 */ 28 class ConditionList<T>(val conditions: List<Condition<T>>) : Condition<T>("", { false }) { 29 constructor(vararg conditions: Condition<T>) : this(listOf(*conditions)) 30 31 override val message: String 32 get() { 33 return "(\n${ 34 conditions <lambda>null35 .joinToString(" and \n") { it.toString() } 36 .prependIndent(" ") 37 }\n)" 38 } 39 40 override val condition: (T) -> Boolean 41 get() = { value -> conditions.all { condition -> condition.isSatisfied(value) } } 42 getMessagenull43 override fun getMessage(value: T): String { 44 return "(\n${ 45 conditions 46 .joinToString(" and \n") { it.getMessage(value) } 47 .prependIndent(" ") 48 }\n)" 49 } 50 } 51