/*
 * 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 cpvreader {

    ArrayList<cpvlist> CPVCodeList = new ArrayList();
    
    public boolean ReadCPVCodesFromFile(String szFilename,String Language)
    {
        try {
            //TODO write your implementation code here: //  int iloop=0;
            String szCodes = "";
            String F1 = "";
            String F2 = "";
            BufferedReader in;


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

            String record1 = "xxx;xxx";
            
            while ((record1 = in.readLine()) != null) {
                
                //look to found f1 and f2
                int j = record1.indexOf(";", 0);

                F1 = record1.substring(0, j);
                F2 = record1.substring(j + 1, record1.length());
                cpvlist ditem = new cpvlist();
                ditem.setSzCode(F1);
                ditem.setSzDescription(F2);
                CPVCodeList.add(ditem);
            }
            return true;
        } catch (IOException ex) {
            return false;
        } 
       
    } // reader class finished

    public int GetMaxSize()
    {
        return CPVCodeList.size();
    }
    
    public String GetCodeFor(int i)
    {
        cpvlist ditem=CPVCodeList.get(i);
        return ditem.getSzCode();
    }
    
    public String GetDescFor(int i)
    {
        cpvlist ditem=CPVCodeList.get(i);
        return ditem.getSzDescription();
    }

}//class ends

    

