Created
March 2, 2018 19:39
-
-
Save alorma/8d49b40792405732e383d26d10287813 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DelayedTimeProvider(private val timeProvider: TimeProvider, | |
private val delayed: Delayed) : TimeProvider { | |
override fun getTime(): Long = timeProvider.getTime() + delayed.get() | |
} | |
data class Delayed(private val time: Long, private val unit: TimeUnit) { | |
fun get() = unit.toMillis(time) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface TimeProvider { | |
fun getTime(): Long | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TimeToLive(private val ttlTime: Long, private val unit: TimeUnit, private val timeProvider: TimeProvider) { | |
fun isValid(time: Long): Boolean = (timeProvider.now() - time) <= unit.toMillis(ttlTime) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment