diff --git a/src/main/java/ducats/commands/Command.java b/src/main/java/ducats/commands/Command.java index 8f581b8c7b..0660bdc329 100644 --- a/src/main/java/ducats/commands/Command.java +++ b/src/main/java/ducats/commands/Command.java @@ -39,6 +39,19 @@ public abstract class Command { */ public abstract String execute(T object, Ui ui, Storage storage) throws DucatsException; + /** + * Used for undo command and redo command only. + * This method passes in a UndoRedoStack object which stores all the version of the SongList object + * + * @param songs the SongList object that is passed in as a version + * @param ui the Ui object responsible for the reading of user input + * and the display of the responses + * @param storage the Storage object used to read and manipulate the .txt file + * @param undoRedoStack the UndoRedoStack object that stores different versions of + * the SongList object + * @return the formatted String to be displayed + * @throws DucatsException in the case of either parsing or IO errors + */ public String execute(SongList songs, Ui ui, Storage storage, UndoRedoStack undoRedoStack) throws DucatsException { return null; } diff --git a/src/main/java/ducats/commands/CommandSyntaxMessage.java b/src/main/java/ducats/commands/CommandSyntaxMessage.java index c05368eb07..1b754c32f1 100644 --- a/src/main/java/ducats/commands/CommandSyntaxMessage.java +++ b/src/main/java/ducats/commands/CommandSyntaxMessage.java @@ -6,59 +6,90 @@ import java.util.Map; //@@author SalonetheGreat - /** * CommandSyntaxMessage is a class that cannot be instantiated. * To add a new command format, just create a String which indicates the command format, * and add the command name and format into nameToSyntax HashMap. */ public abstract class CommandSyntaxMessage { - private static String listSyntax = "list\n"; - private static String newSyntax = "new s/SONG_NAME [key:s/KEY](C) [time:n/TIME_SIG](4/4) [tempo:n/TEMPO](120)\n"; - private static String openSyntax = "open s/SONG_NAME\n"; - private static String viewSyntax = "view [n/BAR_NO](last bar - 1)\n"; - private static String addSyntax = "add s/NOTE\n"; - private static String addbarSyntax = "addbar s/NOTES [bar:n/BAR_NO_TO_ADD_AFTER](last bar)\n"; - private static String asciiSyntax = "ascii song song_name\n"; - // TODO: add overlay syntax - private static String overlaySyntax = "To be implemented in version 2.0\n"; - private static String copySyntax = "copy start_num end_num\nFormat: copy start_num end_num insert_num\n"; - private static String groupSyntax = "group start_num end_num verse_name\n"; - private static String list_groupSyntax = "list_group\nFormat: list_group -starting_substring\n"; - private static String playSyntax = "play [n/STARTING_BAR_NO n/ENDING_BAR_NO]\n" + private static final String helpSyntax = "help\n"; + private static final String listSyntax = "list\n"; + private static final String newSyntax = + "new s/SONG_NAME [key:s/KEY](C) [time:n/TIME_SIG](4/4) [tempo:n/TEMPO](120)\n"; + private static final String deleteSyntax = "delete song:n/SONG_NUM OR delete song:s/SONG_NAME\n"; + private static final String openSyntax = "open s/SONG_NAME\n"; + private static final String viewSyntax = "view [n/BAR_NO](last bar - 1)\n"; + private static final String addSyntax = "add s/NOTE\n"; + private static final String addbarSyntax = "addbar s/NOTES [bar:n/BAR_NO_TO_ADD_AFTER](last bar)\n"; + private static final String deletebarSyntax = "deletebar bar:n/BAR_NUM\n"; + private static final String insertbarSyntax = "insertbar bar:n/BAR_NUM s/NOTES\n"; + private static final String editbarSyntax = "editbar bar:n/BAR_NUM s/NOTES\n"; + private static final String swapbarSyntax = "swapbar bar:n/BAR_NUM bar:n/BAR_NUM\n"; + // TODO: group copy + private static final String groupSyntax = "group n/START_NUM n/END_NUM s/GROUP_NAME\n"; + private static final String copySyntax = "copy s/GROUP_NAME\n" + + "Format: copy n/START_NUM n/END_NUM\n" + + "Format: copy s/GROUP_NAME n/INSERT_INDEX\n" + + "Format: copy n/START_NUM n/END_NUM n/INSERT_INDEX\n"; + // TODO: overlay overlay_group_group overlay_bar_group overlay_bar_song + private static final String overlaySyntax = "overlay n/BAR_NUM1 n/BAR_NUM2\n" + + "Format: overlay n/BAR_NUM1 n/BAR_NUM2 repeat\n"; + private static final String overlay_group_groupSyntax = "overlay_group_group n/SONG1 n/GROUP1 n/SONG2 n/GROUP2\n" + + "Format: overlay_group_group n/SONG1 n/GROUP1 n/SONG2 n/GROUP2 repeat\n"; + private static final String overlay_bar_groupSyntax = "overlay_bar_group n/BAR n/GROUP\n" + + "Format: overlay_bar_group n/BAR n/GROUP repeat\n"; + private static final String overlay_bar_songSyntax = "overlay_bar_song n/SONG1 n/BAR1 n/SONG2 n/BAR2\n" + + "Format: overlay_bar_song n/SONG1 n/BAR1 n/SONG2 n/BAR2 repeat\n"; + private static final String list_groupSyntax = "list_group\n" + + "Format: list_group s/STARTING_SUBSTRING\n"; + private static final String asciiSyntax = "ascii song s/SONG_NAME\n"; + private static final String undoSyntax = "undo\n"; + private static final String redoSyntax = "redo\n"; + private static final String metronomeSyntax = "metronome n/DURATION_IN_NO_OF_BARS n/TEMP0 s/TIME_SIG\n"; + private static final String exitSyntax = "bye\n"; + private static final String playSyntax = "play [n/STARTING_BAR_NO n/ENDING_BAR_NO]\n" + "Format: play s/SONG_NAME (when no song has been opened)\n"; - private static String metronomeSyntax = "metronome n/DURATION_IN_NO_OF_BARS n/TEMP0 s/TIME_SIG\n"; - // TODO: add close, clear, delete, exit syntax - private static String closeSyntax = "To be implemented in version 2.0\n"; - private static String clearSyntax = "To be implemented in version 2.0\n"; - private static String deleteSyntax = "To be implemented in version 2.0\n"; - private static String exitSyntax = "To be implemented in version 2.0\n"; - private static String startHelpMessage = "Here are the commands in Ducats.\n"; - private static String endInstructionMessage = - "Alternatively, you can use help [command] to see format for specific command.\n"; + // TODO: close clear delete exit + private static final String closeSyntax = "To be implemented in version 2.0\n"; + private static final String clearSyntax = "To be implemented in version 2.0\n"; + private static final String startHelpMessage = "Here are the commands in Ducats.\n"; + private static final String endInstructionMessage = + "Alternatively, you can use help [command] to see format for a specific command.\n"; + //@@author SalonetheGreat private static Map nameToSyntax = new HashMap() { { + put("help", helpSyntax); put("list", listSyntax); put("new", newSyntax); + put("delete", deleteSyntax); put("open", openSyntax); put("view", viewSyntax); put("add", addSyntax); put("addbar", addbarSyntax); - put("overlay", overlaySyntax); - put("copy", copySyntax); + put("deletebar", deletebarSyntax); + put("insertbar", insertbarSyntax); + put("editbar", editbarSyntax); + put("swapbar", swapbarSyntax); put("group", groupSyntax); - put("ascii", asciiSyntax); + put("copy", copySyntax); + put("overlay", overlaySyntax); + put("overlay_group_group", overlay_group_groupSyntax); + put("overlay_bar_group", overlay_bar_groupSyntax); + put("overlay_bar_song", overlay_bar_songSyntax); put("list_group", list_groupSyntax); - put("play", playSyntax); + put("ascii", asciiSyntax); + put("undo", undoSyntax); + put("redo", redoSyntax); put("metronome", metronomeSyntax); + put("play", playSyntax); put("close", closeSyntax); put("clear", clearSyntax); - put("delete", deleteSyntax); put("exit", exitSyntax); } }; + //@@author SalonetheGreat /** * The function is to get ALL the commands including their name and format in a single String. * @return a string with all the formats @@ -74,6 +105,7 @@ public static String getMessage() { return output.toString(); } + //@@author SalonetheGreat /** * The getMessage is to get the command and format of a specific command. * @param helpMessage the command to show @@ -82,9 +114,7 @@ public static String getMessage() { */ public static String getMessage(String helpMessage) throws DucatsException { if (nameToSyntax.containsKey(helpMessage)) { - StringBuilder output = new StringBuilder(); - output.append(helpMessage + "\nFormat: " + nameToSyntax.get(helpMessage)); - return output.toString(); + return helpMessage + "\nFormat: " + nameToSyntax.get(helpMessage); } else { throw new DucatsException("", "Other"); } diff --git a/src/main/java/ducats/commands/RedoCommand.java b/src/main/java/ducats/commands/RedoCommand.java index 441de5e55d..414c6483db 100644 --- a/src/main/java/ducats/commands/RedoCommand.java +++ b/src/main/java/ducats/commands/RedoCommand.java @@ -8,11 +8,35 @@ public class RedoCommand extends Command { + /** + * A null method that will never be used, the reason for this method is for inheritance. + * + * @param object the ducats.TaskList or ducats.components.SongList object that contains the task list in use + * @param ui the Ui object responsible for the reading of user input and the display of + * the responses + * @param storage the Storage object used to read and manipulate the .txt file + * @return null + */ @Override public String execute(SongList object, Ui ui, Storage storage) throws DucatsException { return null; } + /** + * The execute() method checks the redoability of a undoRedoStack, and behave accordingly. + * If redo is available, move the undoRedoStack to its next version, and tell the user + * how many times are left to redo. + * If redo is not available, warn the user that the undoRedoStack cannot be redone anymore. + * + * @param songs the SongList object that is passed in as a version + * @param ui the Ui object responsible for the reading of user input + * and the display of the responses + * @param storage the Storage object used to read and manipulate the .txt file + * @param undoRedoStack the UndoRedoStack object that stores different versions of + * the SongList object + * @return the formatted String to be displayed + * @throws DucatsException in case of IO error happens + */ @Override public String execute(SongList songs, Ui ui, Storage storage, UndoRedoStack undoRedoStack) throws DucatsException { if (!undoRedoStack.canRedo()) { diff --git a/src/main/java/ducats/commands/UndoCommand.java b/src/main/java/ducats/commands/UndoCommand.java index 448f58d718..9da61b6b7a 100644 --- a/src/main/java/ducats/commands/UndoCommand.java +++ b/src/main/java/ducats/commands/UndoCommand.java @@ -8,11 +8,35 @@ public class UndoCommand extends Command { + /** + * A null method that will never be used, the reason for this method is for inheritance. + * + * @param object the ducats.TaskList or ducats.components.SongList object that contains the task list in use + * @param ui the Ui object responsible for the reading of user input and the display of + * the responses + * @param storage the Storage object used to read and manipulate the .txt file + * @return null + */ @Override - public String execute(SongList object, Ui ui, Storage storage) throws DucatsException { + public String execute(SongList object, Ui ui, Storage storage) { return null; } + /** + * The execute() method checks the undoability of a undoRedoStack, and behave accordingly. + * If undo is available, move the undoRedoStack to its previous version, and tell the user + * how many times are left to undo. + * If undo is not available, warn the user that the undoRedoStack cannot be undone anymore. + * + * @param songs the SongList object that is passed in as a version + * @param ui the Ui object responsible for the reading of user input + * and the display of the responses + * @param storage the Storage object used to read and manipulate the .txt file + * @param undoRedoStack the UndoRedoStack object that stores different versions of + * the SongList object + * @return the formatted String to be displayed + * @throws DucatsException in case of IO error happens + */ @Override public String execute(SongList songs, Ui ui, Storage storage, UndoRedoStack undoRedoStack) throws DucatsException { if (!undoRedoStack.canUndo()) {