/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.ellectra.code.reader.list;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

/**
 *
 * @author tdi
 */
public class nutsreader {

    ArrayList<nutslist> NUTSCodeList = new ArrayList();
    
    public boolean ReadNutsCodesFromFile(String szFilename,String Language)
    {
        try {
            //TODO write your implementation code here: //  int iloop=0;
            String szCodes = "";
           String F1="";
        String F2="";
        String F3="";
        String F4="";
        String F5="";
            BufferedReader in;


            in = new BufferedReader(new FileReader(szFilename));

            String record1 = "xxx;xxx;xxx;xxx;xxx";
            
            while ((record1 = in.readLine()) != null) {
                
                //look to found f1 and f2
                int j = record1.indexOf(";", 0);
                    int j1 = record1.indexOf(";", j+1);
                    int j2 = record1.indexOf(";", j1+1);
                    int j3 = record1.indexOf(";", j2+1);
                    int j4 = record1.indexOf(";", j3+1);
                    
                  //System.err.print(j1+j2+j3+j4);
              // System.err.print("------");
                    F1=record1.substring(0,j);
                //    System.err.print(F1);
                  
                        F2=record1.substring(j+1,j1);
                 //System.err.print(F2);
                    F3=record1.substring(j1+1,j2);
                   // System.err.print(F3);
                 
                    F4=record1.substring(j2+1,j3);
                    //System.err.print(F4);
                 
                    F5=record1.substring(j3+1,record1.length());
//System.err.print(F5);
//System.err.print("------");
//                F1 = record1.substring(0, j);
//                F2 = record1.substring(j + 1, record1.length());
                nutslist ditem = new nutslist();
                ditem.setSzCode(F1);
                ditem.setSzDescription(F2);
                ditem.setL1(F3);
                ditem.setL2(F4);
                ditem.setL3(F5);
                NUTSCodeList.add(ditem);
            }
            return true;
        } catch (IOException ex) {
            return false;
        } 
       
    } // reader class finished

    public int GetMaxSize()
    {
        return NUTSCodeList.size();
    }
    
    public String GetCodeFor(int i,int ip)
    {
        nutslist ditem=NUTSCodeList.get(i);
        if (ip==1)
            return ditem.getSzCode();
        if (ip==2)
            return ditem.getSzDescription();
        if (ip==3)
            return ditem.getL1();
        if (ip==4)
            return ditem.getL2();
        if (ip==5)
            return ditem.getL3();
        
        return "NA";
    }
    
    

}//class ends

    

