Skip to content
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

finished list /date /sort #218

Merged
merged 3 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion omni.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ 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 / /
>>>>>>> 81de0612da2ab6cfdd12a7ecda4f2359e0f8b70b
38 changes: 38 additions & 0 deletions src/main/java/seedu/omnitravel/errorhandlers/CheckParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
import java.time.DateTimeException;
import java.util.NoSuchElementException;

/**
* The CheckParameters class provides methods to check the user input for various commands.
* An OmniException will be thrown if the input violates the structure of the command.
* Includes methods that will check parameters for the add command, update command, list command, currency command
* as well as helper functions to check the validity of certain strings.
*
*/

public class CheckParameters {
//@@author EugeneChanJiajun
/**
Expand Down Expand Up @@ -36,6 +44,7 @@ public static void addExceptions(String[] input, String commandType, String line
* Checks for all possible input errors that users may make when updating and throws the corresponding exceptions
*
* @param command Command array that users placed into the chatbot
* @param line The line that the user inputs
* @throws OmniException when any of the corresponding input format is wrong
*/
public static void updateExceptions(String[] command, String line) throws OmniException {
Expand All @@ -55,10 +64,39 @@ public static void updateExceptions(String[] command, String line) throws OmniEx
+ " or update INDEX /date YYYY-MM-DD /duration DURATION /tag TAG");
}
}

//@@author annnniexu
/**
* Checks for all possible input errors that users may make when using the list command and
* throws the corresponding exceptions
*
* @param command Command array that users placed into the chatbot
* @param input Input arrary that is split at /date and /sort
* @param line The line that the user inputs
* @throws OmniException when any of the corresponding input format is wrong
*/
public static void listExceptions(String[] command, String[] input, String line) throws OmniException {
//command is split at spaces, input is split at /date and /sort
// /date included, but no date provided
boolean case1 = command.length > 1 && command[1].equals("/date") && (command.length < 3 || input.length != 2);
// something other than /date or /sort is entered after list
boolean case2 = command.length > 1 && !(command[1].equals("/date") || command[1].equals("/sort"));
// only /sort tag but command length > 2
boolean case3 = command.length > 2 && command[1].equals("/sort");
// command length greater than 4
boolean case4 = command.length > 4;
if (case1 || case2 || case3 || case4) {
throw new OmniException("Please check that your list command is in this format:" +
"list [/date YYYY-MM-DD] [/sort]");
}
}


//@@author daryltay415
/**
* Checks if a string contains all the words
* @param input The input String
* @throws OmniException if duration is invalid
*/
public static void containsWords(String input) throws OmniException{
String[] inputSplit = input.split(" ");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package seedu.omnitravel.errorhandlers;

/**
* The OmniException class represents an exception specific to the OmniTravel application.
* It extends the Java Exception class.
*/

public class OmniException extends Exception {
public OmniException(String errorMessage){
super(errorMessage);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/omnitravel/omnitravel/OmniTravel.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static void main(String[] args) throws IOException {
logger.log(Level.INFO, command[0]);
switch (command[0].toLowerCase()) {
case "list":
Parser.getList(command, list);
Parser.getList(line, list);
break;
case "listtags":
Parser.listTagsCommand(command, list);
Expand Down
40 changes: 33 additions & 7 deletions src/main/java/seedu/omnitravel/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,53 @@

import java.io.IOException;
import java.time.LocalDate;
import java.time.format.DateTimeParseException;
import java.util.Arrays;
import java.util.logging.Logger;

/**
* The Parser class contains methods that handles user command inputs and calls the respective methods
* in TravelActivityList.
*/

public class Parser {

private static Logger logger = Logger.getLogger("ParserLogger");

//@@author ChinYanXu
//@@author annnniexu
/**
* Obtains the list of travel activities
*
* @param line Line that the user inputs into the chatbot
* @param list List of travel activities.
*/
public static void getList(String[] command, TravelActivityList list) throws OmniException {
public static void getList(String line, TravelActivityList list) throws OmniException {
Ui.printLine();
if (command.length == 1) {
System.out.println("Here are the travel activities in your list:");
list.listTravelActivities();
} else {
throw new OmniException("Do you mean the command list?");
String[] command = line.split(" ");
String delimiter = "/date | /sort ";
String[] input = line.split(delimiter);
CheckParameters.listExceptions(command, input, line);
boolean sort = false;
boolean isDate = false;
LocalDate date = LocalDate.now();
String dateString = "all dates";
if (command.length == 2 || command.length == 4) {
sort = true;
}
if (command.length == 3 || command.length == 4) {
isDate = true;
try {
date = LocalDate.parse(command[2].trim());
} catch (DateTimeParseException e) {
throw new OmniException("Please provide the date in the format YYYY-MM-DD");
}
if(date.isBefore(LocalDate.now())){
throw new OmniException("Please input a future date.");
}
dateString = date.toString();
}
System.out.println("Here are the travel activities for " + dateString);
list.listTravelActivities(sort, isDate, date);
Ui.printLine();
}
//@@author EugeneChanJiajun
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/seedu/omnitravel/storage/FileSave.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* The FileSave class is responsible for saving a TravelActivity list to disk and loading
* a TravelActivity from disk.
*
*/
public class FileSave {
//@@author EugeneChanJiajun
private static Logger logger = Logger.getLogger("LoadFileLogger");
Expand All @@ -22,6 +27,11 @@ public FileSave(String path) {
this.filePath = path;
}

/**
* Reads data from file and loads it into a travel activity list
* @param list The travel activity list to load data in to
* @throws FileNotFoundException If the file does not exist
*/
public void loadFileContents(TravelActivityList list) throws FileNotFoundException {
logger.log(Level.INFO, "loadFileContents");
java.io.File f = new java.io.File(filePath);
Expand All @@ -42,6 +52,18 @@ public void loadFileContents(TravelActivityList list) throws FileNotFoundExcepti
}
}

/**

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job adding javadocs

* Initializes a travel activity object based on the given parameters
*
* @param type The type of travel activity (food, landmark, accommodation, general)
* @param description The description of the travel activity
* @param date The date of the travel activity
* @param duration The duration of the travel activity
* @param tag The tag of the travel activity
* @param expense The expense of the travel activity
* @return The TravelActivity object
* @throws FileNotFoundException If the type is not valid
*/
public TravelActivity initialiseActivity (String type, String description,
LocalDate date, String duration, String tag, String expense) throws FileNotFoundException {
TravelActivity activity;
Expand All @@ -64,6 +86,11 @@ public TravelActivity initialiseActivity (String type, String description,
return activity;
}

/**
* Saves the travel activity list to the file specified by the file path
* @param list The travel activity list to save to the file
* @throws IOException If an I/o error occurs while writing to file
*/
public void saveActivityList(TravelActivityList list) throws IOException {
logger.log(Level.INFO, "saveActivityList");
FileWriter fw = new FileWriter(filePath);
Expand All @@ -87,6 +114,11 @@ public void saveActivityList(TravelActivityList list) throws IOException {
fw.close();
}

/**
* Reads the file and loads information into the provided travel activity list.
*
* @param list The travel activity list to load the file into
*/
public void readFile(TravelActivityList list) {
logger.log(Level.INFO, "readFile");
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
* The TravelActivity class represents a single travel activity and has attributes
* description, date, duration, tag, expense, and whether or not the activity is completed.
*
*/

public class TravelActivity {
/** Travel activity description */
private String travelActivity;
Expand Down Expand Up @@ -53,6 +59,10 @@ public String getPlan(){
return travelActivity;
}

/**
* Gets the status of the travel activity
* @return boolean representing if activity is done or not
*/
public boolean getActivityStatus() {
return activityIsDone;
}
Expand All @@ -65,42 +75,72 @@ public String getTag() {
return tag;
}

/**
* Sets the tag of the travel activity
* @param tag The tag to be set
*/
public void setTag(String tag) {
this.tag = tag;
}

/**
* Removes the tag of the travel activity.
*/
public void removeTag() {
this.tag = "";
}

/**
* Sets the date of the travel activity
* @param date the date to be set
*/
public void setDate(LocalDate date){
this.date = date;
}

/**
* Gets the date of the travel activity.
* @return the date of the travel activity
*/
public LocalDate getDate(){
return date;
}

/**
* Sets the duration of the travel activity.
* @param duration the duration to be set
*/
public void setDuration(String duration){
this.duration = duration;
}

/**
* Gets the duration of the travel activity
* @return the duration of the travel activity
*/
public String getDuration(){
return duration;
}

/**
* Gets the expense of the travel activity
* @return The tag of the travel activity
* @return The expense of the travel activity
*/
public String getExpense() {
return expense;
}

/**
* Sets the expense of the travel activity
* @param expense The expense of the travel activity
*/
public void setExpense(String expense) {
this.expense = expense;
}

/**
* Removes the expense of the travel activity.
*/
public void removeExpense() {
this.expense = "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.logging.Level;
import java.util.logging.Logger;


/**
* The TravelActivityList class represents the list of travel activities that the user inputs.
* Methods include adding, removing, listing, expensing, updating, tagging, and filtering travel activities.
*
*/
public class TravelActivityList {
private static Logger logger = Logger.getLogger("TravelActivityListLogger");
/** Array of travel activity */
Expand Down Expand Up @@ -42,19 +47,41 @@ public void addTravelActivity(TravelActivity travelActivity){
}

/**
* Prints out all the travel activities
* Prints out all the travel activities.
* If sort is enabled, the list will be printed out from oldest to newest date.
* If filterDate is enabled and a date is provided, only activities from that date will be printed
*
* @param sort boolean indicating if list should be sorted
* @param filterDate boolean indicating if list should be filtered by date
* @param date the date to be filtered by
*/
public void listTravelActivities(){
public void listTravelActivities(boolean sort, boolean filterDate, LocalDate date){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good enhancement to the current list feature

ArrayList<TravelActivity> activities = new ArrayList<>();
if (filterDate) {
for (TravelActivity a: travelActivities) {
if (a.getDate().equals(date)) {
activities.add(a);
}
}
} else {
activities = travelActivities;
}
if (sort) {
Collections.sort(activities, Comparator.comparing(TravelActivity::getDate));
}
int activityCount = 0;
for (TravelActivity activity: travelActivities) {
for (TravelActivity activity: activities) {
if (activity == null) {
break;
}
activityCount++;
Ui.printActivity(activity, activityCount);
}
if (activityCount == 0) {
System.out.println("There are no activities to list");
}
int finalActivityCount = noOfActivities;
assert finalActivityCount == activityCount : "Index out of bounds while listing activities";
assert finalActivityCount >= activityCount : "Index out of bounds while listing activities";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion will cause it to fail as it will check that finalActivityCount >= activityCount. Since that is false it will cause the assertion to happen

}

/**
Expand Down
Loading
Loading