Skip to content

Commit

Permalink
fixing delete bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhil-2101 committed Apr 15, 2024
1 parent 6994579 commit 90208fa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ The generic sequence diagram provides a visual representation of the interaction
ActiveEdge application. It illustrates how user commands are parsed, executed, and interact with different modules such
as user interface, data storage, and task management.

![Generic Sequence Diagram](https://github.com/AY2324S2-CS2113-W12-2/tp/blob/master/images/GenericSequenceDiagram.png?raw=true)
![Generic Sequence Diagram](https://github.com/AY2324S2-CS2113-W12-2/tp/blob/master/images/GenericSequenceDiagram1.png?raw=true)

### Main Component
The `Main` component, residing as a method in the `ActiveEdge` class,serves as the main entry point for the ActiveEdge application, handling user input and
Expand Down
30 changes: 23 additions & 7 deletions src/main/java/command/DeleteLogCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public DeleteLogCommand(String inputTrimmed) {
this.errorRaised = false;
if(parts.length == 2){
if(parts[1].contains("i/")){
indexParts = parts[1].trim().split("i/");
indexParts = parts[1].trim().split("\\s*i/\\s*");;
this.index = Integer.parseInt(indexParts[1].trim());
this.description = indexParts[0].trim().replaceAll("\\s+", " ");
if(index <= 0){
Expand All @@ -36,7 +36,21 @@ public DeleteLogCommand(String inputTrimmed) {
} else {
//If no index to be deleted is passed, 1 is considered as the index.
this.index = 1;
this.description = parts[1].trim().replaceAll("\\s+", " ");
String[] descriptionParts = parts[1].split("\\s*i/\\s*|\\s+");
this.description = descriptionParts[0].trim();
if (descriptionParts.length > 1) {
String[] quantityParts = descriptionParts[1].trim().split("\\s+");
if (quantityParts.length > 0) {
try {
Integer.parseInt(quantityParts[0]);
String quantityWithoutSpaces = quantityParts[0].trim().replaceAll("\\s+", "");
this.description += " " + quantityWithoutSpaces;
} catch (NumberFormatException e) {
// If it's not a number, consider it as part of description
this.description += " " + descriptionParts[1].trim();
}
}
}
}
} else {
CommandUi.printInvalidDeleteFormatMessage();
Expand All @@ -53,12 +67,14 @@ public void execute() {
int countIndex = 0;
for (int i = 0; i < LogList.logList.size(); i++) {
Log log = LogList.logList.get(i);
if (log.getDescription().toLowerCase().startsWith("water")) {
if (log instanceof LogWater) { // Check if it's a WaterLog before casting
String logDescription = log.getDescription().toLowerCase().trim();
if (logDescription.startsWith("water")){
if (log instanceof LogWater) {
String targetDescription = description.trim().replaceAll("\\s+", "");
LogWater logWater = (LogWater) log;

if (((logWater.getQuantity()) + "ml").equalsIgnoreCase(description)) {
countIndex = countIndex + 1;
String quantityString = (logWater.getQuantity()) + "ml";
if (quantityString.equals(targetDescription)) {
countIndex++;
if(countIndex == index){
Log deletedLog = LogList.delete(i);
CommandUi.printLogDeletedMessage(deletedLog);
Expand Down

0 comments on commit 90208fa

Please sign in to comment.