<commit_before>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edacc.manageDB;

import edacc.model.Instance;
import edacc.model.InstanceDAO;
import edacc.model.InstanceHasInstanceClassDAO;
import edacc.model.InstanceHasProperty;
import edacc.model.InstanceHasPropertyDAO;
import edacc.model.Property;
import edacc.model.PropertyDAO;
import edacc.model.PropertyType;
import edacc.satinstances.ConvertException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author rretz
 */
public class InstanceTableModel extends edacc.experiment.InstanceTableModel {

    public static final int COL_PROP = 2;
    private boolean[] visible;
    private ArrayList<Property> properties;
    private String[] CONST_COLUMNS = {"Name", "MD5"};
    private boolean[] CONST_VISIBLE = {true, true};
    private String[] columns;
    protected Vector<Instance> instances;
    protected HashMap<Instance, LinkedList<Integer>> instanceClassIds;

    public String[] getAllColumnNames() {
        return columns;
    }

    public InstanceTableModel() {
        this.instances = new Vector<Instance>();
        columns = new String[CONST_COLUMNS.length];
        visible = new boolean[columns.length];
        for (int i = 0; i < columns.length; i++) {
            columns[i] = CONST_COLUMNS[i];
            visible[i] = CONST_VISIBLE[i];
        }
        instanceClassIds = new HashMap<Instance, LinkedList<Integer>>();
    }

    public boolean isEmpty() {
        if (instances.isEmpty()) {
            return true;
        }
        return false;
    }

    public Vector<Instance> getInstances() {
        return instances;
    }

    public void initInstances(Vector<Instance> instances){
        clearTable();
        this.instances = instances;
    }
    
    public void addInstances(Vector<Instance> instances) {
        for (int i = 0; i < instances.size(); i++) {
            addInstance(instances.get(i));
        }


        for (Instance i : instances) {
            instanceClassIds.put(i, new LinkedList<Integer>());
        }
        try {
            InstanceHasInstanceClassDAO.fillInstanceClassIds(instanceClassIds);
        } catch (SQLException ex) {
            // TODO: error
        }
    }

    private void addInstance(Instance in) {
        if (!instances.contains(in)) {
            instances.add(in);
        }
    }

    public void clearTable() {
        instances.removeAllElements();
    }

    public void remove(Instance instance) {
        instances.remove(instance);
        instanceClassIds.remove(instance);<commit_msg>bugfix<commit_after>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edacc.manageDB;

import edacc.model.Instance;
import edacc.model.InstanceDAO;
import edacc.model.InstanceHasInstanceClassDAO;
import edacc.model.InstanceHasProperty;
import edacc.model.InstanceHasPropertyDAO;
import edacc.model.Property;
import edacc.model.PropertyDAO;
import edacc.model.PropertyType;
import edacc.satinstances.ConvertException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author rretz
 */
public class InstanceTableModel extends edacc.experiment.InstanceTableModel {

    public static final int COL_PROP = 2;
    private boolean[] visible;
    private ArrayList<Property> properties;
    private String[] CONST_COLUMNS = {"Name", "MD5"};
    private boolean[] CONST_VISIBLE = {true, true};
    private String[] columns;
    protected Vector<Instance> instances;
    protected HashMap<Instance, LinkedList<Integer>> instanceClassIds;

    public String[] getAllColumnNames() {
        return columns;
    }

    public InstanceTableModel() {
        this.instances = new Vector<Instance>();
        columns = new String[CONST_COLUMNS.length];
        visible = new boolean[columns.length];
        for (int i = 0; i < columns.length; i++) {
            columns[i] = CONST_COLUMNS[i];
            visible[i] = CONST_VISIBLE[i];
        }
        instanceClassIds = new HashMap<Instance, LinkedList<Integer>>();
    }

    public boolean isEmpty() {
        if (instances.isEmpty()) {
            return true;
        }
        return false;
    }

    public Vector<Instance> getInstances() {
        return instances;
    }

    public void initInstances(Vector<Instance> instances){
        clearTable();
        this.instances = instances;
        
         for (Instance i : instances) {
            instanceClassIds.put(i, new LinkedList<Integer>());
        }
        try {
            InstanceHasInstanceClassDAO.fillInstanceClassIds(instanceClassIds);
        } catch (SQLException ex) {
            // TODO: error
        }
    }
    
    public void addInstances(Vector<Instance> instances) {
        for (int i = 0; i < instances.size(); i++) {
            addInstance(instances.get(i));
        }


        for (Instance i : instances) {
            instanceClassIds.put(i, new LinkedList<Integer>());
        }
        try {
            InstanceHasInstanceClassDAO.fillInstanceClassIds(instanceClassIds);
        } catch (SQLException ex) {
            // TODO: error
        }
    }

    private void addInstance(Instance in) {
        if (!instances.contains(in)) {
            instances.add(in);
        }
    }

    public void clearTable() {
        instances.removeAllElements();
    }

    public void remove(Instance instance) {
        instances.remove(instance);
        instanceClassIds.remove(instance);
{'fraction_non_alphanumeric': 0.10496862811599118, 'fraction_numerical': 0.0013566220111921317, 'mean_word_length': 2.792926045016077, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 26, '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': '4218150', 'n_tokens_mistral': 1655, 'n_tokens_neox': 1630, 'n_words': 383}