Skip to content

Commit f7c2ea7

Browse files
Improve Javadoc
1 parent c73bf41 commit f7c2ea7

13 files changed

+181
-38
lines changed

data/flashcards/flashcard.txt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,2 @@
1-
3 | cs2113 | software enginnering | 3
2-
5 | Hello | Duke | 4
3-
7 | Hello | Duke | 4
4-
9 | id | checker | 6
5-
10 | id increases | correctly | 5
6-
11 | f | dfdf | 5
7-
12 | dfdf | | 5
8-
13 | 1 | j | 5
1+
14 | dfdf | a | 5
2+
15 | now | you can see me | 5

src/main/java/seedu/duke/Duke.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ public static void main(String[] args) {
1515
new Duke().run();
1616
}
1717

18+
/**
19+
* Starts a REPL session where commands are inputted and then processed.
20+
*/
1821
private void run() {
1922
FlashcardComponent fc = new FlashcardComponent();
2023
CalendarManager cm = new CalendarManager(new ArrayList<>());
@@ -29,9 +32,13 @@ private void run() {
2932

3033
if (fc.isResponsible(input)) {
3134
fc.processInput(input);
35+
continue;
3236
} else if (cm.isResponsible(input)) {
3337
cm.processInput(input);
34-
} else if (input.toLowerCase().strip().equals("exit")) {
38+
continue;
39+
}
40+
41+
if (input.toLowerCase().strip().equals("exit")) {
3542
System.out.println(" You are exiting TaskLinker! Bye!");
3643
break;
3744
} else if (input.toLowerCase().strip().equals("help")) {
@@ -55,6 +62,8 @@ private void printHelp() {
5562
"list flashcards",
5663
"create flashcard",
5764
"review flashcards",
65+
"delete flashcard",
66+
"delete all flashcards",
5867
"help",
5968
"add event",
6069
"add goal event",

src/main/java/seedu/duke/flashcard/Flashcard.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public Flashcard(String frontText, String backText) {
2828

2929
globalMaxId += 1;
3030
id = globalMaxId;
31+
32+
assert globalMaxId >= id : "No id must be bigger than globalMaxId";
3133
}
3234

3335
/**

src/main/java/seedu/duke/flashcard/FlashcardCommandParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class FlashcardCommandParser {
2222
* @return The FlashcardCommand corresponding to input
2323
*/
2424
public FlashcardCommand parseInput(String input) {
25-
assert input != null : "input is null";
25+
assert input != null : "input must not be null";
2626

2727
input = input.toLowerCase().strip();
2828

src/main/java/seedu/duke/flashcard/FlashcardComponent.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ public FlashcardUi getUi(){
6363
* @return Whether FlashcardComponent is responsible for handling the input.
6464
*/
6565
public boolean isResponsible(String input) {
66+
assert input != null : "input must not be null";
67+
6668
FlashcardCommand command = parser.parseInput(input);
6769

6870
if (command instanceof UnknownCommand) {
@@ -78,6 +80,8 @@ public boolean isResponsible(String input) {
7880
* @param input The text inputted by the user.
7981
*/
8082
public void processInput(String input) {
83+
assert input != null : "input must not be null";
84+
8185
FlashcardCommand command = parser.parseInput(input);
8286
assert !(command instanceof UnknownCommand) : "Command cannot be " +
8387
"unknown";

src/main/java/seedu/duke/flashcard/FlashcardList.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public void add(Flashcard flashcard) {
4747
*/
4848
public void deleteAllFlashcards() {
4949
flashcards.clear();
50+
51+
assert flashcards.size() == 0 : "flashcardList should be empty now";
5052
}
5153

5254
/**

src/main/java/seedu/duke/flashcard/FlashcardUi.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public class FlashcardUi {
2121
*/
2222
public FlashcardUi(FlashcardList flashcardList) {
2323
scanner = new Scanner(System.in);
24+
25+
assert flashcardList != null : "flashcardList cannot be null";
2426
this.flashcardList = flashcardList;
2527
}
2628

src/main/java/seedu/duke/flashcard/command/CreateFlashcardCommand.java

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,12 @@ public class CreateFlashcardCommand extends FlashcardCommand {
2121
* @param flashcardList Which flashcards to perform actions on.
2222
*/
2323
public void execute(Scanner scanner, FlashcardList flashcardList) {
24-
System.out.print(" Enter the front page text: ");
25-
String frontPageText = scanner.nextLine();
24+
assert scanner != null : "Must be a valid Scanner instance";
25+
assert flashcardList != null : "Must be a valid FlashcardList " +
26+
"instance";
2627

27-
while (frontPageText.strip().equals("")) {
28-
System.out.println(" Invalid input! The front text must " +
29-
"contain at least one letter or digit!");
30-
31-
System.out.print(" Enter the front page text: ");
32-
frontPageText = scanner.nextLine();
33-
}
34-
35-
System.out.print(" Enter the back page text: ");
36-
String backPageText = scanner.nextLine();
37-
38-
while (backPageText.strip().equals("")) {
39-
System.out.println(" Invalid input! The back text must " +
40-
"contain at least one letter or digit!");
41-
42-
System.out.print(" Enter the back page text: ");
43-
backPageText = scanner.nextLine();
44-
}
28+
String frontPageText = getInputUntilNonEmptyString(scanner, "front");
29+
String backPageText = getInputUntilNonEmptyString(scanner, "back");
4530

4631
Flashcard flashcard = new Flashcard(frontPageText, backPageText);
4732

@@ -51,4 +36,31 @@ public void execute(Scanner scanner, FlashcardList flashcardList) {
5136
System.out.println(" Success! Flashcard has been added to your " +
5237
"collection.");
5338
}
39+
40+
/**
41+
* Gets a user input for a flashcard, making sure that it is non-empty.
42+
*
43+
* @param scanner To get user input.
44+
* @param flashcardSide Which side of the flashcard (front or back) is
45+
* targeted.
46+
* @return The user input for the specified flashcardSide.
47+
*/
48+
private String getInputUntilNonEmptyString(Scanner scanner,
49+
String flashcardSide) {
50+
System.out.print(" Enter the " + flashcardSide + " page text: ");
51+
String text = scanner.nextLine();
52+
53+
while (text.strip().equals("")) {
54+
System.out.println(" Invalid input! The " + flashcardSide +
55+
" text must contain at least one letter or digit!");
56+
57+
System.out.print(" Enter the " + flashcardSide
58+
+ " page text: ");
59+
text = scanner.nextLine();
60+
}
61+
62+
assert text != null : "Must be a non-null string";
63+
assert (!text.strip().equals("")) : "Must be a non-empty string";
64+
return text;
65+
}
5466
}

src/main/java/seedu/duke/flashcard/command/DeleteAllFlashcardsCommand.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ public void execute(Scanner scanner, FlashcardList flashcardList) {
1919

2020
System.out.println(" All your flashcards have been successfully " +
2121
"deleted .");
22+
23+
assert flashcardList.isEmpty() : "flashcardList must be empty";
2224
}
2325
}

src/main/java/seedu/duke/flashcard/command/DeleteFlashcardCommand.java

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,31 @@
66

77
import java.util.Scanner;
88

9+
/**
10+
* This command allows deleting a specific flashcard (by its id).
11+
*/
912
public class DeleteFlashcardCommand extends DualFlashcardCommand {
10-
1113
public DeleteFlashcardCommand(String input) {
1214
this.input = input;
1315
beginnerCommandLength = 2;
1416
expertCommandLength = 3;
1517
syntaxString = "delete flashcard FLASHCARD_ID";
1618
}
1719

20+
/**
21+
* Starts an interactive process for deleting a flashcard by its id.
22+
* The user is prompted to enter the id; and then it is deleted.
23+
*
24+
* @param scanner Scanner for getting user input.
25+
* @param flashcardList FlashcardList from which to delete.
26+
*/
1827
protected void executeBeginnerMode(Scanner scanner,
1928
FlashcardList flashcardList) {
20-
System.out.println(" Enter id of the flashcard you want to delete:" +
21-
" ");
29+
assert flashcardList != null : "Must be a valid flashcardList " +
30+
"instance";
31+
32+
System.out.println(" Enter id of the flashcard you want to " +
33+
"delete: ");
2234

2335
String input = scanner.nextLine();
2436
int flashcardId;
@@ -33,9 +45,19 @@ protected void executeBeginnerMode(Scanner scanner,
3345
deleteFlashcardById(flashcardId, flashcardList);
3446
}
3547

48+
/**
49+
* Allows deleting a flashcard whose id is already known.
50+
*
51+
* @param scanner Scanner for getting user input.
52+
* @param flashcardList FlashcardList from which to delete.
53+
*/
3654
protected void executeExpertMode(Scanner scanner,
3755
FlashcardList flashcardList) {
56+
assert flashcardList != null : "Must be a valid flashcardList " +
57+
"instance";
58+
3859
String[] commandParts = input.split(" ");
60+
assert commandParts.length != 0 : "must contain command parts";
3961

4062
try {
4163
int flashcardId = Integer.parseInt(commandParts[2]);
@@ -45,15 +67,22 @@ protected void executeExpertMode(Scanner scanner,
4567
}
4668
}
4769

70+
/**
71+
* Tries to delete a flashcard by id and prints whether it succeeded.
72+
*
73+
* @param flashcardId The id of the flashcard to delete.
74+
* @param flashcardList The list of all known flashcards.
75+
*/
4876
private void deleteFlashcardById(int flashcardId, FlashcardList flashcardList) {
4977
boolean deletionWasSuccessful =
5078
flashcardList.deleteFlashcardById(flashcardId);
5179

5280
if (deletionWasSuccessful) {
53-
System.out.println(" Flashcard with id " + flashcardId + " has been " +
54-
"successfully deleted.");
81+
System.out.println(" Flashcard with id " + flashcardId +
82+
" has been successfully deleted.");
5583
} else {
56-
System.out.println(" Couldn't find a flashcard with id " + flashcardId);
84+
System.out.println(" Couldn't find a flashcard with id "
85+
+ flashcardId);
5786
System.out.println(" No deletion has been performed. Please " +
5887
"try again with a valid id.");
5988
}

0 commit comments

Comments
 (0)