<commit_before>package edu.stuy.starlorn.util;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.BufferedWriter;
import java.io.FileWriter;

public class HighScores {
    protected ScoreTree _scores;

    public HighScores() {
        _scores = new ScoreTree();
    }

    public void addScore(String name, long score) {
        _scores.add(new HighScore(name, score));
    }

    public HighScore[] getScoresSorted() {
        return _scores.getScoresSorted();
    }

    public void saveScores(String filename) {
        try {
            BufferedWriter w = new BufferedWriter(new FileWriter(filename));
            HighScore[] scores = getScoresSorted();
            for (int i = 0; i < scores.length; i++) {
                w.write(scores[i].getName().replace(":", "\\:")); //Escape colons
                w.write(" : "); // separator
                w.write("" + scores[i].getScore());
                w.newLine();
            }
            w.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void saveScores() {
        saveScores("scores.txt");
    }

    public void loadScores(String filename) {
        try {
            BufferedReader b = new BufferedReader(new FileReader(filename));
            while (b.ready()) {
                String[] data = b.readLine().split(" : ");
                String name = data[0].replace("\\:", ":"); // We'll escape their colons whilst saving, so unescape them whilst loading
                long score = Long.parseLong(data[1]);
                addScore(name, score);
            }
            b.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public void loadScores() {
        loadScores("scores.txt");
    }

    private class ScoreTree {
        private HighScore _val;
        private ScoreTree _left, _right;
        private int _size;

        public ScoreTree(HighScore score) {
            _val = score;
            _size = 1;
        }
        public ScoreTree() {
            this(null);
            _size = 0;
        }

        public void add(HighScore score) {<commit_msg>Add nice message if the highscores file doesn't exist<commit_after>package edu.stuy.starlorn.util;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.BufferedWriter;
import java.io.FileWriter;

public class HighScores {
    protected ScoreTree _scores;

    public HighScores() {
        _scores = new ScoreTree();
    }

    public void addScore(String name, long score) {
        _scores.add(new HighScore(name, score));
    }

    public HighScore[] getScoresSorted() {
        return _scores.getScoresSorted();
    }

    public void saveScores(String filename) {
        try {
            BufferedWriter w = new BufferedWriter(new FileWriter(filename));
            HighScore[] scores = getScoresSorted();
            for (int i = 0; i < scores.length; i++) {
                w.write(scores[i].getName().replace(":", "\\:")); //Escape colons
                w.write(" : "); // separator
                w.write("" + scores[i].getScore());
                w.newLine();
            }
            w.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void saveScores() {
        saveScores("scores.txt");
    }

    public void loadScores(String filename) {
        try {
            BufferedReader b = new BufferedReader(new FileReader(filename));
            while (b.ready()) {
                String[] data = b.readLine().split(" : ");
                String name = data[0].replace("\\:", ":"); // We'll escape their colons whilst saving, so unescape them whilst loading
                long score = Long.parseLong(data[1]);
                addScore(name, score);
            }
            b.close();
        } catch (java.io.IOException e) {
            System.out.println("No highscores file exists, so we'll make one later.");
        }
    }
    
    public void loadScores() {
        loadScores("scores.txt");
    }

    private class ScoreTree {
        private HighScore _val;
        private ScoreTree _left, _right;
        private int _size;

        public ScoreTree(HighScore score) {
            _val = score;
            _size = 1;
        }
        public ScoreTree() {
            this(null);
            _size = 0;
        }

        public void add(HighScore score) {
{'fraction_non_alphanumeric': 0.11952101220063263, 'fraction_numerical': 0.0022593764121102574, 'mean_word_length': 1.8036732108929703, 'pattern_counts': {'":': 4, '<': 5, '<?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': '4005392', 'n_tokens_mistral': 1294, 'n_tokens_neox': 1209, 'n_words': 304}