<commit_before>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aha.data;

import java.io.File;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

/**
 *
 * @author simonicsanett
 */
public class FileSystemManager {

    private String fileName = "aha.xml";
    private ApplicationState applicationState;
    private static FileSystemManager instance;

    private FileSystemManager() {
        applicationState = new ApplicationState();
    }

    public static FileSystemManager getInstance() {
        if (instance == null) {
            instance = new FileSystemManager();
            instance.loadState();
        }
        return instance;
    }

    public void loadState() {
        try {
            File file = new File(fileName);
            System.out.println("Loading state from " + file.getAbsolutePath());

            JAXBContext jaxbContext = JAXBContext.newInstance(ApplicationState.class);
            Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
            applicationState = (ApplicationState) jaxbUnmarshaller.unmarshal(file);

        } catch (Exception ex) {
            System.out.println("Could not load application state");
            System.out.println(ex);
        }
    }

    public void saveState() {
        try {
            File file = new File(fileName);
            System.out.println("Saving state to " + file.getAbsolutePath());
            JAXBContext jaxbContext = JAXBContext.newInstance(ApplicationState.class);
            Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

            // output pretty printed
            jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

            jaxbMarshaller.marshal(applicationState, file);
            jaxbMarshaller.marshal(applicationState, System.out);

        } catch (JAXBException ex) {
            System.out.println("Could not save application state.");
            System.out.println(ex);
        }
    }

    public ApplicationState getState() {
        return applicationState;<commit_msg>Comments added<commit_after>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aha.data;

import java.io.File;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

/**
 *
 * @author simonicsanett
 */
public class FileSystemManager {

    private String fileName = "aha.xml";
    private ApplicationState applicationState;
    
    //Singleton pattern
    private static FileSystemManager instance;
    private FileSystemManager() {
        applicationState = new ApplicationState();
    }

    public static FileSystemManager getInstance() {
        if (instance == null) {
            instance = new FileSystemManager();
            instance.loadState();
        }
        return instance;
    }

    public void loadState() {
        try {
            File file = new File(fileName);
            System.out.println("Loading state from " + file.getAbsolutePath());

            JAXBContext jaxbContext = JAXBContext.newInstance(ApplicationState.class);
            Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
            applicationState = (ApplicationState) jaxbUnmarshaller.unmarshal(file);

        } catch (Exception ex) {
            System.out.println("Could not load application state");
            System.out.println(ex);
        }
    }

    public void saveState() {
        try {
            File file = new File(fileName);
            System.out.println("Saving state to " + file.getAbsolutePath());
            JAXBContext jaxbContext = JAXBContext.newInstance(ApplicationState.class);
            Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

            //Formatting output
            jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

            jaxbMarshaller.marshal(applicationState, file);
            jaxbMarshaller.marshal(applicationState, System.out);

        } catch (JAXBException ex) {
            System.out.println("Could not save application state.");
            System.out.println(ex);
        }
    }

    public ApplicationState getState() {
        return applicationState;
{'fraction_non_alphanumeric': 0.09075043630017451, 'fraction_numerical': 0.0, 'mean_word_length': 2.633122028526149, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, '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': '5817500', 'n_tokens_mistral': 1204, 'n_tokens_neox': 1208, 'n_words': 289}