package org.nwapw.abacus.window;

import org.nwapw.abacus.tree.TreeNode;

import javax.swing.event.TableModelListener;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;
import java.util.ArrayList;

public class HistoryTableModel extends AbstractTableModel {

    public static final String[] COLUMN_NAMES = {
            "Input",
            "Parsed Input",
            "Output"
    };

    public static final Class[] CLASS_TYPES = {
            String.class,
            TreeNode.class,
            String.class
    };

    public static class HistoryEntry {
        public String input;
        public TreeNode parsedInput;
        public String output;

        public HistoryEntry(String input, TreeNode parsedInput, String output){
            this.input = input;
            this.parsedInput = parsedInput;
            this.output = output;
        }

        Object nthValue(int n){
            if(n == 0) return input;
            if(n == 1) return parsedInput;
            if(n == 2) return output;
            return null;
        }
    }

    ArrayList<HistoryEntry> entries;

    public HistoryTableModel() {
        entries = new ArrayList<>();
    }

    public void addEntry(HistoryEntry entry){
        entries.add(entry);
    }

        @Override
    public int getRowCount() {
        return entries.size();
    }

    @Override
    public int getColumnCount() {
        return 3;
    }

    @Override
    public String getColumnName(int columnIndex) {
        return COLUMN_NAMES[columnIndex];
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        return CLASS_TYPES[columnIndex];
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        return entries.get(rowIndex).nthValue(columnIndex);
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        return;
    }

    @Override
    public void addTableModelListener(TableModelListener l) {

    }

    @Override
    public void removeTableModelListener(TableModelListener l) {

    }
}

@@ -227,68 +227,223 @@
 t;%0A%0A
-public class HistoryTableModel extends AbstractTableModel %7B%0A
+/**%0A * A table model to store data about the history of inputs%0A * in the calculator.%0A */%0Apublic class HistoryTableModel extends AbstractTableModel %7B%0A%0A    /**%0A     * Static array used to get the column names.%0A     */
 %0A   
@@ -559,32 +559,106 @@
 Output%22%0A    %7D;%0A%0A
+    /**%0A     * Static array used to get the class of each column.%0A     */%0A
     public stati
@@ -772,24 +772,139 @@
 ass%0A    %7D;%0A%0A
+    /**%0A     * Class used specifically to hold data about%0A     * the previous entries into the calculator.%0A     */%0A
     public s
@@ -1428,118 +1428,314 @@
     
-ArrayList%3CHistoryEntry%3E entries;%0A%0A    public HistoryTableModel() %7B%0A        entries = new ArrayList%3C%3E();%0A    %7D%0A
+/**%0A     * The list of entries.%0A     */%0A    ArrayList%3CHistoryEntry%3E entries;%0A%0A    /**%0A     * Creates a new empty history table model%0A     */%0A    public HistoryTableModel() %7B%0A        entries = new ArrayList%3C%3E();%0A    %7D%0A%0A    /**%0A     * Adds an entry to the model.%0A     * @param entry the entry to add.%0A     */
 %0A   
@@ -1808,28 +1808,24 @@
 ry);%0A    %7D%0A%0A
-    
     @Overrid
@@ -2455,288 +2455,6 @@
  %7D%0A%0A
-    @Override%0A    public void setValueAt(Object aValue, int rowIndex, int columnIndex) %7B%0A        return;%0A    %7D%0A%0A    @Override%0A    public void addTableModelListener(TableModelListener l) %7B%0A%0A    %7D%0A%0A    @Override%0A    public void removeTableModelListener(TableModelListener l) %7B%0A%0A    %7D%0A
 %7D%0A

Comment and clean up HistoryTableModel code.