diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2019-03-03 21:38:02 +0100 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2019-05-13 20:26:45 +0200 |
| commit | 1e18b15aee2d9184dc9b7537a9852a3f89fde67b (patch) | |
| tree | b8002fc33674d004425f78cfba6128ff4b1d6ad5 /odcsim-core | |
| parent | 3ed6c000c43842ccfd674c3a9c02aa27d76419bc (diff) | |
feat: Add conversion methods between number and time types
This change adds conversion methods from `Number` types into `Instant`
and `Duration` instances.
Diffstat (limited to 'odcsim-core')
| -rw-r--r-- | odcsim-core/src/main/kotlin/com/atlarge/odcsim/ActorRef.kt | 2 | ||||
| -rw-r--r-- | odcsim-core/src/main/kotlin/com/atlarge/odcsim/Time.kt | 40 |
2 files changed, 41 insertions, 1 deletions
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<in T : Any> { /** * 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() |
