From f23a7717dbbc004ab95a4b888e600258b685c329 Mon Sep 17 00:00:00 2001 From: Zachary Springer Date: Tue, 15 Oct 2024 14:16:18 -0700 Subject: [PATCH 1/8] Added comments to the first 3 lines of Java code --- src/Main.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Main.java b/src/Main.java index e5571ea..5cdebd6 100644 --- a/src/Main.java +++ b/src/Main.java @@ -6,9 +6,12 @@ public class Main { public static void main(String[] args) { + // Initializing a scanner that accepts input from the terminal Scanner s = new Scanner(System.in); + // Prints a prompt for the user to input a file name System.out.print("Enter the CSV filename: "); + // The variable takes in the file name inputed by the user as a String String f = s.nextLine(); List> dta = new ArrayList<>(); @@ -18,11 +21,11 @@ public static void main(String[] args) { while (fs.hasNextLine()) { String[] v = fs.nextLine().split(","); - int chg = Integer.parseInt(v[2]); + int chg = Integer.parseInt(v[2]); Map mp1 = new HashMap<>(); - mp1.put("id", v[0]); - mp1.put("tm", v[1]); + mp1.put("id", v[0]); + mp1.put("tm", v[1]); mp1.put("chg", String.valueOf(chg)); dta.add(mp1); } @@ -52,7 +55,7 @@ public static void main(String[] args) { if (inp.equalsIgnoreCase("all")) { sel = dta; } else { - String id = "fork" + inp; + String id = "fork" + inp; sel = mp2.get(id); } @@ -61,7 +64,7 @@ public static void main(String[] args) { DateTimeFormatter f1 = DateTimeFormatter.ISO_DATE_TIME; LocalDateTime lat = null; for (Map d : sel) { - LocalDateTime t = LocalDateTime.parse(d.get("tm"), f1); + LocalDateTime t = LocalDateTime.parse(d.get("tm"), f1); if (lat == null || t.isAfter(lat)) { lat = t; } From e8fd03bb5b6de5234bf9ccea47cd8ac17387dcb0 Mon Sep 17 00:00:00 2001 From: Juno Arciaga Date: Tue, 15 Oct 2024 14:17:34 -0700 Subject: [PATCH 2/8] Added a comment on line 15 --- src/Main.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Main.java b/src/Main.java index e5571ea..f5e38b7 100644 --- a/src/Main.java +++ b/src/Main.java @@ -11,7 +11,9 @@ public static void main(String[] args) { System.out.print("Enter the CSV filename: "); String f = s.nextLine(); - List> dta = new ArrayList<>(); + + // Lists all the commits were made and prints out the data of each commit + List> dta = new ArrayList<>(); try (Scanner fs = new Scanner(new File(f))) { fs.nextLine(); From 748e5b9d8e1b5911f5e14ccca549cd10286f493d Mon Sep 17 00:00:00 2001 From: Juno Arciaga Date: Tue, 15 Oct 2024 14:28:08 -0700 Subject: [PATCH 3/8] Added more comments from lines 18-28s git push git status --- src/Main.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Main.java b/src/Main.java index 5450805..d654313 100644 --- a/src/Main.java +++ b/src/Main.java @@ -17,10 +17,15 @@ public static void main(String[] args) { // Lists all the commits were made and prints out the data of each commit List> dta = new ArrayList<>(); + + // Scans the new file from user's input try (Scanner fs = new Scanner(new File(f))) { fs.nextLine(); + // While there's still information in the file, the scanner will continuously scan for files while (fs.hasNextLine()) { + + // Array of strings to show the results of scanner that splits each line with a comma String[] v = fs.nextLine().split(","); int chg = Integer.parseInt(v[2]); From b7ed8f992705760c9e37344c737062fd9cbb7013 Mon Sep 17 00:00:00 2001 From: Zachary Springer Date: Tue, 15 Oct 2024 14:35:08 -0700 Subject: [PATCH 4/8] Renamed variable mp1 to commits --- src/Main.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Main.java b/src/Main.java index d654313..0318bf5 100644 --- a/src/Main.java +++ b/src/Main.java @@ -14,27 +14,28 @@ public static void main(String[] args) { // The variable takes in the file name inputed by the user as a String String f = s.nextLine(); - // Lists all the commits were made and prints out the data of each commit - List> dta = new ArrayList<>(); + List> dta = new ArrayList<>(); // Scans the new file from user's input try (Scanner fs = new Scanner(new File(f))) { fs.nextLine(); - // While there's still information in the file, the scanner will continuously scan for files + // While there's still information in the file, the scanner will continuously + // scan for files while (fs.hasNextLine()) { - // Array of strings to show the results of scanner that splits each line with a comma + // Array of strings to show the results of scanner that splits each line with a + // comma String[] v = fs.nextLine().split(","); int chg = Integer.parseInt(v[2]); - Map mp1 = new HashMap<>(); - mp1.put("id", v[0]); - mp1.put("tm", v[1]); - mp1.put("chg", String.valueOf(chg)); - dta.add(mp1); + Map commits = new HashMap<>(); + commits.put("id", v[0]); + commits.put("tm", v[1]); + commits.put("chg", String.valueOf(chg)); + dta.add(commits); } } catch (FileNotFoundException e) { System.out.println("Error reading the file: " + e.getMessage()); From 0fe1d8b435f49c82aca608a4299d5121d1e223be Mon Sep 17 00:00:00 2001 From: Juno Arciaga Date: Tue, 15 Oct 2024 14:37:11 -0700 Subject: [PATCH 5/8] Changed variable dta to commitStats --- src/Main.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Main.java b/src/Main.java index 0318bf5..50390ba 100644 --- a/src/Main.java +++ b/src/Main.java @@ -15,7 +15,7 @@ public static void main(String[] args) { String f = s.nextLine(); // Lists all the commits were made and prints out the data of each commit - List> dta = new ArrayList<>(); + List> commitStats = new ArrayList<>(); // Scans the new file from user's input try (Scanner fs = new Scanner(new File(f))) { @@ -35,7 +35,7 @@ public static void main(String[] args) { commits.put("id", v[0]); commits.put("tm", v[1]); commits.put("chg", String.valueOf(chg)); - dta.add(commits); + commitStats.add(commits); } } catch (FileNotFoundException e) { System.out.println("Error reading the file: " + e.getMessage()); @@ -44,7 +44,7 @@ public static void main(String[] args) { } Map>> mp2 = new HashMap<>(); - for (Map d : dta) { + for (Map d : commitStats) { String id = d.get("id"); List> lst = mp2.get(id); if (lst == null) { @@ -61,7 +61,7 @@ public static void main(String[] args) { List> sel; if (inp.equalsIgnoreCase("all")) { - sel = dta; + sel = commitStats; } else { String id = "fork" + inp; sel = mp2.get(id); From bad09f317e60284a596d603d86125f37601c450f Mon Sep 17 00:00:00 2001 From: Zachary Springer Date: Tue, 15 Oct 2024 14:56:56 -0700 Subject: [PATCH 6/8] Added helper method for parsing the CSV file --- src/Main.java | 66 +++++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/src/Main.java b/src/Main.java index 50390ba..076f5ce 100644 --- a/src/Main.java +++ b/src/Main.java @@ -6,42 +6,16 @@ public class Main { public static void main(String[] args) { + // Initializing a scanner that accepts input from the terminal Scanner s = new Scanner(System.in); // Prints a prompt for the user to input a file name System.out.print("Enter the CSV filename: "); // The variable takes in the file name inputed by the user as a String - String f = s.nextLine(); - - // Lists all the commits were made and prints out the data of each commit - List> commitStats = new ArrayList<>(); + String filename = s.nextLine(); - // Scans the new file from user's input - try (Scanner fs = new Scanner(new File(f))) { - fs.nextLine(); - - // While there's still information in the file, the scanner will continuously - // scan for files - while (fs.hasNextLine()) { - - // Array of strings to show the results of scanner that splits each line with a - // comma - String[] v = fs.nextLine().split(","); - - int chg = Integer.parseInt(v[2]); - - Map commits = new HashMap<>(); - commits.put("id", v[0]); - commits.put("tm", v[1]); - commits.put("chg", String.valueOf(chg)); - commitStats.add(commits); - } - } catch (FileNotFoundException e) { - System.out.println("Error reading the file: " + e.getMessage()); - s.close(); - return; - } + List> commitStats = parseCSV(filename); Map>> mp2 = new HashMap<>(); for (Map d : commitStats) { @@ -110,5 +84,39 @@ public static void main(String[] args) { System.out.println("Min lines changed in a commit: " + mn); s.close(); + } + + public static List> parseCSV(String filename) { + + // Lists all the commits were made and prints out the data of each commit + List> commitStats = new ArrayList<>(); + // Scans the new file from user's input + try (Scanner fs = new Scanner(new File(filename))) { + fs.nextLine(); + + // While there's still information in the file, the scanner will continuously + // scan for files + while (fs.hasNextLine()) { + + // Array of strings to show the results of scanner that splits each line with a + // comma + String[] v = fs.nextLine().split(","); + + int chg = Integer.parseInt(v[2]); + + Map commits = new HashMap<>(); + commits.put("id", v[0]); + commits.put("tm", v[1]); + commits.put("chg", String.valueOf(chg)); + commitStats.add(commits); + } + } catch (FileNotFoundException e) { + System.out.println("Error reading the file: " + e.getMessage()); + } + + return commitStats; + + } + } From fd1d54bd48826742c3083aa56bc0ba588201c302 Mon Sep 17 00:00:00 2001 From: Juno Arciaga Date: Tue, 15 Oct 2024 15:06:22 -0700 Subject: [PATCH 7/8] Added helper method in MainTest class --- src/MainTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/MainTest.java b/src/MainTest.java index 1141d9e..e1af307 100644 --- a/src/MainTest.java +++ b/src/MainTest.java @@ -12,6 +12,8 @@ public class MainTest { void testParseCSV() { // You will finish implementing this method in Wave 3 // TODO: Call Main.parseCSV("data/small_commit_data.csv") here and set it to an actual variable + + List> readCsv = Main.parseCSV("data/small_commit_data.csv"); // Sets up the expected value for you. You do not need to edit this part @@ -36,6 +38,7 @@ void testParseCSV() { expectedCommits.add(commit3); // Finish expected value setup + // TODO: Assert that the expected equals the actual } } From b1bfce2ed1f2a27de03ab0ceffa5fa1d356d598f Mon Sep 17 00:00:00 2001 From: Zachary Springer Date: Tue, 15 Oct 2024 15:10:44 -0700 Subject: [PATCH 8/8] Added a test for the helper method... I think --- src/MainTest.java | 66 +++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/MainTest.java b/src/MainTest.java index e1af307..310237a 100644 --- a/src/MainTest.java +++ b/src/MainTest.java @@ -8,37 +8,37 @@ import org.junit.jupiter.api.Test; public class MainTest { - @Test - void testParseCSV() { - // You will finish implementing this method in Wave 3 - // TODO: Call Main.parseCSV("data/small_commit_data.csv") here and set it to an actual variable - - List> readCsv = Main.parseCSV("data/small_commit_data.csv"); - - - // Sets up the expected value for you. You do not need to edit this part - List> expectedCommits = new ArrayList<>(); - - Map commit1 = new HashMap<>(); - commit1.put("chg", "179"); - commit1.put("tm", "2024-10-15T08:02:04Z"); - commit1.put("id", "fork1"); - expectedCommits.add(commit1); - - Map commit2 = new HashMap<>(); - commit2.put("chg", "1"); - commit2.put("tm", "2024-10-12T19:48:59Z"); - commit2.put("id", "fork2"); - expectedCommits.add(commit2); - - Map commit3 = new HashMap<>(); - commit3.put("chg", "13"); - commit3.put("tm", "2024-10-10T21:56:18Z"); - commit3.put("id", "fork2"); - expectedCommits.add(commit3); - // Finish expected value setup - - - // TODO: Assert that the expected equals the actual - } + @Test + void testParseCSV() { + // You will finish implementing this method in Wave 3 + // TODO: Call Main.parseCSV("data/small_commit_data.csv") here and set it to an + // actual variable + + List> readCsv = Main.parseCSV("data/small_commit_data.csv"); + + // Sets up the expected value for you. You do not need to edit this part + List> expectedCommits = new ArrayList<>(); + + Map commit1 = new HashMap<>(); + commit1.put("chg", "179"); + commit1.put("tm", "2024-10-15T08:02:04Z"); + commit1.put("id", "fork1"); + expectedCommits.add(commit1); + + Map commit2 = new HashMap<>(); + commit2.put("chg", "1"); + commit2.put("tm", "2024-10-12T19:48:59Z"); + commit2.put("id", "fork2"); + expectedCommits.add(commit2); + + Map commit3 = new HashMap<>(); + commit3.put("chg", "13"); + commit3.put("tm", "2024-10-10T21:56:18Z"); + commit3.put("id", "fork2"); + expectedCommits.add(commit3); + // Finish expected value setup + + // TODO: Assert that the expected equals the actual + readCsv = expectedCommits; + } }