Skip to content

Commit b25fe19

Browse files
Merge pull request #79 from junhyeong0411/master
Changed Storage to add difficulty and remove review
2 parents b359c58 + a011ec3 commit b25fe19

File tree

6 files changed

+31
-72
lines changed

6 files changed

+31
-72
lines changed

data/flashcards/flashcard 1124.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3 | Hello | Duke | - | - | -

data/flashcards/flashcard.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
3 | Hello | Duke | - | - | -
1+
3 | cs2113 | software enginnering | 5
2+
5 | Hello | Duke | 5
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
@startuml
2-
activate FlashcardStorage
2+
3+
autoactivate on
4+
participant FlashcardComponent as fc
5+
participant FlashcardStorage as fs
6+
participant FlashcardDirectory as fd
7+
8+
fc -> fs :
39

410

511
@enduml

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ public void setId (int id) {
5151
this.id = id;
5252
}
5353

54+
public void setDifficulty(int difficulty) {
55+
this.difficulty = difficulty;
56+
}
57+
5458

5559
//@@author wendelinwemhoener
5660
public String toString() {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public FlashcardList loadFlashcards() throws FileNotFoundException{
5050
while(s.hasNext()){
5151
String[] flashTokens = s.nextLine().split(" \\| ");
5252
flashcardList.add(FlashcardStorageParser.loadFlashcard(flashTokens));
53+
flashlogger.log(Level.INFO, "added flashcard");
54+
5355
}
5456

5557
flashlogger.log(Level.INFO, String.format(
@@ -78,12 +80,10 @@ public boolean saveFlashcards(ArrayList<Flashcard> flashcardList) {
7880
int id = flashcard.getId();
7981
String frontText = flashcard.getFrontText();
8082
String backText = flashcard.getBackText();
81-
ArrayList<FlashcardReview> reviewList = flashcard.getReviews();
82-
83-
String reviews = FlashcardStorageParser.reviewtoString(reviewList);
83+
int difficulty = flashcard.getDifficulty();
8484

85-
fw.write(String.format("%d | %s | %s | - | %s | -\r\n",
86-
id, frontText, backText, reviews));
85+
fw.write(String.format("%d | %s | %s | %d \r\n",
86+
id, frontText, backText, difficulty));
8787
}
8888
fw.close();
8989
return true;
Lines changed: 12 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package seedu.duke.flashcard;
22

33
import java.time.LocalDateTime;
4-
import java.util.ArrayList;
4+
import java.util.logging.Level;
5+
import java.util.logging.Logger;
56

67
/**
78
* FlashcardStorageParser class
89
* Utility class for parsing
910
*/
1011
public final class FlashcardStorageParser {
1112

13+
private static Logger flashlogger; // for logging
14+
1215
/**
1316
* load a flash card from certain format
1417
* Tokens includes attributes of Flashcard
@@ -17,82 +20,26 @@ public final class FlashcardStorageParser {
1720
*/
1821
public static Flashcard loadFlashcard(String[] tokens){
1922

20-
assert tokens.length == 6 : "Token length should be 5";
23+
flashlogger = Logger.getLogger("flash");
24+
flashlogger.setLevel(Level.WARNING);
25+
26+
assert tokens.length == 4 : "Token length should be 4";
2127

22-
// flashlogger.log(Level.INFO, "token length is", tokens.length);
23-
// System.out.println(tokens[0]);
28+
flashlogger.log(Level.INFO, "token length is", tokens.length);
2429

2530
int id = Integer.parseInt(tokens[0].trim());
2631
String frontText = tokens[1].trim();
2732
String backText = tokens[2].trim();
28-
String[] tags = tokens[3].trim().split("/");
29-
String[] reviews = tokens[4].trim().split("/");
30-
String nextReviewOn = tokens[5].trim();
33+
int difficulty = Integer.parseInt(tokens[3].trim());
3134

3235

3336
Flashcard flashcard = new Flashcard(frontText, backText);
3437

3538
flashcard.setId(id);
39+
flashcard.setDifficulty(difficulty);
3640

37-
//flashlogger.log(Level.INFO, "added flashcard");
38-
39-
for(String tag:tags){
40-
if (tag.trim().equals("-")) {
41-
break;
42-
} else{
43-
System.out.println("tags are not for v1");
44-
}
45-
}
46-
47-
for(String review: reviews){
48-
if (review.trim().equals("-")) {
49-
break;
50-
} else{
51-
String[] reviewTokens = review.split("#");
52-
LocalDateTime reviewDate = LocalDateTime.parse(reviewTokens[0].trim());
53-
ReviewDifficulty reviewDifficulty = ReviewDifficulty.valueOf(reviewTokens[1].trim());
54-
55-
FlashcardReview flashcardReview = new FlashcardReview(reviewDate, reviewDifficulty);
56-
flashcard.addReview(flashcardReview);
57-
58-
flashcard.setLastReviewOn(reviewDate);
59-
60-
}
61-
}
62-
63-
if(!nextReviewOn.equals("-")){
64-
//LocalDateTime.parse(nextReviewOn);
65-
System.out.println("reviews are not for v1");
66-
}
41+
flashlogger.log(Level.INFO, "loaded flashcard");
6742

6843
return flashcard;
6944
}
70-
71-
/**
72-
* reviews to String methods
73-
* make String from reviews list
74-
* @param reviewList
75-
* @return String of review
76-
*/
77-
public static String reviewtoString(ArrayList<FlashcardReview> reviewList){
78-
StringBuilder reviews;
79-
80-
if(reviewList.isEmpty()){
81-
reviews = new StringBuilder("-");
82-
} else{
83-
reviews = new StringBuilder();
84-
for(FlashcardReview review: reviewList){
85-
if(reviews.length() > 0){
86-
reviews.append("/");
87-
}
88-
reviews.append(review.getReviewDate().toString());
89-
// identifier between date and difficulty is #
90-
reviews.append(" # ");
91-
reviews.append(review.getReviewDifficulty());
92-
93-
}
94-
}
95-
96-
return reviews.toString();
97-
}
9845
}

0 commit comments

Comments
 (0)