Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stream #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/se/edu/inclass/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@ public static void main(String[] args) {
DataManager dm = new DataManager("./data/data.txt");
ArrayList<Task> 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<Task> tasksData) {
Expand All @@ -33,17 +39,40 @@ private static int countDeadlines(ArrayList<Task> tasksData) {
return count;
}

public static int countDeadlinesUsingStream(ArrayList<Task> 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<Task> tasksData) {
for (Task t : tasksData) {
System.out.println(t);
}
}

public static void printDataUsingStreams(ArrayList<Task> taskData) {
System.out.println("Use task stream");
taskData.stream()
.forEach(System.out::println);
}

public static void printDeadlines(ArrayList<Task> tasksData) {
for (Task t : tasksData) {
if (t instanceof Deadline) {
System.out.println(t);
}
}
}

public static void printDeadlinesUsingStream(ArrayList<Task> tasksData) {
System.out.println("Print deadlines using stream");
tasksData.stream()
.filter(task -> task instanceof Deadline)
.forEach(System.out::println);
}
}