Refactor scripting - prepare utilities for refactoring of the script definitions handling

This commit is contained in:
Ilya Chernikov
2019-05-12 22:14:45 +02:00
parent 5efd55f530
commit 4fb2f81134
3 changed files with 64 additions and 0 deletions
@@ -83,6 +83,31 @@ open class PropertiesCollection(private val properties: Map<Key<*>, Any?> = empt
data[this] = v
}
fun <T> PropertiesCollection.Key<T>.putIfNotNull(v: T?) {
if (v != null) {
data[this] = v
}
}
fun <T> PropertiesCollection.Key<in List<T>>.putIfAny(vals: Iterable<T>?) {
if (vals?.any() == true) {
data[this] = if (vals is List) vals else vals.toList()
}
}
@JvmName("putIfAny_map")
fun <K, V> PropertiesCollection.Key<in Map<K, V>>.putIfAny(vals: Iterable<Pair<K, V>>?) {
if (vals?.any() == true) {
data[this] = vals.toMap()
}
}
fun <K, V> PropertiesCollection.Key<in Map<K, V>>.putIfAny(vals: Map<K, V>?) {
if (vals?.isNotEmpty() == true) {
data[this] = vals
}
}
// generic for lists
operator fun <T> PropertiesCollection.Key<in List<T>>.invoke(vararg vals: T) {