From 63f6d4d738f2c1d153eb71725eed37c44c369ea1 Mon Sep 17 00:00:00 2001 From: Lu Wenqi Date: Fri, 1 Nov 2019 01:39:58 +0800 Subject: [PATCH] fix tag add delete and edit bugs --- .../algobase/logic/commands/DeleteTagCommand.java | 2 +- .../java/seedu/algobase/model/ModelManager.java | 14 +++++--------- .../seedu/algobase/model/tag/UniqueTagList.java | 5 ++--- src/main/resources/view/MainWindow.fxml | 2 +- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/main/java/seedu/algobase/logic/commands/DeleteTagCommand.java b/src/main/java/seedu/algobase/logic/commands/DeleteTagCommand.java index 1150e7f645f..842fd41c5b0 100644 --- a/src/main/java/seedu/algobase/logic/commands/DeleteTagCommand.java +++ b/src/main/java/seedu/algobase/logic/commands/DeleteTagCommand.java @@ -43,8 +43,8 @@ public CommandResult execute(Model model, CommandHistory history) throws Command } Tag tagToDelete = lastShownList.get(targetIndex.getZeroBased()); - model.deleteTag(tagToDelete); model.deleteTags(tagToDelete); + model.deleteTag(tagToDelete); return new CommandResult(String.format(MESSAGE_DELETE_TAG_SUCCESS, tagToDelete.getName())); } diff --git a/src/main/java/seedu/algobase/model/ModelManager.java b/src/main/java/seedu/algobase/model/ModelManager.java index 3fc79915c67..d78e1205859 100644 --- a/src/main/java/seedu/algobase/model/ModelManager.java +++ b/src/main/java/seedu/algobase/model/ModelManager.java @@ -191,10 +191,8 @@ public void deleteTag(Tag target) { public void deleteTags(Tag target) { for (Problem problem : filteredProblems) { Set targetTags = problem.getTags(); - for (Tag tag : targetTags) { - if (tag.getName().equals(target.getName())) { - problem.deleteTag(tag); - } + if (targetTags.contains(target)) { + problem.deleteTag(target); } } } @@ -224,11 +222,9 @@ public void setTags(Tag target, Tag editedTag) { requireAllNonNull(target, editedTag); for (Problem problem : filteredProblems) { Set targetTags = problem.getTags(); - for (Tag tag : targetTags) { - if (tag.getName().equals(target.getName())) { - problem.addTag(editedTag); - problem.deleteTag(tag); - } + if (targetTags.contains(target)) { + problem.deleteTag(target); + problem.addTag(editedTag); } } } diff --git a/src/main/java/seedu/algobase/model/tag/UniqueTagList.java b/src/main/java/seedu/algobase/model/tag/UniqueTagList.java index 65c4deb899b..5ee977f7148 100644 --- a/src/main/java/seedu/algobase/model/tag/UniqueTagList.java +++ b/src/main/java/seedu/algobase/model/tag/UniqueTagList.java @@ -42,10 +42,9 @@ public boolean contains(Tag toCheck) { */ public void add(Tag toAdd) { requireNonNull(toAdd); - if (contains(toAdd)) { - throw new DuplicateTagException(); + if (!contains(toAdd)) { + internalList.add(toAdd); } - internalList.add(toAdd); } /** diff --git a/src/main/resources/view/MainWindow.fxml b/src/main/resources/view/MainWindow.fxml index d70eb882d15..8701ecd605e 100644 --- a/src/main/resources/view/MainWindow.fxml +++ b/src/main/resources/view/MainWindow.fxml @@ -33,7 +33,7 @@ - +