Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package uk.co.optimisticpanda.atom;
 
 import java.util.List;
 
 
 
public class FeedTraverser {
    private final Predicate<EntrystopPredicate;
    private final EntryVisitor visitor;
    private final Predicate<EntryentriesMatching;
    private final FeedReader reader;
    private final Ordering<EntrylatestToEarliest;
    FeedTraverser(Predicate<EntrystopPredicateEntryVisitor visitorFeedReader readerPredicate<EntryentrysMatchingOrdering<EntrylatestToEarliest) {
        this. = stopPredicate;
        this. = visitor;
        this. = reader;
        this. = entrysMatching;
        this. = latestToEarliest;
    }

    
Traverse a feed found at location. Location maybe a url, file system location, string etc.... The actual meaning of this is determined by the underlying uk.co.optimisticpanda.atom.reader.FeedReader.
    public void traverse(String location) {
        backwardsTraverse(.load(location));
    }
    // Traverse back through the archive from latest to earliest
    private void backwardsTraverse(Feed feed) {
        boolean stopped = false;
        List<EntryseenEntries = Lists.newArrayList();
        
        for (Entry entry : .sortedCopy(feed.getEntries())) {
            if (.apply(entry)) {
                stopped = true;
                break;
            }
            seenEntries.add(entry);
        }
        if (stopped) {
            for (Entry seenEntry : Lists.reverse(seenEntries)) {
                if (.apply(seenEntry)) {
                    .visit(seenEntry);
                }
            }
            Optional<Feednext = .getNextArchive(feed);
            if (next.isPresent()) {
                forwardsTraverse(next.get());
            }
            return;
        }
        Optional<Feedprevious = .getPreviousArchive(feed);
        if (previous.isPresent()) {
            backwardsTraverse(previous.get());
        } else {
            forwardsTraverse(feed);
        }
    }
    // Traverse forwards through the feed from earliest to latest.
    private void forwardsTraverse(Feed feed) {
        for (Entry entry : Lists.reverse(.sortedCopy(feed.getEntries()))) {
            if (.apply(entry)) {
                .visit(entry);
            }
        }
        Optional<Feednext = .getNextArchive(feed);
        if (next.isPresent()) {
            forwardsTraverse(next.get());
        }
    }
New to GrepCode? Check out our FAQ X