package it.pcacademy.corsojava.library;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;
import java.util.Map.Entry;

public class MainLibrary {

	public static void main(String[] args) {
		
		try {
			// File inFile non contiene i dati ma il percorso dove trovarli
			File inputFile = new File("file/elencobibliotechelazio2014.csv");
			BufferedReader buf = new BufferedReader(new FileReader(inputFile));	
			
			List<TreeMap<String, String>> libraryArrayLazio = new ArrayList<TreeMap<String, String>>();
			String line = buf.readLine();
			String[] titleItems = line.split(",");
			System.out.println(titleItems.length);
			StringSplitLibrary infoArray = new StringSplitLibrary();
			line = buf.readLine();
			
			while (line != null) {
				for (int i = 0; i < titleItems.length; i++) {
					TreeMap<String, String> map = new TreeMap<String, String>();
					map.put(titleItems[i], infoArray.split(line, titleItems.length)[i]);
					libraryArrayLazio.add(map);
				}
				line = buf.readLine();
			}
			buf.close();
			for (TreeMap<String, String> map : libraryArrayLazio) {
				for (Entry<String,String> e: map.entrySet()) {
					System.out.println(e.getKey() + ": " + e.getValue());
				}
			}
			
//			List<Library> libraryList = new ArrayList<Library>();
//			for (String[] data: libraryArrayLazio) {
//				Library library = new Library();
////				short[] cap = new short[5];
////				for (int i = 0; i < data[8].length(); i++) {
////					cap[i] = (short)Integer.parseInt(String.valueOf(data[9].charAt(i)));
////				}
//				Address address = new Address(data[7], data[8], data[9]);
//				library.setIndirizzo(address);
//				libraryList.add(library);
//			}
//			
//			for (Library i : libraryList) {
//				System.out.println(i.getIndirizzo().getCap());
//			}
			
		} catch (Exception e) {
			// stampa il messaggio di errore
			e.printStackTrace();
		}
		


	}

}

@@ -844,59 +844,8 @@
 ) %7B%0A
-%09%09%09%09for (int i = 0; i %3C titleItems.length; i++) %7B%0A%09
 %09%09%09%09
@@ -905,16 +905,66 @@
 ing%3E();%0A
+%09%09%09%09for (int i = 0; i %3C titleItems.length; i++) %7B%0A
 %09%09%09%09%09map
@@ -1029,16 +1029,52 @@
 h)%5Bi%5D);%0A
+%09%09%09%09%09if (i == titleItems.length-1)%0A%09
 %09%09%09%09%09lib
@@ -1184,19 +1184,27 @@
 String%3E 
-map
+listLibrary
  : libra
@@ -1252,19 +1252,27 @@
 ing%3E e: 
-map
+listLibrary
 .entrySe

fix TreeMap