Skip to content
Snippets Groups Projects
Commit 79f7bf42 authored by Christopher Bohn's avatar Christopher Bohn :thinking:
Browse files

Changed write method's signature to accept any Iterable

parent 4821aa8f
No related branches found
No related tags found
No related merge requests found
...@@ -67,6 +67,7 @@ public class CSVReaderWriter { ...@@ -67,6 +67,7 @@ public class CSVReaderWriter {
} }
/* LEGACY METHODS */ /* LEGACY METHODS */
@SuppressWarnings("WeakerAccess")
public static Set<Map<String, String>> readCSV(String filename) { public static Set<Map<String, String>> readCSV(String filename) {
return readCSVasSet(filename); return readCSVasSet(filename);
} }
...@@ -85,7 +86,8 @@ public class CSVReaderWriter { ...@@ -85,7 +86,8 @@ public class CSVReaderWriter {
// I'd like to replace this with something that uses openCSV, but it works, and openCSV doesn't seem to have // I'd like to replace this with something that uses openCSV, but it works, and openCSV doesn't seem to have
// writers that take map<string,string> // writers that take map<string,string>
public static boolean writeCSV(String filename, Set<Map<String, String>> data) { @SuppressWarnings("WeakerAccess")
public static boolean writeCSV(String filename, Iterable<Map<String, String>> data) {
boolean wroteFile = true; boolean wroteFile = true;
ClassLoader classLoader = CSVReaderWriter.class.getClassLoader(); ClassLoader classLoader = CSVReaderWriter.class.getClassLoader();
URL resource = classLoader.getResource("csv/" + filename); URL resource = classLoader.getResource("csv/" + filename);
...@@ -145,7 +147,7 @@ public class CSVReaderWriter { ...@@ -145,7 +147,7 @@ public class CSVReaderWriter {
} }
*/ */
static void placeCSVonStream(Set<Map<String, String>> data, OutputStream outputStream) { static void placeCSVonStream(Iterable<Map<String, String>> data, OutputStream outputStream) {
PrintStream writer = new PrintStream(outputStream); PrintStream writer = new PrintStream(outputStream);
Set<String> fieldNames = null; Set<String> fieldNames = null;
int number_of_fields = 0; int number_of_fields = 0;
...@@ -167,11 +169,10 @@ public class CSVReaderWriter { ...@@ -167,11 +169,10 @@ public class CSVReaderWriter {
} }
} }
} }
/*
public static void main(String[] args) { public static void main(String[] args) {
Set<Map<String, String>> demo = readCSV("demo.csv"); Set<Map<String, String>> demo = readCSV("demo.csv");
boolean success = writeCSV("out.csv", demo); boolean success = writeCSV("out.csv", demo);
System.out.println(success ? "Wrote file!" : "Didn't write file"); System.out.println(success ? "Wrote file!" : "Didn't write file");
} }
*/
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment