forked from nus-cs2103-AY2425S1/ip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from muller317/branch-A-CodeQuality
Refactor command classes to reduce code duplication
- Loading branch information
Showing
13 changed files
with
116 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package muller.command; | ||
|
||
import muller.storage.Storage; | ||
import muller.task.TaskList; | ||
import muller.ui.Ui; | ||
|
||
/** | ||
* Utility class for common validation methods. | ||
*/ | ||
public class CommandUtil { | ||
/** | ||
* Checks if the input task, ui, storage are not null. | ||
* | ||
* @param tasks | ||
* @param ui | ||
* @param storage | ||
*/ | ||
public static void assertionTest(TaskList tasks, Ui ui, Storage storage) { | ||
assert tasks != null : "TaskList should not be null"; | ||
assert ui != null : "Ui should not be null"; | ||
assert storage != null : "Storage should not be null"; | ||
} | ||
|
||
/** | ||
* Checks if the input task index is valid. | ||
* | ||
* @param index | ||
* @param taskListSize | ||
* @return | ||
*/ | ||
public static boolean isValidTaskIndex(int index, int taskListSize) { | ||
return index >= 0 && index < taskListSize; | ||
} | ||
|
||
/** | ||
* Check if the input is complete for different tasks. | ||
* | ||
* @param commandInputs | ||
* @return | ||
*/ | ||
public static boolean isInputComplete(String[] commandInputs) { | ||
return commandInputs.length < 2; | ||
} | ||
|
||
/** | ||
* Checks if the input string is a numeric value. | ||
* | ||
* @param str The input string. | ||
* @return True if the string is numeric, false otherwise. | ||
*/ | ||
public static boolean isNumeric(String str) { | ||
try { | ||
Integer.parseInt(str); | ||
return true; | ||
} catch (NumberFormatException e) { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Check the command to delete tasks is complete | ||
* | ||
* @param commandInputs | ||
* @return | ||
*/ | ||
public static boolean isDeleteCommandValid(String[] commandInputs) { | ||
return commandInputs.length < 2 || !isNumeric(commandInputs[1]); | ||
} | ||
|
||
/** | ||
* Check if the input is complete for different tasks. | ||
* | ||
* @param commandInputs | ||
* @return | ||
*/ | ||
public static boolean isFindCommandValid(String[] commandInputs) { | ||
return commandInputs.length < 2 || commandInputs[1].trim().isEmpty(); | ||
} | ||
|
||
/** | ||
* Check the command to delete tasks is complete | ||
* | ||
* @param commandInputs | ||
* @return | ||
*/ | ||
public static boolean isMarkCommandValid(String[] commandInputs) { | ||
return commandInputs.length < 2 || !isNumeric(commandInputs[1]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters