feat: Modified code according to SOLID principles Task List.#47
Open
SachinGoud9 wants to merge 1 commit intocodurance:masterfrom
Open
feat: Modified code according to SOLID principles Task List.#47SachinGoud9 wants to merge 1 commit intocodurance:masterfrom
SachinGoud9 wants to merge 1 commit intocodurance:masterfrom
Conversation
abhi-zorro
suggested changes
Sep 11, 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(); | ||
| } |
There was a problem hiding this comment.
create a POJO and use it here, eliminate primitive obsession
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.