Source:
private Channel createOrMerge(Channel newChannel) { String alias = null; for (String newAlias : newChannel.getAliasUrls()) { if (isPaAlias(newAlias)) { alias = newAlias; break; } } checkNotNull(alias, "channel with uri " + newChannel.getCanonicalUri() + " has no aliases"); Maybe<Channel> existing = channelResolver.forAlias(alias); if (existing.hasValue()) { Channel existingChannel = existing.requireValue(); existingChannel.setImages( Iterables.isEmpty(existingChannel.getAllImages()) ? newChannel.getAllImages() : updateImages(newChannel, existingChannel) ); existingChannel.setImages(updateImages(newChannel, existingChannel)); existingChannel.setTitles(newChannel.getAllTitles()); existingChannel.setAdult(newChannel.getAdult()); existingChannel.setStartDate(newChannel.getStartDate()); existingChannel.setEndDate(newChannel.getEndDate()); existingChannel.setRelatedLinks(newChannel.getRelatedLinks()); existingChannel.setAliasUrls(mergeChannelAliasUrls( existingChannel.getAliasUrls(), newChannel.getAliasUrls() )); existingChannel.setParent(newChannel.getParent()); existingChannel.setMediaType(newChannel.getMediaType()); existingChannel.setHighDefinition(newChannel.getHighDefinition()); existingChannel.setRegional(newChannel.getRegional()); existingChannel.setTimeshift(newChannel.getTimeshift()); existingChannel.setGenres(newChannel.getGenres()); existingChannel.setAvailableFrom(Sets.union( existingChannel.getAvailableFrom(), newChannel.getAvailableFrom() )); existingChannel.setChannelNumbers(Sets.union( newChannel.getChannelNumbers(), Sets.newHashSet( numberingFilterer.filterNotEqualToGroupPublisher( existingChannel.getChannelNumbers(), Publisher.METABROADCAST ) ) )); existingChannel.addAliases(newChannel.getAliases()); return channelWriter.createOrUpdate(existingChannel); } else { return channelWriter.createOrUpdate(newChannel); } }

Target:
private Channel createOrMerge(Channel newChannel) { String alias = null; for (String newAlias : newChannel.getAliasUrls()) { if (isPaAlias(newAlias)) { alias = newAlias; break; } } checkNotNull(alias, "channel with uri " + newChannel.getCanonicalUri() + " has no aliases"); Maybe<Channel> existing = channelResolver.forAlias(alias); if (existing.hasValue()) { Channel existingChannel = existing.requireValue(); if (!Iterables.isEmpty(newChannel.getAllImages())) { if (!Iterables.isEmpty(existingChannel.getAllImages())) { existingChannel.setImages(updateImages(newChannel, existingChannel)); } else { existingChannel.setImages(newChannel.getAllImages()); } } existingChannel.setTitles(newChannel.getAllTitles()); existingChannel.setAdult(newChannel.getAdult()); existingChannel.setStartDate(newChannel.getStartDate()); existingChannel.setEndDate(newChannel.getEndDate()); existingChannel.setRelatedLinks(newChannel.getRelatedLinks()); existingChannel.setAliasUrls(mergeChannelAliasUrls( existingChannel.getAliasUrls(), newChannel.getAliasUrls() )); existingChannel.setParent(newChannel.getParent()); existingChannel.setMediaType(newChannel.getMediaType()); existingChannel.setHighDefinition(newChannel.getHighDefinition()); existingChannel.setRegional(newChannel.getRegional()); existingChannel.setTimeshift(newChannel.getTimeshift()); existingChannel.setGenres(newChannel.getGenres()); existingChannel.setAvailableFrom(Sets.union( existingChannel.getAvailableFrom(), newChannel.getAvailableFrom() )); existingChannel.setChannelNumbers(Sets.union( newChannel.getChannelNumbers(), Sets.newHashSet( numberingFilterer.filterNotEqualToGroupPublisher( existingChannel.getChannelNumbers(), Publisher.METABROADCAST ) ) )); existingChannel.addAliases(newChannel.getAliases()); return channelWriter.createOrUpdate(existingChannel); } else { return channelWriter.createOrUpdate(newChannel); } }