Skip to content

Commit

Permalink
Sarthak | Refactors Projects, removes extends LinkedHashMap
Browse files Browse the repository at this point in the history
  • Loading branch information
SarthakMakhija committed Jan 9, 2025
1 parent b0bd02c commit a4f4cb0
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/main/java/com/codurance/training/tasks/Projects.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
package com.codurance.training.tasks;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;

public class Projects extends LinkedHashMap<String, Project> {
public class Projects {

private final Map<String, Project> projects = new LinkedHashMap<>();

public void addProject(String name) {
this.put(name, new Project(name));
this.projects.put(name, new Project(name));
}

public void addTaskToProjectWithName(String projectName, Task task) {
Project project = this.get(projectName);
Project project = this.projects.get(projectName);
if (project == null) {
throw new IllegalArgumentException("Unknown project: " + projectName);
}
project.addTask(task);
}

public boolean markTaskWithIdDone(int id) {
return this.values().stream().anyMatch((Project project) -> project.markTaskWithIdDone(id));
return this.projects.values().stream().anyMatch((Project project) -> project.markTaskWithIdDone(id));
}

public boolean markTaskWithIdNotDone(int id) {
return this.values().stream().anyMatch((Project project) -> project.markTaskWithIdNotDone(id));
return this.projects.values().stream().anyMatch((Project project) -> project.markTaskWithIdNotDone(id));
}

public String format() {
return this.values().stream().map(Project::format).collect(Collectors.joining());
return this.projects.values().stream().map(Project::format).collect(Collectors.joining());
}
}

Expand Down

0 comments on commit a4f4cb0

Please sign in to comment.