Skip to content

Commit

Permalink
csv reader and ifromcsv
Browse files Browse the repository at this point in the history
  • Loading branch information
sonalgoyal committed Jul 16, 2024
1 parent 6abd121 commit 3de35da
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
28 changes: 28 additions & 0 deletions common/core/src/test/java/zingg/common/core/util/CsvReader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package zingg.common.core.util;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class CsvReader {
protected List<? extends IFromCsv> records;
IFromCsv creator;

public CsvReader(IFromCsv creator){
records = new ArrayList<IFromCsv>();
this.creator = creator;
}

public List<? extends IFromCsv> getRecords(String file, boolean skipHeader) throws FileNotFoundException{
int lineno = 0;
try (Scanner scanner = new Scanner(new File(file))) {
while (scanner.hasNextLine()) {
records.add(creator.fromCsv(scanner.nextLine()));
}
}
return records;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package zingg.common.core.util;

public interface IFromCsv {

<C> C fromCsv(String s);

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package zingg.common.infra.util;
package zingg.common.core.util;

import java.lang.reflect.*;
import java.security.NoSuchAlgorithmException;
Expand Down

0 comments on commit 3de35da

Please sign in to comment.