package com.spakai.parser.csv;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.List;
import static java.util.stream.Collectors.toList;

public class CsvParser implements Iterator<Record> {
    
  private List<Record> list;
  
  private int position = 0;

  public CsvParser(String filePath) throws IOException {
   InputStream is = new FileInputStream(new File(filePath));
   BufferedReader br = new BufferedReader(new InputStreamReader(is));
 
   list = 
       br.lines()
       .map(line -> mapToRecord(line))
       .collect(toList());
  }
  
   public Record mapToRecord(String line) {
       String[] p = line.split(",");
       //temp code for 3 member Record
       return new Record(p[0], p[1], p[2]);
   }
  
  @Override
  public Record next() {
      Record record = list.get(position);
      position = position + 1;
      return record;
  }

  @Override
  public boolean hasNext() {
      if (position >= list.size() || list.get(position) == null) {
	      return false;
      } else {
	      return true;
      }
  } 
  
}


  

@@ -24,17 +24,16 @@
 er.csv;%0A
-%0A
 import j
@@ -43,94 +43,62 @@
 .io.
-BufferedReader;%0Aimport java.io.File;%0Aimport java.io.FileInputStream;%0Aimport java.io.IO
+IOException;%0Aimport java.lang.reflect.InvocationTarget
 Exce
@@ -116,30 +116,30 @@
 rt java.
+n
 io.
-InputStream
+file.Files
 ;%0Aimport
@@ -148,28 +148,22 @@
 ava.
+n
 io.
-InputStreamReader
+file.Paths
 ;%0Aim
@@ -210,16 +210,17 @@
 l.List;%0A
+%0A
 import s
@@ -284,16 +284,19 @@
 svParser
+%3CT%3E
  impleme
@@ -308,18 +308,13 @@
 tera
-tor%3CRecord
+ble%3CT
 %3E %7B%0A
@@ -332,29 +332,29 @@
 ate 
-List%3CRecord%3E list;%0A
+Class%3CT%3E clazz; %0A 
   
+ 
 %0A  p
@@ -364,26 +364,24 @@
 ate 
-int position = 0;%0A
+List%3CT%3E list;%0A  
 %0A  p
@@ -386,25 +386,25 @@
  public 
-CsvParser
+void load
 (String 
@@ -441,53 +441,40 @@
 %0A   
-InputStream 
+   l
 is
+t
  =
- new
  File
-InputStream(new File
+s.lines( Paths.get
 (fil
@@ -484,111 +484,16 @@
 th))
-;
 %0A   
-BufferedReader br = new BufferedReader(new InputStreamReader(is));%0A %0A   list = %0A       br.lines()%0A
+    
     
@@ -534,16 +534,23 @@
 %0A       
+ 
+      
 .collect
@@ -570,30 +570,95 @@
  %7D%0A  %0A  
- 
 public 
-Record
+CsvParser(Class%3CT%3E clazz)  %7B%0A      this.clazz = clazz;%0A  %7D%0A  %0A  public T
  mapToRe
@@ -674,20 +674,20 @@
 ng line)
+ 
  %7B%0A
- 
       St
@@ -724,142 +724,646 @@
     
- //temp code for 3 member Record%0A       return new Record(p%5B0%5D, p%5B1%5D, p%5B2%5D);%0A   %7D%0A  %0A  @Override%0A  public Record next() %7B%0A      Record
+try %7B%0A          return clazz.getDeclaredConstructor( String.class, String.class, String.class ).newInstance( p%5B0%5D, p%5B1%5D, p%5B2%5D );%0A      %7D catch (InstantiationException %7C IllegalAccessException%0A              %7C IllegalArgumentException %7C InvocationTargetException%0A              %7C NoSuchMethodException %7C SecurityException e) %7B%0A          // TODO Auto-generated catch block%0A          e.printStackTrace();%0A          return null;%0A      %7D%0A  %7D%0A  %0A  @Override%0A  public Iterator%3CT%3E iterator() %7B%0A      return new Iterator%3CT%3E() %7B%0A          %0A          private int position = 0;%0A          %0A          @Override%0A          public T next() %7B%0A              T
  rec
@@ -1388,16 +1388,24 @@
 ition);%0A
+        
       po
@@ -1427,16 +1427,24 @@
 on + 1;%0A
+        
       re
@@ -1458,19 +1458,43 @@
 cord;%0A  
-%7D%0A%0A
+        %7D%0A        %0A        
   @Overr
@@ -1489,32 +1489,40 @@
       @Override%0A
+        
   public boolean
@@ -1530,24 +1530,32 @@
 hasNext() %7B%0A
+        
       if (po
@@ -1609,16 +1609,24 @@
 null) %7B%0A
+        
 %09      r
@@ -1638,16 +1638,24 @@
  false;%0A
+        
       %7D 
@@ -1661,16 +1661,24 @@
  else %7B%0A
+        
 %09      r
@@ -1699,21 +1699,42 @@
     
-%7D%0A  %7D %0A  %0A%7D%0A%0A%0A  
+        %7D%0A          %7D %0A      %7D;%0A  %7D%0A%7D
 %0A

Update CsvParser.java