<commit_before>package org.openstreetmap.josm.plugins.notes;

import java.io.IOException;
import java.io.StringReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.openstreetmap.josm.data.coor.LatLon;
import org.openstreetmap.josm.data.osm.User;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;

public class NotesXmlParser extends DefaultHandler {
    private String chars;

    private final static SimpleDateFormat NOTE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z", Locale.ENGLISH);

    private List<Note> notes = new ArrayList<Note>(100);
    private Note thisNote;

    private Date commentCreateDate;
    private String commentUsername;
    private long commentUid;
    private String commentText;

    @Override
    public void characters(char[] ch, int start, int length) throws SAXException {
        chars = new String(ch, start, length);
    }

    @Override
    public void endElement(String uri, String localName, String qName) throws SAXException {
        if ("id".equals(qName)) {
            thisNote.setId(Long.parseLong(chars));
        } else if ("status".equals(qName)) {
            thisNote.setState(Note.State.valueOf(chars));
        } else if ("url".equals(qName)) {
        	thisNote.setNoteUrl(chars);
        } else if ("date_created".equals(qName)) {
            // Note create date
            try {
                thisNote.setCreatedAt(NOTE_DATE_FORMAT.parse(chars));
            } catch (ParseException e) {
                System.err.println("Could not parse note date from API: \"" + chars + "\":");
                e.printStackTrace();
            }
        } else if ("note".equals(qName)) {
            notes.add(thisNote);
        } else if ("date".equals(qName)) {
            // Comment create date
            try {
                commentCreateDate = NOTE_DATE_FORMAT.parse(chars);
            } catch (ParseException e) {
                System.err.println("Could not parse comment date from API: \"" + chars + "\":");
                e.printStackTrace();
            }
        } else if ("user".equals(qName)) {
            commentUsername = chars;
        } else if ("uid".equals(qName)) {
            commentUid = Long.parseLong(chars);
        } else if ("text".equals(qName)) {
            commentText = chars;
        } else if ("comment".equals(qName)) {
            User commentUser = User.createOsmUser(commentUid, commentUsername);
            thisNote.addComment(thisNote.new Comment(commentCreateDate, commentUser, commentText));
        }
    }

    @Override
    public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
        if ("note".equals(qName)) {
            double lat = Double.parseDouble(attrs.getValue("lat"));<commit_msg>Reset the comment data so we don't wipe out anonymous comments.<commit_after>package org.openstreetmap.josm.plugins.notes;

import java.io.IOException;
import java.io.StringReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.openstreetmap.josm.data.coor.LatLon;
import org.openstreetmap.josm.data.osm.User;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;

public class NotesXmlParser extends DefaultHandler {
    private String chars;

    private final static SimpleDateFormat NOTE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z", Locale.ENGLISH);

    private List<Note> notes = new ArrayList<Note>(100);
    private Note thisNote;

    private Date commentCreateDate;
    private String commentUsername;
    private long commentUid;
    private String commentText;

    @Override
    public void characters(char[] ch, int start, int length) throws SAXException {
        chars = new String(ch, start, length);
    }

    @Override
    public void endElement(String uri, String localName, String qName) throws SAXException {
        if ("id".equals(qName)) {
            thisNote.setId(Long.parseLong(chars));
        } else if ("status".equals(qName)) {
            thisNote.setState(Note.State.valueOf(chars));
        } else if ("url".equals(qName)) {
        	thisNote.setNoteUrl(chars);
        } else if ("date_created".equals(qName)) {
            // Note create date
            try {
                thisNote.setCreatedAt(NOTE_DATE_FORMAT.parse(chars));
            } catch (ParseException e) {
                System.err.println("Could not parse note date from API: \"" + chars + "\":");
                e.printStackTrace();
            }
        } else if ("note".equals(qName)) {
            notes.add(thisNote);
        } else if ("date".equals(qName)) {
            // Comment create date
            try {
                commentCreateDate = NOTE_DATE_FORMAT.parse(chars);
            } catch (ParseException e) {
                System.err.println("Could not parse comment date from API: \"" + chars + "\":");
                e.printStackTrace();
            }
        } else if ("user".equals(qName)) {
            commentUsername = chars;
        } else if ("uid".equals(qName)) {
            commentUid = Long.parseLong(chars);
        } else if ("text".equals(qName)) {
            commentText = chars;
        } else if ("comment".equals(qName)) {
            User commentUser = User.createOsmUser(commentUid, commentUsername);
            thisNote.addComment(thisNote.new Comment(commentCreateDate, commentUser, commentText));
            commentUid = 0;
            commentUsername = null;
            commentCreateDate = null;
            commentText = null;
        }
    }

    @Override
    public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
        if ("note".equals(qName)) {
            double lat = Double.parseDouble(attrs.getValue("lat"));
{'fraction_non_alphanumeric': 0.11185819070904646, 'fraction_numerical': 0.001069682151589242, 'mean_word_length': 2.7103174603174605, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 16}, 'pii_count': 0, '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': '7057847', 'n_tokens_mistral': 1867, 'n_tokens_neox': 1817, 'n_words': 427}