Delegate.maskSmart
This commit is contained in:
parent
cde5db7a78
commit
84d17349b7
@ -4,7 +4,7 @@ kotlin.code.style=official
|
|||||||
specifyKotlinAsDependency=false
|
specifyKotlinAsDependency=false
|
||||||
|
|
||||||
projectGroup=ru.dbotthepony.kommons
|
projectGroup=ru.dbotthepony.kommons
|
||||||
projectVersion=2.9.2
|
projectVersion=2.9.3
|
||||||
|
|
||||||
guavaDepVersion=33.0.0
|
guavaDepVersion=33.0.0
|
||||||
gsonDepVersion=2.8.9
|
gsonDepVersion=2.8.9
|
||||||
|
@ -55,6 +55,20 @@ interface Delegate<V> : Supplier<V>, Consumer<V> {
|
|||||||
@Deprecated("Warning: Using read-only property as delegate")
|
@Deprecated("Warning: Using read-only property as delegate")
|
||||||
constructor(prop: KProperty0<V>) : this(prop::get, Consumer { })
|
constructor(prop: KProperty0<V>) : this(prop::get, Consumer { })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
/**
|
||||||
|
* Returns smart box if [getter] or [setter] is not passthrough
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
fun <V> maskSmart(value: V, getter: DelegateGetter<V>, setter: DelegateSetter<V>): Delegate<V> {
|
||||||
|
if (getter === DelegateGetter.passthrough<V>() && setter === DelegateSetter.passthrough<V>()) {
|
||||||
|
return Box(value)
|
||||||
|
} else {
|
||||||
|
return SmartBox(value, getter, setter)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
operator fun <V> Supplier<V>.getValue(ref: Any?, property: KProperty<*>): V {
|
operator fun <V> Supplier<V>.getValue(ref: Any?, property: KProperty<*>): V {
|
||||||
|
Loading…
Reference in New Issue
Block a user