From 03991b0cabc7a510e0d2ff7ed1a2f0bbc300e7c1 Mon Sep 17 00:00:00 2001 From: ArghKevin Date: Thu, 16 May 2024 02:03:54 -0700 Subject: Structure CSVReader to be externally iterable. --- src/CSVReader.java | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/CSVReader.java b/src/CSVReader.java index 1f3189a..fa588ef 100644 --- a/src/CSVReader.java +++ b/src/CSVReader.java @@ -34,7 +34,6 @@ public class CSVReader extends Reader { public void parse() { String[] lines = this.getContents().split("\n"); this.header = lines[0].split(","); - System.out.printf("%d\n", header.length); /* Iterate over all lines of the body. */ for (int i = 1; i < lines.length; i++) { @@ -47,16 +46,13 @@ public class CSVReader extends Reader { } body.add(map); } - - for (String head : this.header) { - System.out.printf("%s\t", head); - } - System.out.println(); - for (HashMap map : body) { - for (int i = 0; i < header.length; i++) { - System.out.printf("%s\t", map.get(header[i])); - } - System.out.println(); - } + } + + public int getLength() { + return body.size(); + } + + public String get(int i, String key) { + return body.get(i).get(key); } } -- cgit v1.2.3