src/main/java/utils/Common.java
/**
     * Imports a list of {@link SearchResultItem} from a CSV file
     * <p>File must have 4 columns and headers "Title", "Price New", "Price Old", "URL" </p>
     *
     * @param path path to valid directory with existing csv file
     * @param items List of {@link SearchResultItem} to be populated with data
     * @throws IOException when could not find file or file is not a list of {@link SearchResultItem}
     */


@param path path to valid directory with existing csv file
@param items List of  SearchResultItem to be populated with data
@throws IOException when could not find file or file is not a list of  SearchResultItem
@param path path to valid directory with existing csv file @param items List of SearchResultItem to be populated with data @throws IOException when could not find file or file is not a list of SearchResultItem
public static void importSearchItemsFromCSV(String path, List<SearchResultItem> items) throws IOException {
        String title;
        String url;
        float priceNew;
        float priceOld;
        CSVReader csvReader = new CSVReader(new FileReader(path));
        List<String[]> allData = csvReader.readAll();
        if((!allData.get(0)[0].contains("Title") && !allData.get(0)[1].contains("Price New") &&
                !allData.get(0)[2].contains("Price Old") && !allData.get(0)[3].contains("URL")) || allData.get(0).length != 4){
            throw new IOException("ERROR! Wrong file.\nFile must contain 4 columns with headers \"Title\", \"Price New\", \"Price Old\", \"URL\"");
        }
        allData.remove(0);
        for(String[] data : allData){
            title = data[0];
            priceNew = Float.parseFloat(data[1]);
            priceOld = Float.parseFloat(data[2]);
            url = data[3];
            items.add(new SearchResultItem(title, url, priceNew, priceOld));
        }
        csvReader.close();
    }
public static void importSearchItemsFromCSV ( String path , List < SearchResultItem > items ) throws IOException { String title ; String url ; float priceNew ; float priceOld ; CSVReader csvReader = new CSVReader ( new FileReader ( path ) ) ; List < String [ ] > allData = csvReader . readAll ( ) ; if ( ( ! allData . get ( 0 ) [ 0 ] . contains ( "Title" ) && ! allData . get ( 0 ) [ 1 ] . contains ( "Price New" ) && ! allData . get ( 0 ) [ 2 ] . contains ( "Price Old" ) && ! allData . get ( 0 ) [ 3 ] . contains ( "URL" ) ) || allData . get ( 0 ) . length != 4 ) { throw new IOException ( "ERROR! Wrong file.\nFile must contain 4 columns with headers \"Title\", \"Price New\", \"Price Old\", \"URL\"" ) ; } allData . remove ( 0 ) ; for ( String [ ] data : allData ) { title = data [ 0 ] ; priceNew = Float . parseFloat ( data [ 1 ] ) ; priceOld = Float . parseFloat ( data [ 2 ] ) ; url = data [ 3 ] ; items . add ( new SearchResultItem ( title , url , priceNew , priceOld ) ) ; } csvReader . close ( ) ; }
Imports a list of {@link SearchResultItem} from a CSV file
 <p>File must have 4 columns and headers "Title", "Price New", "Price Old", "URL" </p>
Imports a list of { @link SearchResultItem } from a CSV file <p > File must have 4 columns and headers " Title " " Price New " " Price Old " " URL " < / p >
// Validate Header and number of columns // Remove header