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

import java.util.ArrayList;
import java.util.List;


/**
 *
 * @author pokotyamu
 */
public class Table {
    
    private List<DataSet> cols;
    private DataSet projectIDds;
    
    public Table() {
        cols = new ArrayList<>();
        projectIDds = new DataSet("ProjectID");
    }
    
    //DataSetの順番については正しく並べ替えられているものとする
    public void addCol(DataSet ds){
        cols.add(ds);
    }
    
    public void setProjectID(DataSet ds){
        this.projectIDds = ds;
    }
    
    public DataSet getProjectID(){
        return projectIDds;
    }
    
    public int getProjectIDIndex(Cell c){
        return projectIDds.getCellIndex(c);
    }
    
    public int getProjectIDIndex(Object ob){
        return projectIDds.getCellIndex(new Cell(ob));
    }
    
    public int getProjectIDIndex(int id){
        return projectIDds.getCellIndex(new Cell(id));
    }
    
    public DataSet getDataSet(String name) {
        DataSet ds = new DataSet();
        for (DataSet col : cols) {
            if(col.isName(name)){
                return col;
            }
        }
        return ds;
    }

    //テーブル列内のソート関数
    //keyが1の時：降順
    //keyが−1の時：昇順
    public void sort(int key,String dataName){
        DataSet ds = this.getDataSet(dataName);
        if(key > 0){//昇順
            for(int i = 0; i < ds.size()-1;i++){
                for(int j = i+1; j < ds.size();j++){
                    if(ds.getIntCell(i) > ds.getIntCell(j)){
                        switchCell(i, j);
                    }
                }
            }
        }else{//降順
            for(int i = 0; i < ds.size()-1;i++){
                for(int j = i+1; j < ds.size();j++){
                    if(ds.getIntCell(i) < ds.getIntCell(j)){
                        switchCell(i, j);
                    }
                }
            }
        }
    }
    
    //その他の全ての列に対しても並べ替えを行う
    private void switchCell(int a,int b){
        for (DataSet col : cols) {
            col.switchCell(a, b);
        }
        this.projectIDds.switchCell(a,b);
    }
}

@@ -588,32 +588,179 @@
 ds);%0A    %7D%0A    %0A
+    //%E3%81%BE%E3%81%A8%E3%82%81%E3%81%A6%E8%BF%BD%E5%8A%A0%0A    public void addCols(List%3CDataSet%3E cols) %7B%0A        for (DataSet col : cols) %7B%0A            this.cols.add(col);%0A        %7D%0A    %7D%0A    %0A
     public void 
@@ -2373,10 +2373,11 @@
 ;%0A    %7D%0A
+%0A
 %7D%0A

add input ColList