summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorArghKevin <kagheli@student.sdccd.edu>2024-05-16 02:03:54 -0700
committerArghKevin <kagheli@student.sdccd.edu>2024-05-16 02:03:54 -0700
commit03991b0cabc7a510e0d2ff7ed1a2f0bbc300e7c1 (patch)
tree632b3da066b54ed50345927ad909e88d60caac5c /src
parent9515724e16f7cf968f80509ef6fe5657e592a3f7 (diff)
Structure CSVReader to be externally iterable.
Diffstat (limited to 'src')
-rw-r--r--src/CSVReader.java20
1 files 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<String,String> 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);
}
}