<commit_before>package com.wsfmn.habittracker;


import android.content.Context;
import android.os.AsyncTask;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;



/**
 * Created by Fredric on 2017-10-16.
 * Updated with GSON by Nicholas on 2017-10-25.
 */

public class OfflineController {
    private static final String HABITLIST_FILENAME = "HabitList.sav";
    private static final String HABITHISTORY_FILENAME = "HabitHistory.sav";


    public static class StoreHabitList extends AsyncTask<HabitList, Void, Void> {

        @Override
        protected Void doInBackground(HabitList... habitList) {
            Context context = App.context;
            try {
                FileOutputStream fos = context.openFileOutput(HABITLIST_FILENAME, 0);
                OutputStreamWriter writer = new OutputStreamWriter(fos);
                GsonBuilder builder = new GsonBuilder();
                Gson gson = builder.create();
                builder.serializeNulls();
                gson.toJson(habitList, writer);
                writer.flush();
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                throw new RuntimeException();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                throw new RuntimeException();
            }
            return null;
        }
    }


    public static class GetHabitList extends AsyncTask<Void, Void, HabitList> {

        @Override
        protected HabitList doInBackground(Void... params) {
            Context context = App.context;
            HabitList[] habitList;
            try {
                FileInputStream fis = context.openFileInput(HABITLIST_FILENAME);
                BufferedReader in = new BufferedReader(new InputStreamReader(fis));
                Gson gson = new Gson();
                habitList = gson.fromJson(in, HabitList[].class);
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                habitList = new HabitList[1];
            }
            return habitList[0];
        }
    }


    public static class StoreHabitHistory extends AsyncTask<HabitHistory, Void, Void> {

        @Override
        protected Void doInBackground(HabitHistory... habitHistory) {
            Context context = App.context;
            try {
                FileOutputStream fos = context.openFileOutput(HABITHISTORY_FILENAME, 0);
                OutputStreamWriter writer = new OutputStreamWriter(fos);
                GsonBuilder builder = new GsonBuilder();
                Gson gson = builder.create();
                builder.serializeNulls();
                gson.toJson(habitHistory, writer);
                writer.flush();
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                throw new RuntimeException();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                throw new RuntimeException();<commit_msg>fixed null array bug in GetHabitList in OfflineController<commit_after>package com.wsfmn.habittracker;


import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;



/**
 * Created by Fredric on 2017-10-16.
 * Updated with GSON by Nicholas on 2017-10-25.
 */

public class OfflineController {
    private static final String HABITLIST_FILENAME = "HabitList.sav";
    private static final String HABITHISTORY_FILENAME = "HabitHistory.sav";


    public static class StoreHabitList extends AsyncTask<HabitList, Void, Void> {

        @Override
        protected Void doInBackground(HabitList... habitList) {
            Context context = App.context;
            try {
                FileOutputStream fos = context.openFileOutput(HABITLIST_FILENAME, 0);
                OutputStreamWriter writer = new OutputStreamWriter(fos);
                GsonBuilder builder = new GsonBuilder();
                Gson gson = builder.create();
                builder.serializeNulls();
                gson.toJson(habitList, writer);
                writer.flush();
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                throw new RuntimeException();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                throw new RuntimeException();
            }
            return null;
        }
    }


    public static class GetHabitList extends AsyncTask<Void, Void, HabitList> {

        @Override
        protected HabitList doInBackground(Void... params) {
            Context context = App.context;
            HabitList[] habitList;
            try {
                FileInputStream fis = context.openFileInput(HABITLIST_FILENAME);
                BufferedReader in = new BufferedReader(new InputStreamReader(fis));
                Gson gson = new Gson();
                habitList = gson.fromJson(in, HabitList[].class);
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                Log.d("FileNotfound", e.getMessage());
                habitList = new HabitList[1];
                habitList[0] = new HabitList();
            }
            return habitList[0];
        }
    }


    public static class StoreHabitHistory extends AsyncTask<HabitHistory, Void, Void> {

        @Override
        protected Void doInBackground(HabitHistory... habitHistory) {
            Context context = App.context;
            try {
                FileOutputStream fos = context.openFileOutput(HABITHISTORY_FILENAME, 0);
                OutputStreamWriter writer = new OutputStreamWriter(fos);
                GsonBuilder builder = new GsonBuilder();
                Gson gson = builder.create();
                builder.serializeNulls();
                gson.toJson(habitHistory, writer);
                writer.flush();
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                throw new RuntimeException();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                throw new RuntimeException();
{'fraction_non_alphanumeric': 0.08133333333333333, 'fraction_numerical': 0.006074074074074074, 'mean_word_length': 2.021933751119069, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '936602', 'n_tokens_mistral': 1807, 'n_tokens_neox': 1659, 'n_words': 435}