<commit_before>package be.cegeka.softwaresandbox;

import org.apache.abdera.Abdera;
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.Feed;
import org.apache.abdera.model.Link;
import org.apache.abdera.parser.Parser;

import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Collections;
import java.util.List;

import static java.lang.Thread.sleep;

public class AtomPoller {

    public AtomPoller() throws IOException, InterruptedException {
        Link last = null;

        while (last == null) {
            last = getLastLink("http://127.0.0.1:2113/streams/fiangular");
            if(last == null) {
                sleep(1000);
            }
        }

        while (true) {
            Link current = readPrevious(last);
            if (current.getHref() == last.getHref()) {
                sleep(1000);
            }
            last = current;
        }
    }

    private Link getLastLink(String url) throws IOException {
        Feed feed = getFeed("admin", "changeit", url);
        Link last = feed.getLink("last");
        return last == null ? feed.getLink("self") : last;
    }

    private Feed getFeed(String username, String password, String url) throws IOException {
        URLConnection uc = new URL(url).openConnection();
//        String userpass = username + ":" + password;
//        String basicAuth = "Basic " + new String(Base64.getEncoder().encode(userpass.getBytes()));
//        uc.setRequestProperty("Authorization", basicAuth);
        uc.setRequestProperty("Accept", "application/atom+xml");

        Abdera abdera = new Abdera();
        Parser parser = abdera.getParser();
        Document<Feed> doc = parser.parse(uc.getInputStream(), url.toString());
        return doc.getRoot();
    }


    private Link readPrevious(Link link) throws IOException {
        Feed feed = getFeed("admin", "changeit", link.getHref().toString());
        List<Entry> entries = feed.getEntries();
        Collections.reverse(new ArrayList(entries));
        for (Entry entry : entries) {
            System.out.println(entry.getTitle());
        }
        Link previous = feed.getLink("previous");
        return previous == null ? link : previous;
    }

    public static void main(String[] args) throws IOException, InterruptedException {
        new AtomPoller();
    }
}<commit_msg>atompoller implementatie fix order of events<commit_after>package be.cegeka.softwaresandbox;

import org.apache.abdera.Abdera;
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.Feed;
import org.apache.abdera.model.Link;
import org.apache.abdera.parser.Parser;

import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Collections;
import java.util.List;

import static java.lang.Thread.sleep;

public class AtomPoller {

    public AtomPoller() throws IOException, InterruptedException {
        Link last = null;

        while (last == null) {
            last = getLastLink("http://127.0.0.1:2113/streams/fiangular");
            if(last == null) {
                sleep(1000);
            }
        }

        while (true) {
            Link current = readPrevious(last);
            if (current.getHref() == last.getHref()) {
                sleep(1000);
            }
            last = current;
        }
    }

    private Link getLastLink(String url) throws IOException {
        Feed feed = getFeed("admin", "changeit", url);
        Link last = feed.getLink("last");
        return last == null ? feed.getLink("self") : last;
    }

    private Feed getFeed(String username, String password, String url) throws IOException {
        URLConnection uc = new URL(url).openConnection();
//        String userpass = username + ":" + password;
//        String basicAuth = "Basic " + new String(Base64.getEncoder().encode(userpass.getBytes()));
//        uc.setRequestProperty("Authorization", basicAuth);
        uc.setRequestProperty("Accept", "application/atom+xml");

        Abdera abdera = new Abdera();
        Parser parser = abdera.getParser();
        Document<Feed> doc = parser.parse(uc.getInputStream(), url.toString());
        return doc.getRoot();
    }


    private Link readPrevious(Link link) throws IOException {
        Feed feed = getFeed("admin", "changeit", link.getHref().toString());
        List<Entry> entries = new ArrayList(feed.getEntries());
        Collections.reverse(entries);
        for (Entry entry : entries) {
            System.out.println(entry.getTitle());
        }
        Link previous = feed.getLink("previous");
        return previous == null ? link : previous;
    }

    public static void main(String[] args) throws IOException, InterruptedException {
        new AtomPoller();
    }
}
{'fraction_non_alphanumeric': 0.12497480346704294, 'fraction_numerical': 0.008869179600886918, 'mean_word_length': 2.6864784546805347, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2492330', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1387, 'n_words': 323}