<commit_before>package com.andela.notelib.note;


import android.content.Context;

import com.andela.notelib.util.Settings;

public class NoteManager {
    public static final int NOTES = 0;
    public static final int TRASH = 1;

    private String COUNT = "count";
    private int counter;
    private NoteDBWriter<Note> noteDBWriter;
    private NoteList<Note> notes = new NoteList<>();
    private NoteList<Note> trashNotes = new NoteList<>();
    private Context context;

    public NoteManager(Context context, String tableName) throws Exception {
        this.noteDBWriter = new NoteDBWriter<>(tableName);
        this.notes.addAllOrderedNote(this.noteDBWriter.selectAllNote(NOTES));
        this.trashNotes.addAllOrderedNote(this.noteDBWriter.selectAllNote(TRASH));

        this.COUNT += tableName;
        this.context = context;
        counter = getCounter();
    }

    public void saveNote(Note note) {
        note.setId(counter);
        note.setTrash(NOTES);
        this.notes.addOrderedNote(note);
        this.noteDBWriter.insertNote(note);
        counter++;
        saveCounter(counter);
    }

    public void updateNote(Note note) {
        this.notes.updateNote(note);
        this.noteDBWriter.updateNote(note);
    }

    public boolean containsNote(Note note) {
        return this.notes.containsNote(note);
    }

    public void moveNoteToTrash(Note note) {
        this.notes.removeNote(note);
        note.setTrash(TRASH);
        this.trashNotes.addOrderedNote(note);
        this.noteDBWriter.updateNote(note);
    }

    public void restoreNoteFromTrash(Note note) {
        this.trashNotes.removeNote(note);
        note.setTrash(NOTES);
        this.notes.addOrderedNote(note);
        this.noteDBWriter.updateNote(note);
    }

    public void deleteFromTrash(Note note) {
        this.trashNotes.removeNote(note);
        this.noteDBWriter.deleteNote(note.getId());
    }

    public void deleteNote(Note note) {
        this.trashNotes.removeNote(note);
        this.notes.removeNote(note);
        this.noteDBWriter.deleteNote(note.getId());
    }

    public void deleteAllTrash() {
        this.trashNotes.clear();
        this.noteDBWriter.deleteAlNote(TRASH);
    }

    public void deleteAll() {
        this.notes.clear();
        this.trashNotes.clear();
        this.noteDBWriter.deleteAlNote(NOTES);
        this.noteDBWriter.deleteAlNote(TRASH);
    }

    public NoteList<Note> getAllNotes() {
        return this.notes;
    }

    public NoteList<Note> getAllTrashNotes() {
        return this.trashNotes;
    }

    public Note getNote(Note note) {
        return this.notes.getNote(note.getId());<commit_msg>Refactor NoteManager Class<commit_after>package com.andela.notelib.note;


import android.content.Context;

import com.andela.notelib.util.Settings;
import com.andela.notelib.util.SortById;

import java.util.Collections;

public class NoteManager {
    public static final int NOTES = 0;
    public static final int TRASH = 1;

    private String COUNT = "count";
    private int counter;
    private NoteDBWriter<Note> noteDBWriter;
    private NoteList<Note> notes = new NoteList<>();
    private NoteList<Note> trashNotes = new NoteList<>();
    private Context context;

    public NoteManager(Context context, String tableName) throws Exception {
        this.noteDBWriter = new NoteDBWriter<>(tableName);

        this.notes = this.noteDBWriter.selectAllNote(NOTES);
        Collections.sort(this.notes, new SortById());

        this.trashNotes = this.noteDBWriter.selectAllNote(TRASH);
        Collections.sort(this.trashNotes, new SortById());

        this.COUNT += tableName;
        this.context = context;
        counter = getCounter();
    }

    public void saveNote(Note note) {
        note.setId(counter);
        note.setTrash(NOTES);
        this.notes.addOrderedNote(note);
        this.noteDBWriter.insertNote(note);
        counter++;
    }

    public void updateNote(Note note) {
        this.notes.updateNote(note);
        this.noteDBWriter.updateNote(note);
    }

    public boolean containsNote(Note note) {
        return this.notes.containsNote(note);
    }

    public void moveNoteToTrash(Note note) {
        this.notes.removeNote(note);
        note.setTrash(TRASH);
        this.trashNotes.addOrderedNote(note);
        this.noteDBWriter.updateNote(note);
    }

    public void restoreNoteFromTrash(Note note) {
        this.trashNotes.removeNote(note);
        note.setTrash(NOTES);
        this.notes.addOrderedNote(note);
        this.noteDBWriter.updateNote(note);
    }

    public void deleteFromTrash(Note note) {
        this.trashNotes.removeNote(note);
        this.noteDBWriter.deleteNote(note.getId());
    }

    public void deleteNote(Note note) {
        this.trashNotes.removeNote(note);
        this.notes.removeNote(note);
        this.noteDBWriter.deleteNote(note.getId());
    }

    public void deleteAllTrash() {
        this.trashNotes.clear();
        this.noteDBWriter.deleteAlNote(TRASH);
    }

    public void deleteAll() {
        this.notes.clear();
        this.trashNotes.clear();
        this.noteDBWriter.deleteAlNote(NOTES);
        this.noteDBWriter.deleteAlNote(TRASH);
    }

    public void saveChanges(){
        saveCounter(counter);
    }

    public NoteList<Note> getAllNotes() {
        return this.notes;
    }

    public NoteList<Note> getAllTrashNotes() {
        return this.trashNotes;
    }

    public Note getNote(Note note) {
        return this.notes.getNote(note.getId());
{'fraction_non_alphanumeric': 0.10809833694866233, 'fraction_numerical': 0.0007230657989877079, 'mean_word_length': 2.813232253618194, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '416500', 'n_tokens_mistral': 1694, 'n_tokens_neox': 1629, 'n_words': 298}