forked from nus-cs2113-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Branch tag list #193
Merged
EugeneChanJiajun
merged 4 commits into
AY2324S2-CS2113-T12-4:master
from
daryltay415:branch-tag-list
Apr 6, 2024
Merged
Branch tag list #193
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
general / 0 / go to paris / 2024-12-12 / 2 hours / hello / $50 | ||
food / 0 / food / 2024-12-12 / now / / | ||
food / 0 / food / 2024-12-12 / 2 hours / / $30 | ||
general / 0 / hello world / 2040-12-12 / 2 hours / your mom / |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,26 +9,12 @@ | |
import seedu.omnitravel.ui.Ui; | ||
|
||
import java.time.LocalDate; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
public class Parser { | ||
|
||
private static Logger logger = Logger.getLogger("ParserLogger"); | ||
/** | ||
* Checks if the string is a number | ||
* | ||
* @param str The string that is to be defined as a number or sentence | ||
* @return true or false | ||
*/ | ||
public static boolean isNumeric(String str) { | ||
try { | ||
Double.parseDouble(str); | ||
return true; | ||
} catch(NumberFormatException e){ | ||
return false; | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Obtains the list of travel activities | ||
|
@@ -63,7 +49,11 @@ public static void activityCommand(String line, TravelActivityList list) throws | |
CheckParameters.addExceptions(input, commandType, line); | ||
String description = line.substring(commandIndex + 1, line.indexOf("/date")).trim(); | ||
LocalDate date = LocalDate.parse(input[1]); | ||
if(date.isBefore(LocalDate.now())){ | ||
throw new OmniException("Please input a future date."); | ||
} | ||
String duration = input[2].trim(); | ||
CheckParameters.containsWords(duration); | ||
String tag = (line.contains("/tag") && input.length == 4) ? input[3].trim() : ""; | ||
TravelActivity activity; | ||
switch (commandType) { | ||
|
@@ -97,11 +87,15 @@ public static void activityCommand(String line, TravelActivityList list) throws | |
public static void addCommand(String line, TravelActivityList list) throws OmniException{ | ||
Ui.printLine(); | ||
String[] command = line.split("/date | /duration | /tag "); | ||
logger.log(Level.INFO, command[0] + " // " + command[1]); | ||
//logger.log(Level.INFO, command[0] + " // " + command[1]); | ||
CheckParameters.addExceptions(command, "add", line); | ||
String description = line.substring(4, line.indexOf("/date")); | ||
LocalDate date = LocalDate.parse(command[1]); | ||
if(date.isBefore(LocalDate.now())){ | ||
throw new OmniException("Please input a future date."); | ||
} | ||
String duration = command[2].trim(); | ||
CheckParameters.containsWords(duration); | ||
String tag = (line.contains("/tag") && command.length == 4) ? command[3].trim() : ""; | ||
TravelActivity newActivity = new TravelActivity(description, date, duration, tag, ""); | ||
list.addTravelActivity(newActivity); | ||
|
@@ -118,11 +112,11 @@ 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 && isNumeric(command[1])){ | ||
if (command.length == 2 && CheckParameters.isNumeric(command[1])){ | ||
int listNumber = Integer.parseInt(command[1]); | ||
list.removeTravelActivity(listNumber); | ||
} else { | ||
throw new OmniException("Please specify which activity to delete"); | ||
throw new OmniException("Please specify which activity index to delete"); | ||
} | ||
} | ||
|
||
|
@@ -134,7 +128,7 @@ public static void deleteCommand(String[] command, TravelActivityList list) thro | |
* @throws OmniException if command.length != 2 && command[1] is not numeric | ||
*/ | ||
public static void checkCommand(String[] command, TravelActivityList list) throws OmniException { | ||
if (command.length == 2 && isNumeric(command[1])){ | ||
if (command.length == 2 && CheckParameters.isNumeric(command[1])){ | ||
int listNumber = Integer.parseInt(command[1]); | ||
list.checkTravelActivity(listNumber); | ||
} else { | ||
|
@@ -150,7 +144,7 @@ public static void checkCommand(String[] command, TravelActivityList list) throw | |
* @throws OmniException if command.length != 2 && command[1] is not numeric | ||
*/ | ||
public static void uncheckCommand(String[] command, TravelActivityList list) throws OmniException { | ||
if (command.length == 2 && isNumeric(command[1])){ | ||
if (command.length == 2 && CheckParameters.isNumeric(command[1])){ | ||
int listNumber = Integer.parseInt(command[1]); | ||
|
||
list.uncheckTravelActivity(listNumber); | ||
|
@@ -169,7 +163,7 @@ public static void uncheckCommand(String[] command, TravelActivityList list) thr | |
*/ | ||
public static void tagCommand(String line, TravelActivityList list) throws OmniException { | ||
String[] command = line.split(" "); | ||
if (command.length >= 3 && isNumeric(command[1])){ | ||
if (command.length >= 3 && CheckParameters.isNumeric(command[1])){ | ||
String index = command[1]; | ||
String[] tagSplit = line.split(index); | ||
String tag = tagSplit[1].trim(); | ||
|
@@ -190,7 +184,7 @@ public static void tagCommand(String line, TravelActivityList list) throws OmniE | |
* @throws OmniException if command.length != 2 && command[1] is not numeric | ||
*/ | ||
public static void removeTagCommand(String[] command, TravelActivityList list) throws OmniException { | ||
if (command.length == 2 && isNumeric(command[1])) { | ||
if (command.length == 2 && CheckParameters.isNumeric(command[1])) { | ||
int listNumber = Integer.parseInt(command[1]); | ||
list.removeTag(listNumber); | ||
} else { | ||
|
@@ -222,10 +216,10 @@ public static void updateCommand(String line, TravelActivityList list) throws Om | |
|
||
public static void findTagCommand(String line, TravelActivityList list) throws OmniException { | ||
String[] command = line.split("findtag"); | ||
if (command.length < 1) { | ||
throw new OmniException("Please check that your update command is in this format: findtag <tag>"); | ||
} else { | ||
if (command.length > 1) { | ||
list.findTag(command[1].trim()); | ||
} else { | ||
throw new OmniException("Please check that your update command is in this format: findtag <tag>"); | ||
} | ||
} | ||
|
||
|
@@ -241,6 +235,8 @@ public static void findTypeCommand(String line, TravelActivityList list) throws | |
String[] command = line.split("findtype"); | ||
if (command.length < 1) { | ||
throw new OmniException("Please check that your find type command is in this format: findtype <type>"); | ||
} else if (command[1].trim().equalsIgnoreCase("general")){ | ||
list.findType("TravelActivity"); | ||
} else { | ||
list.findType(command[1].trim()); | ||
} | ||
|
@@ -249,13 +245,14 @@ public static void findTypeCommand(String line, TravelActivityList list) throws | |
/** | ||
* Handles the case where the find command is given as input | ||
* | ||
* @param command Command array of input string without spaces | ||
* @param line input string | ||
* @param list List of travel activities | ||
* @throws OmniException if command.length != 2 | ||
*/ | ||
public static void findCommand(String[] command, TravelActivityList list) throws OmniException { | ||
if (command.length == 2) { | ||
String keyword = command[1]; | ||
public static void findCommand(String line, TravelActivityList list) throws OmniException { | ||
String[] command = line.split("find"); | ||
if (command.length > 1 && !command[1].isBlank()) { | ||
String keyword = command[1].trim(); | ||
list.searchKeyword(keyword); | ||
} else { | ||
throw new OmniException("Please check that your find type command is in this format: find <description>"); | ||
|
@@ -272,11 +269,9 @@ public static void findCommand(String[] command, TravelActivityList list) throws | |
*/ | ||
public static void expenseCommand(String line, TravelActivityList list) throws OmniException { | ||
String[] command = line.split(" "); | ||
if (command.length == 3 && isNumeric(command[1])){ | ||
String index = command[1]; | ||
String[] expenseSplit = line.split(index); | ||
if (command.length == 3 && CheckParameters.isNumeric(command[1])){ | ||
int listNumber = Integer.parseInt(command[1]); | ||
String expense = expenseSplit[1].trim(); | ||
String expense = command[2]; | ||
list.expenseActivity(listNumber, expense); | ||
} else if (command.length == 2) { | ||
throw new OmniException("Please specify expense amount"); | ||
|
@@ -293,11 +288,11 @@ public static void expenseCommand(String line, TravelActivityList list) throws O | |
* @throws OmniException if command.length != 2 && command[1] is not numeric | ||
*/ | ||
public static void removeExpenseCommand(String[] command, TravelActivityList list) throws OmniException { | ||
if (command.length == 2 && isNumeric(command[1])) { | ||
if (command.length == 2 && CheckParameters.isNumeric(command[1])) { | ||
int listNumber = Integer.parseInt(command[1]); | ||
list.removeExpense(listNumber); | ||
} else { | ||
throw new OmniException("Please specify which task to remove expense"); | ||
throw new OmniException("Please follow the format: removeexpense INDEX"); | ||
} | ||
} | ||
|
||
|
@@ -318,9 +313,28 @@ public static void totalExpenseCommand(String line, TravelActivityList list) thr | |
throw new OmniException("Please check your command is in the format totalexpense [/type TYPE]"); | ||
} | ||
list.totalExpense("all"); | ||
} else if(command[1].trim().equals("general")){ | ||
list.totalExpense("TravelActivity"); | ||
} else { | ||
list.totalExpense(command[1].trim()); | ||
} | ||
} | ||
|
||
/** | ||
* Handles the case whereby the command is listtags | ||
* @param command The command given by the user | ||
* @param list The travel activity list | ||
* @throws OmniException Throws an exception when the command is in an invalid format | ||
*/ | ||
public static void listTagsCommand(String[] command, TravelActivityList list) throws OmniException{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM! |
||
Ui.printLine(); | ||
if (command.length == 1) { | ||
System.out.println("These are the tags in your list: "); | ||
list.listTags(); | ||
} else { | ||
throw new OmniException("Do you mean the command listtags?"); | ||
} | ||
Ui.printLine(); | ||
} | ||
|
||
} |
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job in identifying the keywords for duration