package org.josast.AmsatList.Commande;

import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import org.josast.AmsatList.source.ReadCsvFile;

public class CommandeList {
	

	Hashtable<Integer, Commande> HashtableCommande = new Hashtable<Integer, Commande>();
	Vector<Commande> listeCommande = null;
	
	
	public  CommandeList(String file)
	{
		listeCommande = new  Vector<Commande> () ;
		ReadCsvFile rcv = new ReadCsvFile();
		
		 List<String[]> listrawcmd = rcv.allLine(file);
		 
		 Iterator<String[]>  it = listrawcmd.iterator();
		 {
			  while(it.hasNext())
			    {
				  Commande cmd = new Commande(it.next());
				  listeCommande.add(cmd);
				  HashtableCommande.put(cmd.getNasaId(),cmd);
			    }  
		 }
	}
	
	public  CommandeList(Vector<Commande> listeCommande)
	{
		this.listeCommande = listeCommande;
		 Iterator<Commande> itr = listeCommande.iterator();
	        while(itr.hasNext()){
	          Commande cmd = itr.next();
	      	  HashtableCommande.put(cmd.getNasaId(),cmd);
	        }
	}
	
	
	public void save(String file)
	{
		PrintWriter writer = null;
		try {
			writer = new PrintWriter(file);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 Iterator<Commande> itr = listeCommande.iterator();
	        while(itr.hasNext()){
	        	writer.println(itr.next().toString());
	        }

		writer.close();
		 
	}

	public Hashtable<Integer, Commande> getHashtableCommande() {
		return HashtableCommande;
	}

	public void setHashtableCommande(Hashtable<Integer, Commande> hashtableCommande) {
		HashtableCommande = hashtableCommande;
	}

	public Vector<Commande> getListeCommande() {
		return listeCommande;
	}

	public void setListeCommande(Vector<Commande> listeCommande) {
		this.listeCommande = listeCommande;
	}
	
	public void print()
	{
	 Iterator<Commande> itr = listeCommande.iterator();
     while(itr.hasNext()){
         System.out.println(itr.next().toString());
     }
	}
}
