Skip to content

Commit fa125bc

Browse files
committed
java doc for flashcard set data access
1 parent e8047db commit fa125bc

File tree

1 file changed

+44
-6
lines changed

1 file changed

+44
-6
lines changed

src/main/java/frameworks_and_drivers/database/FlashcardSetDataAccess.java

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ public class FlashcardSetDataAccess implements IFlashcardSetDataAccess {
1515

1616
private final Map<Integer, FlashcardSetDsRequestModel> flashcardSets = new HashMap<>();
1717

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+
*/
1822
public FlashcardSetDataAccess(String csvPath) throws IOException {
1923
flashCardSetCsvFile = new File(csvPath);
2024

@@ -53,6 +57,9 @@ public FlashcardSetDataAccess(String csvPath) throws IOException {
5357
reader.close();
5458
}
5559
}
60+
/**
61+
* A private function that is called in the methods below which saves any changes made to a flashcard set.
62+
*/
5663
private void save() {
5764
BufferedWriter writer;
5865
try {
@@ -78,25 +85,42 @@ private void save() {
7885
throw new RuntimeException(e);
7986
}
8087
}
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+
*/
8293
@Override
8394
public FlashcardSetDsRequestModel getFlashcardSet(int flashcardSetId) {
8495
return flashcardSets.get(flashcardSetId);
8596
}
8697

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+
*/
87103
@Override
88104
public String[] getTitleAndDescription(int flashcardSetId) {
89105
return new String[] {flashcardSets.get(flashcardSetId).getTitle(),
90106
flashcardSets.get(flashcardSetId).getDescription()};
91107
}
92108

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+
*/
93113
@Override
94114
public void editTitleAndDescription(FlashcardSetDsRequestModel flashcardSet) {
95115
int id = flashcardSet.getFlashcardSetId();
96116
flashcardSets.replace(id, flashcardSet);
97117
save();
98118
}
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+
*/
100124
@Override
101125
public void saveFlashcardID(int flashcardSetId, int flashcardId) {
102126
FlashcardSetDsRequestModel oldFlashcardSet = flashcardSets.get(flashcardSetId);
@@ -111,7 +135,11 @@ public void saveFlashcardID(int flashcardSetId, int flashcardId) {
111135
flashcardSets.put(flashcardSetId, newFlashcardSet);
112136
save();
113137
}
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+
*/
115143
@Override
116144
public void removeFlashcardId(int flashcardSetId, int flashcardId){
117145
FlashcardSetDsRequestModel oldFlashcardSet = flashcardSets.get(flashcardSetId);
@@ -126,13 +154,20 @@ public void removeFlashcardId(int flashcardSetId, int flashcardId){
126154
flashcardSets.put(flashcardSetId, newFlashcardSet);
127155
save();
128156
}
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+
*/
130161
@Override
131162
public void deleteFlashcardSet(int flashcardSetID) {
132163
flashcardSets.remove(flashcardSetID);
133164
save();
134165
}
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+
*/
136171
@Override
137172
public int saveFlashcardSet(FlashcardSetDsRequestModel flashcardSet) {
138173
int id = getLargestId() + 1;
@@ -141,7 +176,10 @@ public int saveFlashcardSet(FlashcardSetDsRequestModel flashcardSet) {
141176
save();
142177
return id;
143178
}
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+
*/
145183
private int getLargestId(){
146184
if (flashcardSets.size() == 0) {
147185
return -1;

0 commit comments

Comments
 (0)