Skip to content

Commit

Permalink
Merge pull request #211 from ChinYanXu/DeleteFunctionEnhancement
Browse files Browse the repository at this point in the history
Delete function enhancement and add valid inputs to Junit tests
  • Loading branch information
EugeneChanJiajun committed Apr 9, 2024
2 parents 0590f1b + 8ed4232 commit 87aefa9
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 105 deletions.
13 changes: 11 additions & 2 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,14 @@ ____________________________________________________________
### Deleting a travel activity : `delete`
Deletes a travel activity from the travel activity list

Format: `delete INDEX`
* `INDEX` has to be a number that is shown in the list of travel activities
Format: `delete ACTIVITY`
* `ACTIVITY` can be an index of an activity or a keyword found in the description of an activity in the list of travel
* activities. If the user writes a number only the activity in that particular index on the list gets deleted.
* If the user writes a keyword then every activity with that keyword in its description gets deleted.

Examples of usage:
* `delete 1`
* `delete Eiffel`

Expected output:
```
Expand All @@ -192,6 +195,12 @@ I have removed this activity:
Accommodation: Four Seasons Hotel :14 Mar 2025 :2 days
____________________________________________________________
```
```
____________________________________________________________
I have removed this activity:
1. Landmark: Eiffel Tower :14 Mar 2025 :2 hours (go up tower)
____________________________________________________________
```

### Listing all the travel activities : `list`
Shows all the travel activities including their tags and expenses
Expand Down
14 changes: 14 additions & 0 deletions omni.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
accommodation / 0 / nus rvrc / 2024-04-04 / 2 days / test / $50
accommodation / 0 / nus pgpr / 2025-10-12 / 5 years / campus stay /
accommodation / 0 / nus utr / 2025-09-12 / 5 years / campus stay /
landmark / 0 / berlin wall / 2027-12-15 / 5 hours / historic site /
landmark / 0 / utown / 2028-08-14 / 10 hours / recreational centre /
landmark / 0 / supper stretch / 2027-08-18 / 2 hours / tourist hotspot /
food / 0 / utown mala / 2028-06-19 / 2 hours / spicy /
food / 0 / pgpr mala / 2026-07-07 / 1 hours / spicy /
food / 0 / pgpr waffle / 2026-03-09 / 0.5 hours / non-spicy /
general / 0 / esplanade / 2026-03-19 / 3 hours / concert /
general / 0 / merlion / 2026-04-07 / 2 hours / sightseeing /
general / 0 / chinatown / 2025-02-21 / 5 hours / sightseeing /
accommodation / 0 / description / 2024-10-04 / 2 days / test /

7 changes: 3 additions & 4 deletions src/main/java/seedu/omnitravel/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,10 @@ public static void addCommand(String line, TravelActivityList list) throws OmniE
* @throws OmniException if command.length != 2 && command[1] is not numeric
*/
public static void deleteCommand(String[] command, TravelActivityList list) throws OmniException {
if (command.length == 2 && CheckParameters.isNumeric(command[1])){
int listNumber = Integer.parseInt(command[1]);
list.removeTravelActivity(listNumber);
if (command.length == 2){
list.removeTravelActivity(command[1]);
} else {
throw new OmniException("Please specify which activity index to delete");
throw new OmniException("Please specify which activity index or description to delete");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,41 @@ public void listTravelActivities(){
public int getNoOfTravelActivities(){
return noOfActivities;
}

/**
* Removes travel activity from the travel activity list
* @param activityNumber The travel activity number on the list
* @param activityNumber The travel activity index number or description on the list
*/
public void removeTravelActivity(int activityNumber) throws OmniException {
assert activityNumber != 0 :"There is not activities in the list";
if(activityNumber > travelActivities.size() || (activityNumber <= 0)){
throw new OmniException("Travel activity cannot be found!");
public void removeTravelActivity(String activityNumber) throws OmniException {
try {
assert Integer.parseInt(activityNumber) != 0 : "There is not activities in the list";
int indexOfActivity = Integer.parseInt(activityNumber) - 1;
int initialListSize = noOfActivities;
TravelActivity removedActivity = travelActivities.get(indexOfActivity);
travelActivities.remove(indexOfActivity);
System.out.println("I have removed this activity:");
System.out.println(removedActivity);
noOfActivities -= 1;
int newSize = noOfActivities;
assert newSize == initialListSize - 1 : "There is an error with list size!";
} catch (NumberFormatException e) {
int foundCounter = 0;
for (int iterator = 0; iterator < travelActivities.size(); iterator += 1) {
if (travelActivities.get(iterator).getPlan().toLowerCase().contains(activityNumber.toLowerCase())) {
if (foundCounter == 0) {
System.out.println("I have removed this activity:");
}
System.out.println(Integer.toString(foundCounter + 1) + ". " + travelActivities.get(iterator));
travelActivities.remove(iterator);
noOfActivities -= 1;
foundCounter += 1;
assert noOfActivities >= 0 : "There is an error with list size!";
}
}
if (foundCounter == 0) {
System.out.println("Travel activity cannot be found!");
}
}
int indexOfActivity = activityNumber - 1;
int initialListSize = noOfActivities;
TravelActivity removedActivity = travelActivities.get(indexOfActivity);
travelActivities.remove(indexOfActivity);
System.out.println("I have removed this activity:");
System.out.println(removedActivity);
noOfActivities-=1;
int newSize = noOfActivities;
assert newSize == initialListSize - 1 :"There is an error with list size!";
}

/**
Expand Down
Loading

0 comments on commit 87aefa9

Please sign in to comment.