Source:
public AppUnreadStats unread(@Scope(OAuthScope.APP_STATS) final AccessToken accessToken) { final Long accountId = accessToken.accountId; final Optional<DateTime> insightsLastViewed = appStatsDAO.getInsightsLastViewed(accountId); final Optional<Boolean> hasUnreadInsights = insightsLastViewed.transform(new Function<DateTime, Boolean>() { @Override public Boolean apply(DateTime insightsLastViewed) { final Boolean chronological = false; final DateTime queryDate = DateTime.now(DateTimeZone.UTC).plusDays(1); final ImmutableList<InsightCard> insights = insightsDAO.getInsightsByDate(accountId, queryDate, chronological, 1); return (!insights.isEmpty() && insights.get(0).timestamp.isAfter(insightsLastViewed)); } }); final Optional<Integer> accountAgeInDays = getAccountAgeInDays(accountId); final Optional<DateTime> questionsLastViewed = appStatsDAO.getQuestionsLastViewed(accountId); final Optional<Boolean> hasUnansweredQuestions = accountAgeInDays.transform(new Function<Integer, Boolean>() { @Override public Boolean apply(Integer accountAgeInDays) { final int timeZoneOffset = getTimeZoneOffsetMillis(accountId); final DateTime today = DateTime.now(DateTimeZone.UTC).plusMillis(timeZoneOffset).withTimeAtStartOfDay(); final List<Question> questions = questionProcessor.getQuestions(accountId, accountAgeInDays, today, QuestionProcessor.DEFAULT_NUM_QUESTIONS, true); if (questionsLastViewed.isPresent()) { final DateTime lastViewed = questionsLastViewed.get(); for (final Question question : questions) { if (!question.created.isPresent()) { continue; } if (question.created.get().isAfter(lastViewed)) { return true; } } return false; } else { return !questions.isEmpty(); } } }); return new AppUnreadStats(hasUnreadInsights.or(false), hasUnansweredQuestions.or(false)); }

Target:
public AppUnreadStats unread(@Scope(OAuthScope.APP_STATS) final AccessToken accessToken) { final Long accountId = accessToken.accountId; final Optional<DateTime> insightsLastViewed = appStatsDAO.getInsightsLastViewed(accountId); final Optional<Boolean> hasUnreadInsights = insightsLastViewed.transform(new Function<DateTime, Boolean>() { @Override public Boolean apply(DateTime insightsLastViewed) { final Boolean chronological = false; final DateTime queryDate = DateTime.now(DateTimeZone.UTC).plusDays(1); final ImmutableList<InsightCard> insights = insightsDAO.getInsightsByDate(accountId, queryDate, chronological, 1); return (!insights.isEmpty() && insights.get(0).timestamp.isAfter(insightsLastViewed)); } }); final Optional<Integer> accountAgeInDays = getAccountAgeInDays(accountId); final Optional<DateTime> questionsLastViewed = appStatsDAO.getQuestionsLastViewed(accountId); final Optional<Boolean> hasUnansweredQuestions = accountAgeInDays.transform(new Function<Integer, Boolean>() { @Override public Boolean apply(Integer accountAgeInDays) { final int timeZoneOffset = getTimeZoneOffsetMillis(accountId); final DateTime today = DateTime.now(DateTimeZone.UTC).plusMillis(timeZoneOffset).withTimeAtStartOfDay(); final List<Question> questions = questionProcessor.getQuestions(accountId, accountAgeInDays, today, QuestionProcessor.DEFAULT_NUM_QUESTIONS, true); if (questionsLastViewed.isPresent()) { final DateTime lastViewed = questionsLastViewed.get(); for (final Question question : questions) { if (question.accountCreationDate.isAfter(lastViewed)) { return true; } } return false; } return !questions.isEmpty(); } }); return new AppUnreadStats(hasUnreadInsights.or(false), hasUnansweredQuestions.or(false)); }