From 1e18b15aee2d9184dc9b7537a9852a3f89fde67b Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Sun, 3 Mar 2019 21:38:02 +0100 Subject: feat: Add conversion methods between number and time types This change adds conversion methods from `Number` types into `Instant` and `Duration` instances. --- .../src/main/kotlin/com/atlarge/odcsim/ActorRef.kt | 2 +- .../src/main/kotlin/com/atlarge/odcsim/Time.kt | 40 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) (limited to 'odcsim-core/src/main') diff --git a/odcsim-core/src/main/kotlin/com/atlarge/odcsim/ActorRef.kt b/odcsim-core/src/main/kotlin/com/atlarge/odcsim/ActorRef.kt index f6a9f0b5..3f01e409 100644 --- a/odcsim-core/src/main/kotlin/com/atlarge/odcsim/ActorRef.kt +++ b/odcsim-core/src/main/kotlin/com/atlarge/odcsim/ActorRef.kt @@ -36,7 +36,7 @@ interface ActorRef { /** * Send the specified message to the actor referenced by this [ActorRef]. * - * @param msg The message to send to the referenced architecture. + * @param msg The message to send to the referenced actor. * @param after The delay after which the message should be received by the actor. */ fun send(msg: T, after: Duration = 0.1) diff --git a/odcsim-core/src/main/kotlin/com/atlarge/odcsim/Time.kt b/odcsim-core/src/main/kotlin/com/atlarge/odcsim/Time.kt index 8eab3bdc..f19f6fe2 100644 --- a/odcsim-core/src/main/kotlin/com/atlarge/odcsim/Time.kt +++ b/odcsim-core/src/main/kotlin/com/atlarge/odcsim/Time.kt @@ -33,3 +33,43 @@ typealias Instant = Double * A time interval which represents the amount of elapsed time between two messages. */ typealias Duration = Double + +/** + * Convert this [Int] into an [Instant]. + */ +fun Int.toInstant(): Instant = toDouble() + +/** + * Convert this [Int] into a [Duration]. + */ +fun Int.toDuration(): Duration = toDouble() + +/** + * Convert this [Long] into an [Instant]. + */ +fun Long.toInstant(): Instant = toDouble() + +/** + * Convert this [Long] into a [Duration]. + */ +fun Long.toDuration(): Duration = toDouble() + +/** + * Convert this [Float] into an [Instant]. + */ +fun Float.toInstant(): Instant = toDouble() + +/** + * Convert this [Float] into a [Duration]. + */ +fun Float.toDuration(): Duration = toDouble() + +/** + * Convert this [Double] into an [Instant]. + */ +fun Double.toInstant(): Instant = toDouble() + +/** + * Convert this [Double] into a [Duration]. + */ +fun Double.toDuration(): Duration = toDouble() -- cgit v1.2.3