Skip to content

Commit

Permalink
Merge branch 'work'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jefferson111 committed Nov 10, 2019
2 parents b305baf + 9aae71d commit 839df32
Show file tree
Hide file tree
Showing 44 changed files with 272 additions and 195 deletions.
2 changes: 1 addition & 1 deletion src/main/java/sgtravel/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void start(Stage stage) {
mainWindow.show();
mainWindow.initialise(this);
} catch (Exception e) {
e.printStackTrace();
logger.log(Level.WARNING, "Something went wrong with the application.");
}
}

Expand Down
42 changes: 35 additions & 7 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 @@ -19,8 +34,24 @@ public class Messages {
public static final String ROUTE_NODE_EDIT_SUCCESS = "Edited the Route!\n";
public static final String ROUTE_NODE_NEIGHBOURS_SUCCESS = "Here are some Nodes that are close to this:\n";
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_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 All @@ -37,7 +68,7 @@ public class Messages {
public static final String ERROR_FILE_NOT_SAVED = "File not saved! :-(";
public static final String ERROR_RESOURCE_NOT_FOUND = "Resource not found! :-( Missing: ";
public static final String ERROR_OBJECT_NOT_CREATED = "Item could not be created! :-(";
public static final String ERROR_TASK_DUPLICATED = "Task already exists! :-(";
public static final String ERROR_EVENT_DUPLICATED = "Event already exists! :-(";
public static final String ERROR_ROUTE_DUPLICATE = "Route already exists! :-(";
public static final String ERROR_ROUTE_NOT_FOUND = "Route not found! :-(";
public static final String ERROR_ROUTE_NODE_DUPLICATE = "Node already exists! :-(";
Expand Down Expand Up @@ -69,17 +100,17 @@ public class Messages {
public static final String ERROR_RECOMMENDATION_FAIL = "I'm sorry, the days of the trip is too long.\n"
+ "I can only give a good recommendation within 8 days";
public static final String ERROR_HELP_FAIL = "I'm sorry, unable to open user guide.";
public static final String ERROR_QUICK_EDIT_COMMAND_FAIL = "I'm sorry, edit could not "
+ "be made because your format was wrong. :(";

/**
* Messages sent via Prompt by Duke.
* Format is PROMPT_TYPE_DESCRIPTION
*/
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 @@ -109,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
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
/**
* Exception thrown when a duplicate task is detected.
*/
public class DuplicateTaskException extends DukeException {
public class DuplicateEventException extends DukeException {

/**
* Constructs the Exception.
*/
public DuplicateTaskException() {
super(Messages.ERROR_TASK_DUPLICATED);
public DuplicateEventException() {
super(Messages.ERROR_EVENT_DUPLICATED);
}
}
28 changes: 21 additions & 7 deletions src/main/java/sgtravel/logic/LogicManager.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sgtravel.logic;

import sgtravel.commons.Messages;
import sgtravel.commons.exceptions.ApiException;
import sgtravel.commons.exceptions.ChronologyAfterPresentException;
import sgtravel.commons.exceptions.ChronologyBeforePresentException;
Expand All @@ -16,7 +17,10 @@
import sgtravel.model.ModelManager;

import javafx.scene.input.KeyCode;
import sgtravel.model.lists.RouteList;
import sgtravel.model.planning.Itinerary;

import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -46,17 +50,19 @@ public LogicManager() {
public CommandResult execute(String userInput) throws DukeException {
Command c;
if (EditorManager.isActive()) {
logger.log(Level.INFO, "editing...");
logger.log(Level.INFO, "Editing...");
c = EditorManager.edit(userInput);
} else {
try {
c = Parser.parseComplexCommand(userInput);
conversationManager.clearContext();
logger.log(Level.INFO, "Executing command...");
} catch (ChronologyAfterPresentException | ChronologyBeforePresentException
| ChronologyInconsistentException | ApiException e) {
throw e;
} catch (ParseException e) {
c = getCommandFromConversationManager(userInput);
logger.log(Level.INFO, "Conversing...");
}
}
return (CommandResult) c.execute(model);
Expand Down Expand Up @@ -84,11 +90,19 @@ private Command getCommandFromConversationManager(String userInput) throws DukeE
return conversationManager.getCommand();
}

public String getName() {
return model.getName();
}

public Model getModel() {
return model;
/**
* Gets the welcome message.
* @return The welcome message.
*/
public String getWelcomeMessage() {
HashMap<String, Itinerary> itineraries = model.getItineraryTable();
RouteList routes = model.getRoutes();
String message = Messages.STARTUP_WELCOME_MESSAGE + model.getName() + "\n\n";
message += Messages.STARTUP_WELCOME_MESSAGE_ITINERARY_START + itineraries.size()
+ Messages.STARTUP_WELCOME_MESSAGE_ITINERARY_END;
message += Messages.STARTUP_WELCOME_MESSAGE_ROUTE_START + routes.size()
+ Messages.STARTUP_WELCOME_MESSAGE_ROUTE_END;
message += Messages.STARTUP_WELCOME_MESSAGE_HELP;
return message;
}
}
63 changes: 44 additions & 19 deletions src/main/java/sgtravel/logic/PathFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ public ArrayList<Venue> execute(Venue start, Venue end, Constraint constraint) t
}
}

/**
* Finds the train route.
* @param start The starting point.
* @param end The ending point.
* @return An array of Venues representing the route.
*/
private ArrayList<Venue> findTrainRoute(Venue start, Venue end) {
this.found = false;
TrainStation startTrainStation = ApiConstraintParser.getNearestTrainStation(start, this.map.getTrainMap());
Expand Down Expand Up @@ -109,10 +115,22 @@ private ArrayList<Venue> findTrainRoute(Venue start, Venue end) {

}

/**
* Checks to see if 2 Venues are the same.
* @param start The first Venue.
* @param end The second Venue.
* @return True if the Venues are the same.
*/
private boolean isSameLocation(Venue start, Venue end) {
return start.equals(end);
}

/**
* Checks to see if 2 train station are on the same line.
* @param cur The current train station.
* @param endTrainStation The other train station.
* @return True if the 2 trains are on the same line.
*/
private boolean onSameLine(TrainStation cur, TrainStation endTrainStation) {
for (String code : cur.getTrainCodes()) {
for (String code2 : endTrainStation.getTrainCodes()) {
Expand All @@ -124,6 +142,12 @@ private boolean onSameLine(TrainStation cur, TrainStation endTrainStation) {
return false;
}

/**
* Finds the bus route between 2 venues.
* @param start The starting point.
* @param end The ending point.
* @return An array of Venues representing the route.
*/
private ArrayList<Venue> findBusRoute(Venue start, Venue end) {
this.found = false;
BusStop startBusStop = ApiConstraintParser.getNearestBusStop(start, this.map.getBusStopMap());
Expand Down Expand Up @@ -165,38 +189,41 @@ private ArrayList<Venue> findBusRoute(Venue start, Venue end) {
}
}

/**
* Performs depth first search.
* @param cur The starting node.
* @param endBusStop The goal node.
* @param depthLimit The depth limit.
*/
private void depthFirstSearch(BusStop cur, BusStop endBusStop, int depthLimit) {
if (depthLimit == 0 || this.visited.contains(cur)) {
if (depthLimit == 0 || visited.contains(cur)) {
return;
}
visited.add(cur);

this.visited.add(cur);

for (String bus : cur.getBuses()) { //loop through all bus in bus stop
for (String bus : cur.getBuses()) {
Direction direction;
if (this.map.getBusMap().get(bus).getDirection(Direction.FORWARD).contains(cur.getBusCode())) {
if (map.getBusMap().get(bus).getDirection(Direction.FORWARD).contains(cur.getBusCode())) {
direction = Direction.FORWARD;
} else {
direction = Direction.BACKWARD;
}

for (String busCode : this.map.getBusMap().get(bus).getDirection(direction)) { // depth search the bus route

if (this.found) {
for (String busCode : map.getBusMap().get(bus).getDirection(direction)) {
if (found) {
break;
}

if (busCode.equals(cur.getBusCode())) {
continue;
}

path.put(busCode, cur.getBusCode());
if (haveSameBus(this.map.getBusStopMap().get(busCode), endBusStop)) {
if (haveSameBus(map.getBusStopMap().get(busCode), endBusStop)) {
path.put(endBusStop.getBusCode(), busCode);
this.found = true;
found = true;
return;
} else {
depthFirstSearch(this.map.getBusStopMap().get(busCode), endBusStop, depthLimit - 1);
depthFirstSearch(map.getBusStopMap().get(busCode), endBusStop, depthLimit - 1);
}
}
}
Expand Down Expand Up @@ -237,14 +264,14 @@ public static RouteNode generateCustomRouteNode(Venue venue) {
* @return result The ArrayList of Venues.
* @throws QueryFailedException If a TrainStation cannot be queried.
*/
public static ArrayList<Venue> generateInbetweenNodes(Venue startVenue, Venue endVenue, Model model)
public static ArrayList<Venue> generateInBetweenNodes(Venue startVenue, Venue endVenue, Model model)
throws QueryFailedException {
ArrayList<Venue> result = new ArrayList<>();

if (startVenue instanceof BusStop && endVenue instanceof BusStop) {
result = generateInbetweenBusRoutes(startVenue, endVenue, model);
result = generateInBetweenBusRoutes(startVenue, endVenue, model);
} else if (startVenue instanceof TrainStation && endVenue instanceof TrainStation) {
result = generateInbetweenTrainRoutes((TrainStation) startVenue, (TrainStation) endVenue, model);
result = generateInBetweenTrainRoutes((TrainStation) startVenue, (TrainStation) endVenue, model);
}

return result;
Expand All @@ -258,7 +285,7 @@ public static ArrayList<Venue> generateInbetweenNodes(Venue startVenue, Venue en
* @param model The model object containing information about the user.
* @return result The ArrayList of BusStops.
*/
private static ArrayList<Venue> generateInbetweenBusRoutes(Venue startVenue, Venue endVenue, Model model)
private static ArrayList<Venue> generateInBetweenBusRoutes(Venue startVenue, Venue endVenue, Model model)
throws QueryFailedException {
boolean isGenerated = false;
ArrayList<Venue> result = new ArrayList<>();
Expand All @@ -270,7 +297,6 @@ private static ArrayList<Venue> generateInbetweenBusRoutes(Venue startVenue, Ven
if (!isGenerated) {
BusService bus = busMap.get(busNumber);
ArrayList<String> busCodes = bus.getDirection(Direction.FORWARD);

result =
searchForwardDirectionBus((BusStop) startVenue, (BusStop) endVenue, busNumber, busCodes, model);
if (result != null) {
Expand All @@ -283,7 +309,6 @@ private static ArrayList<Venue> generateInbetweenBusRoutes(Venue startVenue, Ven
isGenerated = true;
}
}

} else {
break;
}
Expand Down Expand Up @@ -395,7 +420,7 @@ private static ArrayList<Venue> searchReverseDirectionBus(BusStop startVenue, Bu
* @param model The model object containing information about the user.
* @return result The ArrayList of TrainStations.
*/
private static ArrayList<Venue> generateInbetweenTrainRoutes(TrainStation startVenue, TrainStation endVenue,
private static ArrayList<Venue> generateInBetweenTrainRoutes(TrainStation startVenue, TrainStation endVenue,
Model model) throws QueryFailedException {
boolean isGenerated = false;
ArrayList<Venue> result = new ArrayList<>();
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/sgtravel/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sgtravel.logic.commands;

import sgtravel.commons.exceptions.DuplicateTaskException;
import sgtravel.commons.Messages;
import sgtravel.commons.exceptions.DuplicateEventException;
import sgtravel.commons.exceptions.FileNotSavedException;
import sgtravel.logic.commands.results.CommandResultText;
import sgtravel.model.Event;
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 @@ -27,12 +27,12 @@ public AddCommand(Event event) {
*
* @param model The model object containing event list.
* @throws FileNotSavedException If the data could not be saved.
* @throws DuplicateTaskException If there is a duplicated event.
* @throws DuplicateEventException If there is a duplicated event.
*/
@Override
public CommandResultText execute(Model model) throws DuplicateTaskException, FileNotSavedException {
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);
}
}
Loading

0 comments on commit 839df32

Please sign in to comment.