diff --git a/src/se/edu/inclass/Main.java b/src/se/edu/inclass/Main.java index 3781393..05c4476 100644 --- a/src/se/edu/inclass/Main.java +++ b/src/se/edu/inclass/Main.java @@ -16,11 +16,17 @@ public static void main(String[] args) { DataManager dm = new DataManager("./data/data.txt"); ArrayList tasksData = dm.loadData(); + printData(tasksData); + System.out.println("Printing deadlines"); printDeadlines(tasksData); System.out.println("Total number of deadlines: " + countDeadlines(tasksData)); + printDataUsingStreams(tasksData); + System.out.println( + "Count Deadlines: " + countDeadlinesUsingStream(tasksData) + ); } private static int countDeadlines(ArrayList tasksData) { @@ -33,12 +39,28 @@ private static int countDeadlines(ArrayList tasksData) { return count; } + public static int countDeadlinesUsingStream(ArrayList tasksData) { + System.out.println("Count Deadlines using stream"); + int count; + count = (int) tasksData.stream() + .filter(task -> task instanceof Deadline) + .count(); + + return count; + } + public static void printData(ArrayList tasksData) { for (Task t : tasksData) { System.out.println(t); } } + public static void printDataUsingStreams(ArrayList taskData) { + System.out.println("Use task stream"); + taskData.stream() + .forEach(System.out::println); + } + public static void printDeadlines(ArrayList tasksData) { for (Task t : tasksData) { if (t instanceof Deadline) { @@ -46,4 +68,11 @@ public static void printDeadlines(ArrayList tasksData) { } } } + + public static void printDeadlinesUsingStream(ArrayList tasksData) { + System.out.println("Print deadlines using stream"); + tasksData.stream() + .filter(task -> task instanceof Deadline) + .forEach(System.out::println); + } }