Skip to content

Commit

Permalink
Move messages to Message class
Browse files Browse the repository at this point in the history
  • Loading branch information
Jefferson111 committed Nov 10, 2019
1 parent dcd67ed commit 9aae71d
Show file tree
Hide file tree
Showing 18 changed files with 62 additions and 54 deletions.
36 changes: 31 additions & 5 deletions src/main/java/sgtravel/commons/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@ public class Messages {
* Include any specific error messages pertaining to the command.
* Format is COMMAND_DESCRIPTION
*/
public static final String VIEW_SCHEDULE_SUCCESS = "Calendar is launching...";
public static final String EDIT_SUCCESS = "The following is successfully changed to:\n";
public static final String LIST_FAVOURITE_SUCCESS = "Here is a list of favourite itinerary: \n";
public static final String DELETE_FAVOURITE_SUCCESS = "Successfully deleted this itinerary from favourite: \n";
public static final String ADD_FAVOURITE_SUCCESS = "Successfully added this itinerary to favourite: " + "\n";
public static final String ITINERARY_SUCCESS = "New Itinerary Created with name: ";
public static final String MARK_DONE_SUCCESS = "Nice! I've marked this event as done:\n ";
public static final String LIST_ITINERARY_SUCCESS = "Your Saved Itineraries are :" + "\n";
public static final String EXIT_SUCCESS = "Bye. Hope to see you again soon!\n";
public static final String EDITOR_SUCCESS = "Editor mode is turned on. Please press any key to begin. "
+ "Enter new information to edit. Enter x to save changes and exit Editor mode.";
public static final String ADD_EVENT_SUCCESS = "Got it. I've added this event:\n ";
public static final String ADD_ITINERARY_SUCCESS = "Successfully added the recommendation : \n";
public static final String DELETE_EVENT_SUCCESS = "Alright! I've removed this event:\n ";
public static final String DELETE_ITINERARY_SUCCESS = "Successfully deleted your itinerary with name ";
public static final String LOCATIONSEARCH_STARTER = "These are the coordinates of your search:\n";
public static final String LOCATIONSEARCH_API_EXCEPTION
= "Sorry, but the search has timed out due to connection issues.";
Expand All @@ -21,6 +36,22 @@ public class Messages {
public static final String ROUTE_DELETE_SUCCESS = "Got it. I've deleted this Route:\n";
public static final String STATIC_MAP_SUCCESS = "Showing map of : ";
public static final String STATIC_MAP_FAILURE = "I'm sorry, but nothing was found...\n";
public static final String EDIT_FAILURE = "Changes are not/cannot be saved.\n";
public static final String HELP_SUCCESS = "Here is the list of commands:\n"
+ " Event: event <venue> between <time> and <time>\n"
+ " Event: delete <index> \n"
+ " Event: done <index> \n"
+ " List events: list\n"
+ " Showing a Profile: profileShow\n"
+ " Showing bus stop: busStop <bus stop code>\n"
+ " Showing a bus route: busRoute <bus number>\n"
+ " Search locations: search <venue>\n"
+ " Map of locations: map <venue>\n"
+ " Find event in events: find <keyword>\n"
+ " For more commands, please visit our Github website.\n"
+ "\n"
;


/**
* Error messages.
Expand Down Expand Up @@ -78,10 +109,8 @@ public class Messages {
*/
public static final String PROMPT_ERROR = "Sorry, but something went wrong...";
public static final String PROMPT_NOT_INT = "Please use a number!";
public static final String PROMPT_NOT_DOUBLE = "Please use a number!";
public static final String PROMPT_NOT_DATE = "Please use a proper date!";
public static final String PROMPT_NOT_ROUTE_FIELD = "Please choose either name or description!";
public static final String PROMPT_NOT_ROUTENODE_FIELD = "Please use a proper field!";
public static final String PROMPT_SEARCH_STARTER = "Where would you like to find?";
public static final String PROMPT_SEARCH_SUCCESS = "These are the coordinates of your search:";
public static final String PROMPT_FIND_STARTER = "What task would you like to find?";
Expand Down Expand Up @@ -111,9 +140,6 @@ public class Messages {
public static final String PROMPT_ROUTENODE_DELETE_STARTER = "Which route does the node belong to?";
public static final String PROMPT_ROUTENODE_DELETE_NODEINDEX = "What is the index of the node?";
public static final String PROMPT_ROUTENODE_DELETE_SUCCESS = "Route node deleted successfully!";
public static final String PROMPT_ROUTENODE_SHOW_STARTER = "Which route does the node belong to?";
public static final String PROMPT_ROUTENODE_SHOW_NODEINDEX = "What is the index of the node?";
public static final String PROMPT_ROUTENODE_SHOW_SUCCESS = "Here is the route node";
public static final String PROMPT_ROUTE_LIST_STARTER = "Which route would you like to see?";
public static final String PROMPT_ROUTE_SELECTOR_DISPLAY = "Showing node:\n";
public static final String PROMPT_CANCEL = "Current conversation has ended.";
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/sgtravel/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sgtravel.logic.commands;

import sgtravel.commons.Messages;
import sgtravel.commons.exceptions.DuplicateEventException;
import sgtravel.commons.exceptions.FileNotSavedException;
import sgtravel.logic.commands.results.CommandResultText;
Expand All @@ -11,7 +12,6 @@
*/
public class AddCommand extends Command {
private final Event event;
private static final String MESSAGE_ADDITION = "Got it. I've added this event:\n ";

/**
* Creates a new AddCommand with the given event.
Expand All @@ -33,6 +33,6 @@ public AddCommand(Event event) {
public CommandResultText execute(Model model) throws DuplicateEventException, FileNotSavedException {
model.getEvents().add(event);
model.save();
return new CommandResultText(MESSAGE_ADDITION + event);
return new CommandResultText(Messages.ADD_EVENT_SUCCESS + event);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sgtravel.logic.commands;

import sgtravel.commons.Messages;
import sgtravel.commons.exceptions.AddListFailException;
import sgtravel.commons.exceptions.FileNotSavedException;
import sgtravel.commons.exceptions.NoRecentItineraryException;
Expand Down Expand Up @@ -36,7 +37,6 @@ public CommandResultText execute(Model model) throws FileNotSavedException, NoRe
model.setRecentItinerary(null);
model.save();
String printString = itinerary.printItinerary();
return new CommandResultText("Successfully added the recommendation : " + "\n"
+ printString);
return new CommandResultText(Messages.ADD_ITINERARY_SUCCESS + printString);
}
}
4 changes: 2 additions & 2 deletions src/main/java/sgtravel/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sgtravel.logic.commands;

import sgtravel.commons.Messages;
import sgtravel.commons.exceptions.FileNotSavedException;
import sgtravel.commons.exceptions.OutOfBoundsException;
import sgtravel.logic.commands.results.CommandResultText;
Expand All @@ -11,7 +12,6 @@
*/
public class DeleteCommand extends Command {
private int index;
private static final String MESSAGE_DELETE = "Alright! I've removed this task:\n ";

/**
* Creates a new DeleteCommand with the given index.
Expand All @@ -34,7 +34,7 @@ public CommandResultText execute(Model model) throws OutOfBoundsException, FileN
try {
Event event = model.getEvents().remove(index);
model.save();
return new CommandResultText(MESSAGE_DELETE + event);
return new CommandResultText(Messages.DELETE_EVENT_SUCCESS + event);
} catch (IndexOutOfBoundsException e) {
throw new OutOfBoundsException();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sgtravel.logic.commands;

import sgtravel.commons.Messages;
import sgtravel.commons.exceptions.FileNotSavedException;
import sgtravel.commons.exceptions.NoSuchItineraryException;
import sgtravel.logic.commands.results.CommandResultText;
Expand Down Expand Up @@ -31,6 +32,6 @@ public DoneItineraryCommand(String name) {
public CommandResultText execute(Model model) throws NoSuchItineraryException, FileNotSavedException {
model.doneItinerary(name);
model.save();
return new CommandResultText("Successfully deleted your itinerary with name " + name);
return new CommandResultText(Messages.DELETE_ITINERARY_SUCCESS + name);
}
}
4 changes: 2 additions & 2 deletions src/main/java/sgtravel/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sgtravel.logic.commands;

import sgtravel.commons.Messages;
import sgtravel.commons.exceptions.FileNotSavedException;
import sgtravel.logic.commands.results.CommandResultText;
import sgtravel.model.Model;
Expand All @@ -13,7 +14,6 @@
*/
public class EditCommand extends Command {
private static final Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
private static final String MESSAGE_EDIT_FAILURE = "Changes are not/cannot be saved.\n";
private boolean canSave;
private EventList events;

Expand Down Expand Up @@ -41,6 +41,6 @@ public CommandResultText execute(Model model) throws FileNotSavedException {
logger.log(Level.FINE, "Event list is saved.");
return new CommandResultText(model.getEvents());
}
return new CommandResultText(MESSAGE_EDIT_FAILURE);
return new CommandResultText(Messages.EDIT_FAILURE);
}
}
6 changes: 2 additions & 4 deletions src/main/java/sgtravel/logic/commands/EditorCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sgtravel.logic.commands;

import sgtravel.commons.Messages;
import sgtravel.commons.exceptions.EmptyVenueException;
import sgtravel.logic.edits.EditorManager;
import sgtravel.logic.commands.results.CommandResultText;
Expand All @@ -12,9 +13,6 @@
* Turns on the editing mode on SGTravel.
*/
public class EditorCommand extends Command {
private static final String MESSAGE_EDITOR = "Editor mode is turned on. Please press any key to begin. "
+ "Enter new information to edit. Enter x to save changes and exit Editor mode.";

/**
* Executes this command and returns a text result.
*
Expand All @@ -25,6 +23,6 @@ public class EditorCommand extends Command {
public CommandResultText execute(Model model) throws EmptyVenueException {
EventList events = SerializationUtils.clone(model.getEvents());
EditorManager.activate(events, model.getEventVenues());
return new CommandResultText(MESSAGE_EDITOR);
return new CommandResultText(Messages.EDITOR_SUCCESS);
}
}
5 changes: 2 additions & 3 deletions src/main/java/sgtravel/logic/commands/ExitCommand.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package sgtravel.logic.commands;

import sgtravel.commons.Messages;
import sgtravel.logic.commands.results.CommandResultExit;
import sgtravel.model.Model;

/**
* Exits SGTravel.
*/
public class ExitCommand extends Command {
private static final String MESSAGE_BYE = "Bye. Hope to see you again soon!\n";

/**
* Executes this command and returns a text result.
*
* @param model The model object containing event list.
*/
@Override
public CommandResultExit execute(Model model) {
return new CommandResultExit(MESSAGE_BYE);
return new CommandResultExit(Messages.EXIT_SUCCESS);
}
}
17 changes: 2 additions & 15 deletions src/main/java/sgtravel/logic/commands/HelpCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sgtravel.logic.commands;

import sgtravel.commons.Messages;
import sgtravel.commons.exceptions.HelpFailException;
import sgtravel.logic.commands.results.CommandResultText;
import sgtravel.model.Model;
Expand All @@ -14,20 +15,6 @@
*/
public class HelpCommand extends Command {
private static final String HELP_URL = "https://github.com/AY1920S1-CS2113T-W13-3/main/blob/master/docs/UserGuide.adoc";
private static final String MESSAGE_HELP = "Here is the list of commands:\n"
+ " Event: event <venue> between <time> and <time>\n"
+ " Event: delete <index> \n"
+ " Event: done <index> \n"
+ " List events: list\n"
+ " Showing a Profile: profileShow\n"
+ " Showing bus stop: busStop <bus stop code>\n"
+ " Showing a bus route: busRoute <bus number>\n"
+ " Search locations: search <venue>\n"
+ " Map of locations: map <venue>\n"
+ " Find event in events: find <keyword>\n"
+ " For more commands, please visit our Github website.\n"
+ "\n"
;

/**
* Executes this command and returns a text result.
Expand All @@ -42,6 +29,6 @@ public CommandResultText execute(Model model) throws HelpFailException {
} catch (URISyntaxException | IOException e) {
throw new HelpFailException();
}
return new CommandResultText(MESSAGE_HELP);
return new CommandResultText(Messages.HELP_SUCCESS);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sgtravel.logic.commands;

import sgtravel.commons.Messages;
import sgtravel.logic.commands.results.CommandResultText;
import sgtravel.model.Model;
import sgtravel.model.planning.Itinerary;
Expand All @@ -10,7 +11,6 @@
* Lists the stored itineraries names an serial number.
*/
public class ListItineraryCommand extends Command {

/**
* Executes this command on the given task list and user interface.
*
Expand All @@ -24,6 +24,6 @@ public CommandResultText execute(Model model) {
for (String name : itineraryHashMap.keySet()) {
stringBuilder.append(i++).append(". ").append(name).append("\n");
}
return new CommandResultText("Your Saved Itineraries are :" + "\n" + stringBuilder.toString());
return new CommandResultText(Messages.LIST_ITINERARY_SUCCESS + stringBuilder.toString());
}
}
4 changes: 2 additions & 2 deletions src/main/java/sgtravel/logic/commands/MarkDoneCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sgtravel.logic.commands;

import sgtravel.commons.Messages;
import sgtravel.commons.exceptions.FileNotSavedException;
import sgtravel.commons.exceptions.OutOfBoundsException;
import sgtravel.logic.commands.results.CommandResultText;
Expand All @@ -11,7 +12,6 @@
*/
public class MarkDoneCommand extends Command {
private int index;
private static final String MESSAGE_MARK_DONE = "Nice! I've marked this task as done:\n ";

/**
* Creates a new MarkDoneCommand with the given index.
Expand All @@ -35,7 +35,7 @@ public CommandResultText execute(Model model) throws OutOfBoundsException, FileN
Event event = model.getEvents().get(index);
event.setDone(true);
model.save();
return new CommandResultText(MESSAGE_MARK_DONE + event);
return new CommandResultText(Messages.MARK_DONE_SUCCESS + event);
} catch (IndexOutOfBoundsException e) {
throw new OutOfBoundsException();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sgtravel.logic.commands;

import sgtravel.commons.Messages;
import sgtravel.commons.exceptions.ApiException;
import sgtravel.commons.exceptions.FileNotSavedException;
import sgtravel.commons.exceptions.ItineraryIncorrectDaysException;
Expand Down Expand Up @@ -43,6 +44,6 @@ public CommandResultText execute(Model model) throws ApiException, ParseExceptio
model.setNewItinerary(itinerary);
logger.log(Level.FINE, "New itinerary is saved");
model.save();
return new CommandResultText("New Itinerary Created with name: " + itinerary.getName());
return new CommandResultText(Messages.ITINERARY_SUCCESS + itinerary.getName());
}
}
2 changes: 0 additions & 2 deletions src/main/java/sgtravel/logic/commands/ProfileAddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* Sets up the profile.
*/
public class ProfileAddCommand extends Command {

private String name;
private LocalDateTime birthday;

Expand All @@ -22,7 +21,6 @@ public class ProfileAddCommand extends Command {
* @param birthday The birthday of the person.
*/
public ProfileAddCommand(String name, LocalDateTime birthday) {

this.name = name;
this.birthday = birthday;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sgtravel.logic.commands;

import sgtravel.commons.Messages;
import sgtravel.commons.exceptions.FileNotSavedException;
import sgtravel.commons.exceptions.NoSuchItineraryException;
import sgtravel.logic.commands.results.CommandResultText;
Expand Down Expand Up @@ -28,11 +29,9 @@ public ProfileAddFavCommand(String word) {
*/
@Override
public CommandResultText execute(Model model) throws FileNotSavedException, NoSuchItineraryException {
// Add to the list of Itineraries
Itinerary itinerary = model.getItinerary(name);
model.addToFavourite(name, itinerary);
model.save();
return new CommandResultText("Successfully added this itinerary to favourite: " + "\n" + name);

return new CommandResultText(Messages.ADD_FAVOURITE_SUCCESS + name);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sgtravel.logic.commands;

import sgtravel.commons.Messages;
import sgtravel.commons.exceptions.FileNotSavedException;
import sgtravel.commons.exceptions.NoSuchItineraryException;
import sgtravel.logic.commands.results.CommandResultText;
Expand All @@ -9,7 +10,6 @@
* Deletes itinerary from favourite.
*/
public class ProfileDeleteFavCommand extends Command {

private final String name;

/**
Expand All @@ -30,6 +30,6 @@ public ProfileDeleteFavCommand(String word) {
public CommandResultText execute(Model model) throws FileNotSavedException, NoSuchItineraryException {
model.deleteFavourite(name);
model.save();
return new CommandResultText("Successfully deleted this itinerary from favourite: " + "\n" + name);
return new CommandResultText(Messages.DELETE_FAVOURITE_SUCCESS + name);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sgtravel.logic.commands;

import sgtravel.commons.Messages;
import sgtravel.commons.exceptions.DukeException;
import sgtravel.logic.commands.results.CommandResult;
import sgtravel.logic.commands.results.CommandResultText;
Expand Down Expand Up @@ -27,6 +28,6 @@ public CommandResult execute(Model model) throws DukeException {
for (String name : favHashMap.keySet()) {
stringBuilder.append(i++).append(". ").append(name).append("\n");
}
return new CommandResultText("Here is a list of favourite itinerary: " + "\n" + stringBuilder.toString());
return new CommandResultText(Messages.LIST_FAVOURITE_SUCCESS + stringBuilder.toString());
}
}
Loading

0 comments on commit 9aae71d

Please sign in to comment.