/*
 * 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 clases;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author chuen
 */
public class Filtros {


public DefaultTableModel filtrar (DefaultTableModel modeloafiltrar, ArrayList<String> seleccion, int columna){
DefaultTableModel modelofiltrado; 
ArrayList<Integer> indices = new ArrayList<Integer>();
int coincidencias=0;

    for (int i = 0; i < modeloafiltrar.getRowCount(); i++) {
        
    
    System.out.println("entra al primer for");
    for (int j = 0; j < seleccion.size(); j++) {
        System.out.println("entra al segundo for");
        if(String.valueOf(modeloafiltrar.getValueAt(i, columna)).equals(seleccion.get(j))){
            coincidencias=coincidencias++;
            indices.add(i);
        }else{
            System.out.println("entra al else");
            
        }
    }
   


    
}



 String [][]  matriz = new String [indices.size()][4];


    for (int i = 0; i < indices.size(); i++) {
        System.out.println("entra a paso de matriz");
        matriz[i][0]=String.valueOf(modeloafiltrar.getValueAt(indices.get(i), 0));
        matriz[i][1]=String.valueOf(modeloafiltrar.getValueAt(indices.get(i), 1));
        matriz[i][2]=String.valueOf(modeloafiltrar.getValueAt(indices.get(i), 2));
        matriz[i][3]=String.valueOf(modeloafiltrar.getValueAt(indices.get(i), 3));

    }
    
      
    
 
modelofiltrado= new javax.swing.table.DefaultTableModel(
            matriz,
            new String [] {
                "Nombre", "Title 2", "Title 3", "Title 4"
            }
        ); 
 
    return modelofiltrado;
}    
public DefaultTableModel listasdelistas (DefaultTableModel modeloafiltrar, String [][] filtros, String [] numcols, int columna){
DefaultTableModel modelofiltrado=null; 
ArrayList<Integer> indices = new ArrayList<Integer>();
ArrayList<Integer> disctintindices = new ArrayList<Integer>();
int coincidencias=0;



    for (int i = 0; i < modeloafiltrar.getRowCount(); i++) {
        for (int j = 0; j < numcols.length; j++) {
            for (int k = 0; k < filtros.length; k++) {
                for (int l = 0; l < filtros[k].length; l++) {
                    if(filtros[k][l].equals(numcols[j])){
                        if(filtros[k][l].equals(modeloafiltrar.getValueAt(i, j))){
                        coincidencias=coincidencias++;
                        indices.add(i);
                        }
                        
                    }
                }
            }
        }
    }


    for (int i = 0; i < indices.size(); i++) {
    if(!disctintindices.contains(indices.get(i))){
        disctintindices.add(indices.get(i));
}        
    }

    
    
    

 String [][]  matriz = new String [indices.size()][4];


    for (int i = 0; i < indices.size(); i++) {
        for (int j = 0; j < modeloafiltrar.getColumnCount(); j++) {
        matriz[i][j]=String.valueOf(modeloafiltrar.getValueAt(disctintindices.get(i), j));

        }
      

    }
    

    
 
modelofiltrado= new javax.swing.table.DefaultTableModel(
            matriz,
            new String [] {
                "Nombre", "Title 2", "Title 3", "Title 4"
            }
        ); 
 
    return modelofiltrado;
}    
}
