From 8c730e180ce18f4a161517b6543f78322b27ce48 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Mon, 3 Jun 2019 18:36:06 +0300 Subject: [PATCH] Make ClockMark an abstract class instead of an interface --- libraries/stdlib/js/src/kotlin/time/MonoClock.kt | 2 +- libraries/stdlib/src/kotlin/time/Clock.kt | 10 +++++----- libraries/stdlib/src/kotlin/time/Clocks.kt | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libraries/stdlib/js/src/kotlin/time/MonoClock.kt b/libraries/stdlib/js/src/kotlin/time/MonoClock.kt index 99d1ea9f4c7..90bb837b3e5 100644 --- a/libraries/stdlib/js/src/kotlin/time/MonoClock.kt +++ b/libraries/stdlib/js/src/kotlin/time/MonoClock.kt @@ -30,7 +30,7 @@ internal external interface Process { internal class HrTimeClock(val process: Process) : Clock { - override fun mark(): ClockMark = object : ClockMark { + override fun mark(): ClockMark = object : ClockMark() { val startedAt = process.hrtime() override fun elapsed(): Duration = process.hrtime(startedAt).let { (seconds, nanos) -> seconds.seconds + nanos.nanoseconds } diff --git a/libraries/stdlib/src/kotlin/time/Clock.kt b/libraries/stdlib/src/kotlin/time/Clock.kt index 328858b93cd..1a00e8f6fbd 100644 --- a/libraries/stdlib/src/kotlin/time/Clock.kt +++ b/libraries/stdlib/src/kotlin/time/Clock.kt @@ -24,29 +24,29 @@ public interface Clock { * Represents a time point notched on a particular [Clock]. Remains bound to the clock it was taken from * and allows querying for the duration of time elapsed from that point (see the function [elapsed]). */ -public interface ClockMark { +public abstract class ClockMark { /** * Returns the amount of time passed from this clock mark on the clock from which this mark was taken. */ - fun elapsed(): Duration + abstract fun elapsed(): Duration /** * Returns a clock mark on the same clock that is ahead of this clock mark by the specified [duration]. * * The returned clock mark is more _late_ when the [duration] is positive, and more _early_ when the [duration] is negative. */ - operator fun plus(duration: Duration): ClockMark = AdjustedClockMark(this, duration) + open operator fun plus(duration: Duration): ClockMark = AdjustedClockMark(this, duration) /** * Returns a clock mark on the same clock that is behind this clock mark by the specified [duration]. * * The returned clock mark is more _early_ when the [duration] is positive, and more _late_ when the [duration] is negative. */ - operator fun minus(duration: Duration): ClockMark = plus(-duration) + open operator fun minus(duration: Duration): ClockMark = plus(-duration) } -private class AdjustedClockMark(val mark: ClockMark, val adjustment: Duration) : ClockMark { +private class AdjustedClockMark(val mark: ClockMark, val adjustment: Duration) : ClockMark() { override fun elapsed(): Duration = mark.elapsed() - adjustment override fun plus(duration: Duration): ClockMark = AdjustedClockMark(mark, adjustment + duration) diff --git a/libraries/stdlib/src/kotlin/time/Clocks.kt b/libraries/stdlib/src/kotlin/time/Clocks.kt index 5657f8a78a3..92446213ba7 100644 --- a/libraries/stdlib/src/kotlin/time/Clocks.kt +++ b/libraries/stdlib/src/kotlin/time/Clocks.kt @@ -18,7 +18,7 @@ public expect object MonoClock : Clock public abstract class AbstractLongClock(protected val unit: DurationUnit) : Clock { protected abstract fun read(): Long - override fun mark(): ClockMark = object : ClockMark { + override fun mark(): ClockMark = object : ClockMark() { val startedAt = read() override fun elapsed(): Duration = (read() - startedAt).toDuration(this@AbstractLongClock.unit) } @@ -30,7 +30,7 @@ public abstract class AbstractLongClock(protected val unit: DurationUnit) : Cloc public abstract class AbstractDoubleClock(protected val unit: DurationUnit) : Clock { protected abstract fun read(): Double - override fun mark(): ClockMark = object : ClockMark { + override fun mark(): ClockMark = object : ClockMark() { val startedAt = read() override fun elapsed(): Duration = (read() - startedAt).toDuration(this@AbstractDoubleClock.unit) }