Final moves: map delegating accessors and timing utils, provide deprecated methods in the old place

This commit is contained in:
Ilya Gorbunov
2015-11-26 15:48:10 +03:00
parent 597f2c0a8c
commit 0ab33ab075
3 changed files with 62 additions and 0 deletions
@@ -0,0 +1,39 @@
@file:kotlin.jvm.JvmName("MapAccessorsKt")
package kotlin.properties
import kotlin.reflect.KProperty
import kotlin.internal.Exact
/**
* Returns the value of the property for the given object from this read-only map.
* @param thisRef the object for which the value is requested (not used).
* @param property the metadata for the property, used to get the name of property and lookup the value corresponding to this name in the map.
* @return the property value.
*
* @throws NoSuchElementException when the map doesn't contain value for the property name and doesn't provide an implicit default (see [withDefault]).
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public operator fun <V, V1: V> Map<in String, @Exact V>.getValue(thisRef: Any?, property: KProperty<*>): V1 = getOrImplicitDefault(property.name) as V1
/**
* Returns the value of the property for the given object from this mutable map.
* @param thisRef the object for which the value is requested (not used).
* @param property the metadata for the property, used to get the name of property and lookup the value corresponding to this name in the map.
* @return the property value.
*
* @throws NoSuchElementException when the map doesn't contain value for the property name and doesn't provide an implicit default (see [withDefault]).
*/
@kotlin.jvm.JvmName("getVar")
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public operator fun <V> MutableMap<in String, in V>.getValue(thisRef: Any?, property: KProperty<*>): V = getOrImplicitDefault(property.name) as V
/**
* Stores the value of the property for the given object in this mutable map.
* @param thisRef the object for which the value is requested (not used).
* @param property the metadata for the property, used to get the name of property and store the value associated with that name in the map.
* @param value the value to set.
*/
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
public operator fun <V> MutableMap<in String, in V>.setValue(thisRef: Any?, property: KProperty<*>, value: V) {
this.put(property.name, value)
}
@@ -1,4 +1,5 @@
@file:kotlin.jvm.JvmName("TimingKt")
@file:kotlin.jvm.JvmVersion
package kotlin.system
/**
@@ -0,0 +1,22 @@
@file:kotlin.jvm.JvmName("TimingUtilsKt")
package kotlin.util
/**
* Executes the given block and returns elapsed time in milliseconds.
*/
@Deprecated("Use measureTimeMillis from system.timing instead.", ReplaceWith("kotlin.system.measureTimeMillis(block)", "kotlin.system"))
public fun measureTimeMillis(block: () -> Unit) : Long {
val start = System.currentTimeMillis()
block()
return System.currentTimeMillis() - start
}
/**
* Executes the given block and returns elapsed time in nanoseconds.
*/
@Deprecated("Use measureTimeNano from system.timing instead.", ReplaceWith("kotlin.system.measureTimeNano(block)", "kotlin.system"))
public fun measureTimeNano(block: () -> Unit) : Long {
val start = System.nanoTime()
block()
return System.nanoTime() - start
}