From 44cf7e2699e1a98263d2ac8e3cfdef16e52b0394 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 27 May 2016 07:29:07 +0200 Subject: [PATCH] wetter.com state can iterate over its hour states --- .../rhynodge/webpages/weather/wettercom/WetterComState.kt | 6 +++++- .../rhynodge/webpages/weather/wettercom/WetterComStateTest.kt | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/net/pterodactylus/rhynodge/webpages/weather/wettercom/WetterComState.kt b/src/main/kotlin/net/pterodactylus/rhynodge/webpages/weather/wettercom/WetterComState.kt index 1181406..59147eb 100644 --- a/src/main/kotlin/net/pterodactylus/rhynodge/webpages/weather/wettercom/WetterComState.kt +++ b/src/main/kotlin/net/pterodactylus/rhynodge/webpages/weather/wettercom/WetterComState.kt @@ -8,7 +8,7 @@ import java.time.ZonedDateTime * * @author [David ‘Bombe’ Roden](mailto:bombe@pterodactylus.net) */ -class WetterComState(val dateTime: ZonedDateTime) : AbstractState(true) { +class WetterComState(val dateTime: ZonedDateTime) : AbstractState(true), Iterable { val hours: List = mutableListOf() @@ -16,6 +16,10 @@ class WetterComState(val dateTime: ZonedDateTime) : AbstractState(true) { (hours as MutableList).add(hourState) } + override fun iterator(): Iterator { + return hours.iterator() + } + override fun equals(other: Any?): Boolean { other as? WetterComState ?: return false return (dateTime == other.dateTime) and (hours == other.hours) diff --git a/src/test/kotlin/net/pterodactylus/rhynodge/webpages/weather/wettercom/WetterComStateTest.kt b/src/test/kotlin/net/pterodactylus/rhynodge/webpages/weather/wettercom/WetterComStateTest.kt index c67b82b..e6ab943 100644 --- a/src/test/kotlin/net/pterodactylus/rhynodge/webpages/weather/wettercom/WetterComStateTest.kt +++ b/src/test/kotlin/net/pterodactylus/rhynodge/webpages/weather/wettercom/WetterComStateTest.kt @@ -34,4 +34,13 @@ class WetterComStateTest { assertThat(firstState, `is`(secondState)) } + @Test + fun iteratingDeliversHourStates() { + val now = Instant.now().atZone(ZoneId.of("UTC")) + val firstState = WetterComState(ZonedDateTime.from(now)) + firstState.addHour(HourState(0, 10.0, 0.05, 0.0, WindDirection.NORTH, 5.0, "Fine", "http://1")) + firstState.addHour(HourState(1, 12.0, 0.1, 2.0, WindDirection.WEST, 8.0, "Superb", "http://2")) + assertThat(firstState.iterator().asSequence().toList(), `is`(firstState.hours as Iterable)) + } + } -- 2.7.4