@@ -15,6 +15,10 @@ public class FlashcardSetDataAccess implements IFlashcardSetDataAccess {
15
15
16
16
private final Map <Integer , FlashcardSetDsRequestModel > flashcardSets = new HashMap <>();
17
17
18
+ /**
19
+ * Creates a flashcard set data access object based on the following parameters.
20
+ * @param csvPath the csv file pathway to the database.
21
+ */
18
22
public FlashcardSetDataAccess (String csvPath ) throws IOException {
19
23
flashCardSetCsvFile = new File (csvPath );
20
24
@@ -53,6 +57,9 @@ public FlashcardSetDataAccess(String csvPath) throws IOException {
53
57
reader .close ();
54
58
}
55
59
}
60
+ /**
61
+ * A private function that is called in the methods below which saves any changes made to a flashcard set.
62
+ */
56
63
private void save () {
57
64
BufferedWriter writer ;
58
65
try {
@@ -78,25 +85,42 @@ private void save() {
78
85
throw new RuntimeException (e );
79
86
}
80
87
}
81
-
88
+ /**
89
+ * Gets the flashcard set request model containing the given flashcard set id.
90
+ * @param flashcardSetId the id of the flashcard set.
91
+ * @return the flashcard set request model containing the given flashcard set id.
92
+ */
82
93
@ Override
83
94
public FlashcardSetDsRequestModel getFlashcardSet (int flashcardSetId ) {
84
95
return flashcardSets .get (flashcardSetId );
85
96
}
86
97
98
+ /**
99
+ * Gets the title and description of the flashcard set
100
+ * @param flashcardSetId the id of the flashcard set.
101
+ * @return the tile and description of the flashcard set
102
+ */
87
103
@ Override
88
104
public String [] getTitleAndDescription (int flashcardSetId ) {
89
105
return new String [] {flashcardSets .get (flashcardSetId ).getTitle (),
90
106
flashcardSets .get (flashcardSetId ).getDescription ()};
91
107
}
92
108
109
+ /**
110
+ * Edits the title and description of the flashcard set by edits given and rewrites the flashcard set database.
111
+ * @param flashcardSet the flashcard set object.
112
+ */
93
113
@ Override
94
114
public void editTitleAndDescription (FlashcardSetDsRequestModel flashcardSet ) {
95
115
int id = flashcardSet .getFlashcardSetId ();
96
116
flashcardSets .replace (id , flashcardSet );
97
117
save ();
98
118
}
99
-
119
+ /**
120
+ * Saves the newly created flashcard id into the list of flashcard ids contained in the flashcard set.
121
+ * @param flashcardSetId the id of the flashcard set.
122
+ * @param flashcardId the id of the flashcard that will be added.
123
+ */
100
124
@ Override
101
125
public void saveFlashcardID (int flashcardSetId , int flashcardId ) {
102
126
FlashcardSetDsRequestModel oldFlashcardSet = flashcardSets .get (flashcardSetId );
@@ -111,7 +135,11 @@ public void saveFlashcardID(int flashcardSetId, int flashcardId) {
111
135
flashcardSets .put (flashcardSetId , newFlashcardSet );
112
136
save ();
113
137
}
114
-
138
+ /**
139
+ * Removes a flashcard id from the list of flashcard ids contained in the flashcard set.
140
+ * @param flashcardSetId the id of the flashcard set.
141
+ * @param flashcardId the id of the flashcard that will be removed.
142
+ */
115
143
@ Override
116
144
public void removeFlashcardId (int flashcardSetId , int flashcardId ){
117
145
FlashcardSetDsRequestModel oldFlashcardSet = flashcardSets .get (flashcardSetId );
@@ -126,13 +154,20 @@ public void removeFlashcardId(int flashcardSetId, int flashcardId){
126
154
flashcardSets .put (flashcardSetId , newFlashcardSet );
127
155
save ();
128
156
}
129
-
157
+ /**
158
+ * Deletes a flashcard set containing the given id.
159
+ * @param flashcardSetID the id of the flashcard set that will be deleted.
160
+ */
130
161
@ Override
131
162
public void deleteFlashcardSet (int flashcardSetID ) {
132
163
flashcardSets .remove (flashcardSetID );
133
164
save ();
134
165
}
135
-
166
+ /**
167
+ * Saves a newly created flashcard set with a unique id into the database.
168
+ * @param flashcardSet the flashcard set object.
169
+ * @return the id of the newly created flashcard set.
170
+ */
136
171
@ Override
137
172
public int saveFlashcardSet (FlashcardSetDsRequestModel flashcardSet ) {
138
173
int id = getLargestId () + 1 ;
@@ -141,7 +176,10 @@ public int saveFlashcardSet(FlashcardSetDsRequestModel flashcardSet) {
141
176
save ();
142
177
return id ;
143
178
}
144
-
179
+ /**
180
+ * Gets the largest id contained in a flashcard set in the database.
181
+ * @return the largest id contained in a flashcard set in the database.
182
+ */
145
183
private int getLargestId (){
146
184
if (flashcardSets .size () == 0 ) {
147
185
return -1 ;
0 commit comments