private void addBroadcast(Version version, Broadcast newBroadcast) { if (Strings.isNullOrEmpty(newBroadcast.getSourceId())) { return; } Set<Broadcast> broadcasts = Sets.newHashSet(); Interval newBroadcastInterval = newBroadcast.transmissionInterval().requireValue(); for (Broadcast existingBroadcast : version.getBroadcasts()) { if (newBroadcast.getSourceId().equals(existingBroadcast.getSourceId())) { continue; } if (existingBroadcast.transmissionInterval().hasValue()) { Interval currentInterval = existingBroadcast.transmissionInterval().requireValue(); if (existingBroadcast.getBroadcastOn().equals(newBroadcast.getBroadcastOn()) && currentInterval.overlaps(newBroadcastInterval)) { continue; } } broadcasts.add(existingBroadcast); } broadcasts.add(newBroadcast); version.setBroadcasts(broadcasts); }
private void updateSchedule(Item item) { Iterable<Broadcast> broadcasts = Iterables.concat(Iterables.transform(item.getVersions(), Version.TO_BROADCASTS)); for (Broadcast broadcast : broadcasts) { Maybe<Channel> channel = channelResolver.fromUri(broadcast.getBroadcastOn()); if (channel.hasValue()) { scheduleWriter.replaceScheduleBlock( item.getPublisher(), channel.requireValue(), ImmutableSet.of(new ScheduleEntry.ItemRefAndBroadcast(item, broadcast))); } } }