import java.io.File;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class PersonTester {
    private static final String INPUT_FILE_NAME = "sorted_by_Nom.csv";
    private static final String OUTPUT_FILE_NAME = "sorted_by_Cognoms.csv";
    private static final String SEPARATOR = ",";
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(new File(INPUT_FILE_NAME));
        PrintWriter out = new PrintWriter(OUTPUT_FILE_NAME);
        String[] header;
        ArrayList<Person> people;
        if (in.hasNext()) {
            header = in.nextLine().split(SEPARATOR);
            System.out.println("header#0:" + header[0]
                    + "\theader#1: " + header[1]);
            people = new ArrayList<>();
            for (int lineNum = 0; in.hasNext(); lineNum++) {
                String[] column = in.nextLine().split(SEPARATOR);
                System.out.println(header[0] + ": " + column[0]
                        + "\t" + header[1] + ": " + column[1]);
                people.add(new Person(column[0], column[1]));
            }
            in.close();
            Collections.sort(people);
            out.println(header[1] + SEPARATOR + header[0]);
            for (Person p : people) {
                out.println(p.getLastName() + SEPARATOR + p.getFirstName());
            }
            out.close();
        }
    }
}
/*
 * El directorio por defecto en Netbeans es el directorio del project:
 * W??
 * En la version RAW es el directorio donde estan los *.class:
 * RAW/W??/W??H??_*
 */
