Source:
public Optional<InsightCard.Category> generateGeneralInsights(final Long accountId, final Long deviceId, final Set<InsightCard.Category> recentCategories, final DateTime currentTime, final RolloutClient featureFlipper) { final Optional<InsightCard.Category> toGenerateWeeklyCategory = selectWeeklyInsightsToGenerate(accountId, recentCategories, currentTime); if (toGenerateWeeklyCategory.isPresent()) { LOGGER.debug("Trying to generate category insight for accountId {}", toGenerateWeeklyCategory, accountId); final Optional<InsightCard.Category> generatedWeeklyCategory = this.generateInsightsByCategory(accountId, deviceId, toGenerateWeeklyCategory.get()); if (generatedWeeklyCategory.isPresent()) { LOGGER.debug("Successfully generated category insight for accountId {}", generatedWeeklyCategory, accountId); return generatedWeeklyCategory; } } if (recentCategories.size() > NUM_INSIGHTS_ALLOWED_PER_WEEK) { return Optional.absent(); } final Optional<InsightCard.Category> toGenerateHighPriorityCategory = selectHighPriorityInsightToGenerate(accountId, recentCategories, currentTime, featureFlipper); if (toGenerateHighPriorityCategory.isPresent()) { LOGGER.debug("Trying to generate category insight for accountId {}", toGenerateHighPriorityCategory, accountId); final Optional<InsightCard.Category> generatedHighPriorityCategory = this.generateInsightsByCategory(accountId, deviceId, toGenerateHighPriorityCategory.get()); if (generatedHighPriorityCategory.isPresent()) { LOGGER.debug("Successfully generated category insight for accountId {}", generatedHighPriorityCategory, accountId); return generatedHighPriorityCategory; } } final Optional<InsightCard.Category> toGenerateRandomCategory = selectRandomOldInsightsToGenerate(accountId, recentCategories, currentTime); if (!toGenerateRandomCategory.isPresent()) { return Optional.absent(); } LOGGER.debug("Trying to generate category insight for accountId {}", toGenerateRandomCategory.get(), accountId); final Optional<InsightCard.Category> generatedRandomCategory = this.generateInsightsByCategory(accountId, deviceId, toGenerateRandomCategory.get()); if (generatedRandomCategory.isPresent()) { LOGGER.debug("Successfully generated category insight for accountId {}", generatedRandomCategory.get(), accountId); return generatedRandomCategory; } return Optional.absent(); }

Target:
public Optional<InsightCard.Category> generateGeneralInsights(final Long accountId, final Long deviceId, final Set<InsightCard.Category> recentCategories, final DateTime currentTime, final RolloutClient featureFlipper) { final Optional<InsightCard.Category> toGenerateWeeklyCategory = selectWeeklyInsightsToGenerate(accountId, recentCategories, currentTime); if (toGenerateWeeklyCategory.isPresent()) { LOGGER.debug("Trying to generate category insight for accountId {}", toGenerateWeeklyCategory.get(), accountId); final Optional<InsightCard.Category> generatedWeeklyCategory = this.generateInsightsByCategory(accountId, deviceId, toGenerateWeeklyCategory.get()); if (generatedWeeklyCategory.isPresent()) { LOGGER.debug("Successfully generated category insight for accountId {}", generatedWeeklyCategory.get(), accountId); return generatedWeeklyCategory; } } if (recentCategories.size() > NUM_INSIGHTS_ALLOWED_PER_WEEK) { return Optional.absent(); } final Optional<InsightCard.Category> toGenerateHighPriorityCategory = selectHighPriorityInsightToGenerate(accountId, recentCategories, currentTime, featureFlipper); if (toGenerateHighPriorityCategory.isPresent()) { LOGGER.debug("Trying to generate category insight for accountId {}", toGenerateHighPriorityCategory.get(), accountId); final Optional<InsightCard.Category> generatedHighPriorityCategory = this.generateInsightsByCategory(accountId, deviceId, toGenerateHighPriorityCategory.get()); if (generatedHighPriorityCategory.isPresent()) { LOGGER.debug("Successfully generated category insight for accountId {}", generatedHighPriorityCategory.get(), accountId); return generatedHighPriorityCategory; } } final Optional<InsightCard.Category> toGenerateRandomCategory = selectRandomOldInsightsToGenerate(accountId, recentCategories, currentTime); if (!toGenerateRandomCategory.isPresent()) { return Optional.absent(); } LOGGER.debug("Trying to generate category insight for accountId {}", toGenerateRandomCategory.get(), accountId); final Optional<InsightCard.Category> generatedRandomCategory = this.generateInsightsByCategory(accountId, deviceId, toGenerateRandomCategory.get()); if (generatedRandomCategory.isPresent()) { LOGGER.debug("Successfully generated category insight for accountId {}", generatedRandomCategory.get(), accountId); return generatedRandomCategory; } return Optional.absent(); }