@@ -15,7 +15,10 @@ public class FlashcardDataAccess implements IFlashcardDataAccess {
15
15
private final Map <String , Integer > headers = new LinkedHashMap <>();
16
16
17
17
private final Map <Integer , FlashcardDsRequestModel > flashcards = new HashMap <>();
18
-
18
+ /**
19
+ * Creates a flashcard data access object based on the following parameters.
20
+ * @param csvPath the csv file pathway to the database.
21
+ */
19
22
public FlashcardDataAccess (String csvPath ) throws IOException {
20
23
flashCardCsvFile = new File (csvPath );
21
24
@@ -49,6 +52,9 @@ public FlashcardDataAccess(String csvPath) throws IOException {
49
52
reader .close ();
50
53
}
51
54
}
55
+ /**
56
+ * A private function that is called in the methods below which saves any changes made to a flashcard.
57
+ */
52
58
private void save () {
53
59
BufferedWriter writer ;
54
60
try {
@@ -72,12 +78,20 @@ private void save() {
72
78
}
73
79
}
74
80
75
-
81
+ /**
82
+ * Gets the flashcard request model containing a given flashcard id.
83
+ * @param flashcardId the id of the flashcard.
84
+ * @return the flashcard request model containing a given flashcard id.
85
+ */
76
86
@ Override
77
- public FlashcardDsRequestModel getFlashcard (Integer flashcardID ) {
78
- return flashcards .get (flashcardID );
87
+ public FlashcardDsRequestModel getFlashcard (Integer flashcardId ) {
88
+ return flashcards .get (flashcardId );
79
89
}
80
-
90
+ /**
91
+ * Saves a newly created flashcard into the database with a unique id.
92
+ * @param flashcard the flashcard object that will be created.
93
+ * @return the id of the flashcard saved.
94
+ */
81
95
@ Override
82
96
public int saveFlashcard (FlashcardDsRequestModel flashcard ) {
83
97
int id = getLargestId () + 1 ;
@@ -87,18 +101,28 @@ public int saveFlashcard(FlashcardDsRequestModel flashcard) {
87
101
return id ;
88
102
}
89
103
104
+ /**
105
+ * Gets the largest id contained in a flashcard in the database.
106
+ * @return the largest id contained in a flashcard in the database.
107
+ */
90
108
private int getLargestId (){
91
109
Set <Integer > ids = flashcards .keySet ();
92
110
return max (ids );
93
111
}
94
-
112
+ /**
113
+ * Edits the flashcard by edits given and rewrites the flashcard database.
114
+ * @param flashcard the flashcard request model that will be edited
115
+ */
95
116
@ Override
96
117
public void editFlashcard (FlashcardDsRequestModel flashcard ) {
97
118
int id = flashcard .getFlashcardId ();
98
119
flashcards .replace (id , flashcard );
99
120
save ();
100
121
}
101
-
122
+ /**
123
+ * Deletes the flashcard containing the given id and rewrites the flashcard database.
124
+ * @param flashcardID the id of the flashcard that will be deleted.
125
+ */
102
126
@ Override
103
127
public void deleteFlashcard (Integer flashcardID ) {
104
128
flashcards .remove (flashcardID );
0 commit comments