Skip to content

Conversation

SachinGoud9
Copy link

No description provided.

@SachinGoud9 SachinGoud9 changed the title feat: Modified code according to SOLID principles. feat: Modified code according to SOLID principles Task List. Sep 8, 2023
Comment on lines +58 to +103
public void add(String commandLine) {
String[] subcommandRest = commandLine.split(" ", 2);
String subcommand = subcommandRest[0];
if (subcommand.equals("project")) {
addProject(subcommandRest[1]);
} else if (subcommand.equals("task")) {
String[] projectTask = subcommandRest[1].split(" ", 2);
addTask(projectTask[0], projectTask[1]);
}
}

public void addProject(String name) {
tasks.put(name, new ArrayList<Task>());
}

public void addTask(String project, String description) {
List<Task> projectTasks = tasks.get(project);
if (projectTasks == null) {
out.printf("Could not find a project with the name \"%s\".", project);
out.println();
return;
}
projectTasks.add(new Task(nextId(), description, false));
}

public void check(String idString) {
setDone(idString, true);
}

public void uncheck(String idString) {
setDone(idString, false);
}

public void setDone(String idString, boolean done) {
int id = Integer.parseInt(idString);
for (Map.Entry<String, List<Task>> project : tasks.entrySet()) {
for (Task task : project.getValue()) {
if (task.getId() == id) {
task.setDone(done);
return;
}
}
}
out.printf("Could not find a task with an ID of %d.", id);
out.println();
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create a POJO and use it here, eliminate primitive obsession

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants