<commit_before>package in.twizmwaz.cardinal;

import org.bukkit.OfflinePlayer;
import org.jdom2.Attribute;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.UUID;

public final class Database {
    
    private final Document document;

    private Database(Document document) {
        this.document = document;
    }
    
    private Database() {
        this.document = new Document(new Element("database"));
    }
    
    public static Database newInstance(File file) {
        Database newDatabase = new Database();
        newDatabase.save(file);
        return newDatabase;
    }
    
    public static Database loadFromFile(File file) throws JDOMException, IOException {
        SAXBuilder saxBuilder = new SAXBuilder();
        return new Database(saxBuilder.build(file));
    }
    
    public boolean save(File file) {
        XMLOutputter outputter = new XMLOutputter();
        outputter.setFormat(Format.getPrettyFormat());
        try {
            outputter.output(document, new FileWriter(file));
            return true;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }
    
    public void put(OfflinePlayer player, String key, String value) {
        getKey(getPlayerElement(player), key).setAttribute("value", value);
    }
    
    public String get(OfflinePlayer player, String key) {
        return getKey(getPlayerElement(player), key).getAttributeValue("value");<commit_msg>Fix database file not being created on first start<commit_after>package in.twizmwaz.cardinal;

import org.bukkit.OfflinePlayer;
import org.jdom2.Attribute;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.UUID;

public final class Database {
    
    private final Document document;

    private Database(Document document) {
        this.document = document;
    }
    
    private Database() {
        this.document = new Document(new Element("database"));
    }
    
    public static Database newInstance(File file) {
        Database newDatabase = new Database();
        newDatabase.save(file);
        return newDatabase;
    }
    
    public static Database loadFromFile(File file) throws JDOMException, IOException {
        SAXBuilder saxBuilder = new SAXBuilder();
        return new Database(saxBuilder.build(file));
    }
    
    public boolean save(File file) {
        XMLOutputter out = new XMLOutputter();
        out.setFormat(Format.getPrettyFormat());
        try {
            if (file.createNewFile()) {
                out.output(document, new FileWriter(file));
                return true;
            } else return false;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }
    
    public void put(OfflinePlayer player, String key, String value) {
        getKey(getPlayerElement(player), key).setAttribute("value", value);
    }
    
    public String get(OfflinePlayer player, String key) {
        return getKey(getPlayerElement(player), key).getAttributeValue("value");
{'fraction_non_alphanumeric': 0.09512893982808023, 'fraction_numerical': 0.0040114613180515755, 'mean_word_length': 2.848952590959206, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '3427475', 'n_tokens_mistral': 988, 'n_tokens_neox': 963, 'n_words': 238}