From f9ebfb4dc294951f35b3d0322f84aada2ab6eb2f Mon Sep 17 00:00:00 2001 From: Florent Biville Date: Wed, 20 Feb 2013 01:00:50 +0100 Subject: [PATCH] Issue #93. Handle when there is no current broadcast for the given channel. --- .../tv/esporx/services/TimelineService.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/tv/esporx/services/TimelineService.java b/src/main/java/tv/esporx/services/TimelineService.java index b39ccd4..529fed3 100644 --- a/src/main/java/tv/esporx/services/TimelineService.java +++ b/src/main/java/tv/esporx/services/TimelineService.java @@ -11,6 +11,8 @@ import tv.esporx.repositories.OccurrenceRepository; import tv.esporx.services.timeline.Timeline; +import java.util.NoSuchElementException; + import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.collect.Iterables.find; @@ -33,12 +35,17 @@ public Timeline getTimeline(DateTime start, DateTime end) { public Occurrence findCurrentBroadcastByChannel(final Channel channel) { DateTime start = toStartHour(new DateTime()); Timeline timeline = this.getTimeline(start, start.plusHours(1)); - return find(timeline.perHourMultimap().values(), new Predicate() { - @Override - public boolean apply(Occurrence input) { - return input.getChannels().contains(channel); - } - }); + try { + return find(timeline.perHourMultimap().values(), new Predicate() { + @Override + public boolean apply(Occurrence input) { + return input.getChannels().contains(channel); + } + }); + } + catch (NoSuchElementException e) { + return null; + } } private void checkSanity(DateTime startDay, DateTime endDay) {