Skip to content

Commit

Permalink
Removal of dead code and static keywords for Jarvis, Parser and Ui cl…
Browse files Browse the repository at this point in the history
…asses.

Dead code and unused variables are redundant and confuses other developers.
Wrong use of static keyword confuses others developers as class level methods and attributes are not actually meant to be as such.

Delete dead code and remove unnecessary static keywords.

So as to declutter code and fix wrong class level methods.
  • Loading branch information
amosting committed Sep 13, 2023
1 parent fb007b2 commit 95f9ed0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/main/java/Jarvis/Jarvis.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public Jarvis(String fileName) {
// getting the file path to the save file
String home = System.getProperty("user.home");
Path pathToSaveFile = Paths.get(home, "Desktop", "CS2103T", "IP", "data", fileName);
boolean isFileExists = Files.exists(pathToSaveFile);

assert !pathToSaveFile.toString().isEmpty() : "pathToSaveFile in Jarvis() does not contain a file path";

Expand All @@ -38,9 +37,9 @@ public Jarvis(String fileName) {

public String getResponse(String input) {
try {
return Parser.parseCommand(storage, tasks, input);
return parser.parseCommand(storage, tasks, input);
} catch (IncorrectJarvisCommandException e) {
return Ui.getListOfCommands(Parser.validCommands, e);
return Ui.getListOfCommands(parser.validCommands, e);
} catch (InvalidTaskNumberException e) {
return Ui.respond(e.getMessage() + "\n" +
" There are currently " + tasks.countTask() + " tasks in the list.");
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/Jarvis/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* </p>
*/
public class Parser {
protected static ArrayList<String> validCommands; // list of valid commands
protected ArrayList<String> validCommands; // list of valid commands

/**
* Constructs a new Parser object.
Expand Down Expand Up @@ -44,7 +44,7 @@ private void addValidCommands() {
* @return the valid command that the user inputted, an empty string otherwise.
*/
// checks if command is valid and throws Jarvis.IncorrectJarvisCommandException
private static String isValidCommand(String inputCommand) {
private String isValidCommand(String inputCommand) {

assert !inputCommand.isEmpty() : "inputCommand parameter in isValidCommand() is an empty string";

Expand Down Expand Up @@ -81,7 +81,7 @@ private static String isValidCommand(String inputCommand) {
* @param validInputCommand the valid command which the user inputted
*/
// identifies which command has wrong formatting and prints feedback to user
public static String isWrongFormat(String inputCommand, String validInputCommand) {
public String isWrongFormat(String inputCommand, String validInputCommand) {

assert !inputCommand.isEmpty() : "inputCommand parameter in isWrongFormat() is an empty string";
assert !validInputCommand.isEmpty() : "validInputCommand parameter in isWrongFormat() is an empty string";
Expand Down Expand Up @@ -141,7 +141,7 @@ public static String isWrongFormat(String inputCommand, String validInputCommand
* @throws InvalidTaskNumberException If the task number is out of the range of the number of tasks.
* @throws WrongJarvisCommandFormatException If the command is correct but its formatted incorrectly.
*/
public static String parseCommand(Storage storage, TaskList tasks, String userInput) throws
public String parseCommand(Storage storage, TaskList tasks, String userInput) throws
IncorrectJarvisCommandException, InvalidTaskNumberException, WrongJarvisCommandFormatException {

Pattern todoPattern = Pattern.compile("(todo) (.+)");
Expand Down
1 change: 0 additions & 1 deletion src/main/java/Jarvis/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

public class Ui {
private static final String name = "Jarvis";
private static final String line = "____________________________________________________________";
private static final String greeting = "Good day Sir! I'm ";
private static final String question = "How can I help you today Sir?";
private static final String signOff = "Good bye Sir!";
Expand Down

0 comments on commit 95f9ed0

Please sign in to comment.