Skip to content

Commit

Permalink
Merge pull request #89 from Woolicious98/branch-JavaDoc
Browse files Browse the repository at this point in the history
Branch java doc
  • Loading branch information
kelvneo authored Oct 12, 2021
2 parents db8c150 + 60710c8 commit 369f62a
Show file tree
Hide file tree
Showing 18 changed files with 249 additions and 132 deletions.
16 changes: 8 additions & 8 deletions src/main/java/terminus/Terminus.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,28 @@ public class Terminus {
"Invalid file data detected.",
"TermiNUS will still run, but the file will be overwritten when the next command is ran.",
"To save your current file, close your terminal (do not run exit).",
"Otherwise, you can continue using the program :)"
"Otherwise, you can continue using the program :)"
};
private Ui ui;
private CommandParser parser;
private String workspace;

private ModuleStorage moduleStorage;
private NusModule nusModule;

private static final String INVALID_ARGUMENT_FORMAT_MESSAGE = "Format: %s";
private static final Path DATA_DIRECTORY = Path.of(System.getProperty("user.dir"), "data");
private static final String MAIN_JSON = "main.json";

/**
* Main entry-point for the terminus.Terminus application.
* Enters the main entry-point for the terminus.Terminus application.
*/
public static void main(String[] args) {
new Terminus().run();
}

/**
* Start the program.
* Starts the program.
*/
public void run() {
start();
Expand All @@ -58,7 +58,7 @@ private void start() {
this.parser = MainCommandParser.getInstance();
this.workspace = "";
this.moduleStorage = new ModuleStorage(DATA_DIRECTORY.resolve(MAIN_JSON));

TerminusLogger.info("Loading file...");
this.nusModule = moduleStorage.loadFile();
} catch (IOException e) {
Expand Down Expand Up @@ -91,7 +91,7 @@ private void runCommandsUntilExit() {
try {
currentCommand = parser.parseCommand(input);
CommandResult result = currentCommand.execute(ui, nusModule);

boolean isExitCommand = result.isOk() && result.isExit();
boolean isWorkspaceCommand = result.isOk() && result.getAdditionalData() != null;
if (isExitCommand) {
Expand All @@ -112,11 +112,11 @@ private void runCommandsUntilExit() {
ui.printSection(e.getMessage());
} catch (InvalidArgumentException e) {
TerminusLogger.warning("Invalid input provided: " + input, e.fillInStackTrace());

// Check if the exception specified a correct command format for the user to follow.
if (e.getFormat() != null) {
// Print the format of the command along with the error message to the user.
ui.printSection(e.getMessage(), String.format(INVALID_ARGUMENT_FORMAT_MESSAGE, e.getFormat()));
ui.printSection(e.getMessage(), String.format(INVALID_ARGUMENT_FORMAT_MESSAGE, e.getFormat()));
} else {
ui.printSection(e.getMessage());
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/terminus/command/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public abstract class Command {

protected String arguments;

public Command() {

}
Expand All @@ -31,7 +31,7 @@ public Command() {
* Parses remaining arguments for the command.
*
* @param arguments The string arguments to be parsed in to the respective fields.
* @throws InvalidArgumentException Exception for when arguments parsing fails
* @throws InvalidArgumentException when arguments parsing fails.
*/
public void parseArguments(String arguments)
throws InvalidArgumentException {
Expand All @@ -42,11 +42,11 @@ public void parseArguments(String arguments)
* Executes the command.
* Prints the required result to the Ui.
*
* @param ui The Ui object to send messages to the users.
* @param module The NusModule contain the list of all notes and schedules.
* @param ui The Ui object to send messages to the users.
* @param module The NusModule contain the ContentManager of all notes and schedules.
* @return The CommandResult object indicating the success of failure including additional options.
* @throws InvalidCommandException Exception for when the command could not be found.
* @throws InvalidArgumentException Exception for when arguments parsing fails
* @throws InvalidCommandException when the command could not be found.
* @throws InvalidArgumentException when arguments parsing fails.
*/
public abstract CommandResult execute(Ui ui, NusModule module)
throws InvalidCommandException, InvalidArgumentException;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/terminus/command/CommandResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public CommandResult(boolean isOk, boolean isExit, CommandParser additionalData,
* Returns the CommandParser that is required to switch workspaces.
* If additionalData will be null.
*
* @return The CommandParser object for the workspace or else null
* @return The CommandParser object for the workspace or else null.
*/
public CommandParser getAdditionalData() {
return additionalData;
Expand All @@ -45,7 +45,7 @@ public CommandParser getAdditionalData() {
/**
* Returns the result of the command execution.
*
* @return True if successful or else false
* @return True if successful or else false.
*/
public boolean isOk() {
return isOk;
Expand All @@ -54,7 +54,7 @@ public boolean isOk() {
/**
* Returns the result to exit or not.
*
* @return True if 'exit' command is sent
* @return True if 'exit' command is sent.
*/
public boolean isExit() {
return isExit;
Expand All @@ -63,7 +63,7 @@ public boolean isExit() {
/**
* Returns the error message as a String.
*
* @return The String object containing the error
* @return The String object containing the error.
*/
public String getErrorMessage() {
return errorMessage;
Expand Down
29 changes: 28 additions & 1 deletion src/main/java/terminus/command/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,21 @@
import terminus.module.NusModule;
import terminus.ui.Ui;

/**
* DeleteCommand generic class which will manage the deletion of Content specified by user command.
*
* @param <T> Content object type.
*/
public class DeleteCommand<T extends Content> extends Command {

private final Class<T> type;
private int itemNumber;

/**
* Creates a DeleteCommand object with referenced to the provided class type.
*
* @param type Content object type.
*/
public DeleteCommand(Class<T> type) {
this.type = type;
}
Expand All @@ -29,6 +39,13 @@ public String getHelpMessage() {
return Messages.MESSAGE_COMMAND_DELETE;
}

/**
* Parses the arguments to the DeleteCommand object.
* The arguments are attributes to identify a Content object in an ArrayList.
*
* @param arguments The string arguments to be parsed in to the respective fields.
* @throws InvalidArgumentException when argument provided is empty, non-numeric or less than 1.
*/
@Override
public void parseArguments(String arguments) throws InvalidArgumentException {
if (arguments == null || arguments.isBlank()) {
Expand All @@ -47,14 +64,24 @@ public void parseArguments(String arguments) throws InvalidArgumentException {
}
}

/**
* Executes the delete command.
* Prints the relevant response to the Ui and the specified Content object will be removed from the arraylist.
*
* @param ui The Ui object to send messages to the users.
* @param module The NusModule contain the ContentManager of all notes and schedules.
* @return CommandResult to indicate the success and additional information about the execution.
* @throws InvalidArgumentException when argument provided is index out of bounds of the ArrayList.
*/
@Override
public CommandResult execute(Ui ui, NusModule module) throws InvalidArgumentException {
ContentManager<T> contentManager = module.getContentManager(type);
assert contentManager != null;
TerminusLogger.info("Executing Delete Command");
String deletedContentName = contentManager.deleteContent(itemNumber);
assert deletedContentName != null && !deletedContentName.isBlank();

TerminusLogger.info(
String.format("%s(%s) has been deleted", CommonUtils.getClassName(type), deletedContentName));
ui.printSection(String.format(Messages.MESSAGE_RESPONSE_DELETE,
CommonUtils.getClassName(type).toLowerCase(), deletedContentName));
return new CommandResult(true);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/terminus/command/ScheduleCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public ScheduleCommand() {
/**
* Returns the keyword for schedule-related commands.
*
* @return The string containing the keyword for schedule-related commands
* @return The string containing the keyword for schedule-related commands.
*/
@Override
public String getFormat() {
Expand All @@ -26,7 +26,7 @@ public String getFormat() {
/**
* Returns the description for the command.
*
* @return The string containing the description for this command
* @return The string containing the description for this command.
*/
@Override
public String getHelpMessage() {
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/terminus/command/ViewCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,27 @@
import terminus.module.NusModule;
import terminus.ui.Ui;

/**
* ViewCommand generic class which will manage the viewing of Content information specified by user command.
*
* @param <T> Content object type.
*/
public class ViewCommand<T extends Content> extends Command {

private final Class<T> type;

private int itemNumber;

/**
* Determines whether to print the list of all Content objects or just the specified one.
*/
private boolean displayAll;

/**
* Creates a ViewCommand object with referenced to the provided class type.
*
* @param type Content object type.
*/
public ViewCommand(Class<T> type) {
this.type = type;
this.displayAll = false;
Expand All @@ -31,6 +45,14 @@ public String getHelpMessage() {
return Messages.MESSAGE_COMMAND_VIEW;
}

/**
* Parses the arguments to the ViewCommand object.
* The arguments are attributes to identify a Content object in an ArrayList. The arguments can be empty which
* refers to viewing a list all Content object in an ArrayList instead.
*
* @param arguments The string arguments to be parsed in to the respective fields.
* @throws InvalidArgumentException when a non-empty argument provided is non-numeric or less than 1.
*/
@Override
public void parseArguments(String arguments) throws InvalidArgumentException {
if (arguments == null || arguments.isBlank()) {
Expand All @@ -51,6 +73,15 @@ public void parseArguments(String arguments) throws InvalidArgumentException {
}
}

/**
* Executes the view command.
* Prints the relevant response to the Ui.
*
* @param ui The Ui object to send messages to the users.
* @param module The NusModule contain the ContentManager of all notes and schedules.
* @return CommandResult to indicate the success and additional information about the execution.
* @throws InvalidArgumentException when argument provided is index out of bounds of the ArrayList.
*/
@Override
public CommandResult execute(Ui ui, NusModule module) throws InvalidArgumentException {
StringBuilder result = new StringBuilder();
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/terminus/command/WorkspaceCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ public WorkspaceCommand(CommandParser commandMap) {
}

/**
* Returns the Command Result after execution. If no other arguments, returns the workspace.
* Returns the Command Result after execution.
* If no other arguments, returns the workspace.
*
* @param ui The Ui object to send messages to the users.
* @param ui The Ui object to send messages to the users.
* @param module The NusModule contain the list of all notes and schedules.
* @return The CommandResult containing success or failure of command and CommandParser Object
* @throws InvalidCommandException Exception for when the command could not be found.
* @return The CommandResult containing success or failure of command and CommandParser Object.
* @throws InvalidCommandException when the command could not be found.
*/
@Override
public CommandResult execute(Ui ui, NusModule module) throws InvalidCommandException, InvalidArgumentException {
Expand Down
35 changes: 27 additions & 8 deletions src/main/java/terminus/command/note/AddNoteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,19 @@
import terminus.content.ContentManager;
import terminus.content.Note;
import terminus.exception.InvalidArgumentException;
import terminus.exception.InvalidCommandException;
import terminus.module.NusModule;
import terminus.ui.Ui;

/**
* AddNoteCommand class which will manage the adding of new Notes from user command.
*/
public class AddNoteCommand extends Command {

private String name;
private String data;

private static final int ADD_NOTE_ARGUMENTS = 2;

public AddNoteCommand() {

}

@Override
public String getFormat() {
return CommonFormat.COMMAND_ADD_NOTE_FORMAT;
Expand All @@ -35,6 +33,13 @@ public String getHelpMessage() {
return Messages.MESSAGE_COMMAND_ADD;
}

/**
* Parses the arguments to the AddNoteCommand object.
* The arguments are attributes for a new Note object.
*
* @param arguments The string arguments to be parsed in to the respective fields.
* @throws InvalidArgumentException when arguments are empty or missing.
*/
@Override
public void parseArguments(String arguments) throws InvalidArgumentException {
TerminusLogger.info("Parsing add note arguments");
Expand All @@ -52,9 +57,17 @@ public void parseArguments(String arguments) throws InvalidArgumentException {
TerminusLogger.info(String.format("Parsed argument (name = %s, data = %s) to Add Note Command", name, data));
}

@Override
public CommandResult execute(Ui ui, NusModule module) throws InvalidCommandException {
/**
* Executes the add Note command.
* Prints the relevant response to the Ui and a new Note will be added into the arraylist of Notes.
*
* @param ui The Ui object to send messages to the users.
* @param module The NusModule contain the ContentManager of all notes and schedules.
* @return CommandResult to indicate the success and additional information about the execution.
*/
public CommandResult execute(Ui ui, NusModule module) {
TerminusLogger.info("Executing Add Note Command");

ContentManager contentManager = module.getContentManager(Note.class);
assert contentManager != null;

Expand All @@ -64,13 +77,19 @@ public CommandResult execute(Ui ui, NusModule module) throws InvalidCommandExcep
return new CommandResult(true, false);
}

/**
* Checks if arguments are non-empty and valid.
*
* @param argArray The command arguments in an array list.
* @return True if the appropriate number of arguments are present, false otherwise.
*/
private boolean isValidNoteArguments(ArrayList<String> argArray) {
boolean isValid = true;
if (argArray.size() != ADD_NOTE_ARGUMENTS) {
TerminusLogger.warning(String.format("Failed to find %d arguments: %d arguments found",
ADD_NOTE_ARGUMENTS, argArray.size()));
isValid = false;
} else if (CommonUtils.isArrayEmpty(argArray)) {
} else if (CommonUtils.hasEmptyString(argArray)) {
TerminusLogger.warning("Failed to parse arguments: some arguments found is empty");
isValid = false;
}
Expand Down
Loading

0 comments on commit 369f62a

Please sign in to comment.