diff --git a/Lec6.iml b/Lec6.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Lec6.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/se/edu/inclass/Main.java b/src/se/edu/inclass/Main.java index 25ea5d7..86c6b54 100644 --- a/src/se/edu/inclass/Main.java +++ b/src/se/edu/inclass/Main.java @@ -14,10 +14,16 @@ public class Main { public static void main(String[] args) { DataManager dm = new DataManager("./data/data.txt"); ArrayList tasksData = dm.loadData(); + System.out.println("All data:"); + printData(tasksData); +//code to stage System.out.println("Printing deadlines"); printDeadlines(tasksData); - + printDataUsingStream(tasksData); + printDeadlines(tasksData); + printDeadlinesUsingStream(tasksData); + System.out.println(countDeadlinesUsingStream(tasksData)); System.out.println("Total number of deadlines: " + countDeadlines(tasksData)); } @@ -32,17 +38,43 @@ private static int countDeadlines(ArrayList tasksData) { return count; } + private static int countDeadlinesUsingStream(ArrayList tasks) { + System.out.println("count using stream"); + int count = (int) tasks.stream() + .filter(t -> t instanceof Deadline) + .count(); + return count; + + } + public static void printData(ArrayList tasksData) { + System.out.println("Printing data using loop"); for (Task t : tasksData) { System.out.println(t); } } + public static void printDataUsingStream(ArrayList tasks) { + System.out.println("Printing data using streams"); + tasks.stream(). + forEach(System.out::println); + + } + + public static void printDeadlines(ArrayList tasksData) { + System.out.println("Print deadlines using loop"); for (Task t : tasksData) { if (t instanceof Deadline) { System.out.println(t); } } } -} \ No newline at end of file + + public static void printDeadlinesUsingStream(ArrayList tasks) { + System.out.println("Print deadlines using stream"); + tasks.parallelStream() + .filter(t -> t instanceof Deadline) //lambda + .forEach(System.out::println); + } +}