livingStoryId, filterSpec, focusedContentItemId, cutoff);
if (result != null) {
return result;
}
FilterSpec localFilterSpec = new FilterSpec(filterSpec);
BaseContentItem focusedContentItem = null;
if (focusedContentItemId != null) {
focusedContentItem = getContentItem(focusedContentItemId, false);
if (focusedContentItem != null) {
if (adjustFilterSpecForContentItem(localFilterSpec, focusedContentItem)) {
// If we had to adjust the filter spec to accommodate the focused content item,
// we'll be switching filter views, so we want to clear the start date
// and reload the list from the beginning.
cutoff = null;
}
}
}
// Some preliminaries. Note that the present implementation just filters all content items for
// a story, which could be a bit expensive if there's a cache miss. By and large, though,
// we'd expect a lot more cache hits than cache misses, unlike the case with, say,
// a twitter "following" feed, which is more likely to be unique to that user.
List<BaseContentItem> allContentItems = getContentItemsForLivingStory(livingStoryId, true);
Map<Long, BaseContentItem> idToContentItemMap = Maps.newHashMap();
List<BaseContentItem> relevantContentItems = Lists.newArrayList();
for (BaseContentItem contentItem : allContentItems) {
idToContentItemMap.put(contentItem.getId(), contentItem);
Date sortKey = contentItem.getDateSortKey();
boolean matchesStartDate = (cutoff == null) ||
(localFilterSpec.oldestFirst ? !sortKey.before(cutoff) : !sortKey.after(cutoff));
if (matchesStartDate && localFilterSpec.doesContentItemMatch(contentItem)) {
relevantContentItems.add(contentItem);
}
}
sortContentItemList(relevantContentItems, localFilterSpec);