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 import java.util.function.Predicate 20 21 /** 22 * The utility class to validate a set of conditions 23 * 24 * This class is used to easily integrate multiple conditions into a single verification, for 25 * example, during [WaitCondition], while keeping the individual conditions separate for better 26 * reuse 27 * 28 * @param conditions conditions to be checked 29 */ 30 class ConditionList<T>(val conditions: List<Condition<T>>) : Condition<T>("", { false }) { 31 constructor(vararg conditions: Condition<T>) : this(listOf(*conditions)) 32 33 override val message: String 34 get() { 35 return "(\n${ 36 conditions <lambda>null37 .joinToString(" and \n") { it.toString() } 38 .prependIndent(" ") 39 }\n)" 40 } 41 42 override val condition: Predicate<T> 43 get() = Predicate { value -> conditions.all { condition -> condition.isSatisfied(value) } } 44 getMessagenull45 override fun getMessage(value: T): String { 46 return "(\n${ 47 conditions 48 .joinToString(" and \n") { it.getMessage(value) } 49 .prependIndent(" ") 50 }\n)" 51 } 52 } 53