1 /*
2  * Copyright 2018 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 // Always inline ktx extension methods unless we have additional call site costs.
18 @file:Suppress("NOTHING_TO_INLINE")
19 
20 package androidx.work
21 
22 /**
23  * Converts a list of pairs to a [Data] object.
24  *
25  * If multiple pairs have the same key, the resulting map will contain the value from the last of
26  * those pairs.
27  *
28  * Entries of the map are iterated in the order they were specified.
29  */
workDataOfnull30 public inline fun workDataOf(vararg pairs: Pair<String, Any?>): Data {
31     val dataBuilder = Data.Builder()
32     for (pair in pairs) {
33         dataBuilder.put(pair.first, pair.second)
34     }
35     return dataBuilder.build()
36 }
37 
38 /**
39  * Returns true if the instance of [Data] has a value corresponding to the given [key] with an
40  * expected type [T].
41  */
hasKeyWithValueOfTypenull42 public inline fun <reified T : Any> Data.hasKeyWithValueOfType(key: String): Boolean =
43     hasKeyWithValueOfType(key, T::class.java)
44