Skip to content

Commit e8047db

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

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

src/main/java/frameworks_and_drivers/database/CommonUserDataAccess.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class CommonUserDataAccess implements IUserDataAccess {
1919
private final Map<String, CommonUserDsRequestModel> accounts = new HashMap<>();
2020

2121
/**
22-
* Creates a common user data access based on the following parameters.
22+
* Creates a common user data access object based on the following parameters.
2323
* @param csvPath the csv file pathway to the database.
2424
*/
2525
public CommonUserDataAccess(String csvPath) throws IOException {

src/main/java/frameworks_and_drivers/database/FlashcardDataAccess.java

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ public class FlashcardDataAccess implements IFlashcardDataAccess {
1515
private final Map<String, Integer> headers = new LinkedHashMap<>();
1616

1717
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+
*/
1922
public FlashcardDataAccess(String csvPath) throws IOException {
2023
flashCardCsvFile = new File(csvPath);
2124

@@ -49,6 +52,9 @@ public FlashcardDataAccess(String csvPath) throws IOException {
4952
reader.close();
5053
}
5154
}
55+
/**
56+
* A private function that is called in the methods below which saves any changes made to a flashcard.
57+
*/
5258
private void save() {
5359
BufferedWriter writer;
5460
try {
@@ -72,12 +78,20 @@ private void save() {
7278
}
7379
}
7480

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+
*/
7686
@Override
77-
public FlashcardDsRequestModel getFlashcard(Integer flashcardID) {
78-
return flashcards.get(flashcardID);
87+
public FlashcardDsRequestModel getFlashcard(Integer flashcardId) {
88+
return flashcards.get(flashcardId);
7989
}
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+
*/
8195
@Override
8296
public int saveFlashcard(FlashcardDsRequestModel flashcard) {
8397
int id = getLargestId() + 1;
@@ -87,18 +101,28 @@ public int saveFlashcard(FlashcardDsRequestModel flashcard) {
87101
return id;
88102
}
89103

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+
*/
90108
private int getLargestId(){
91109
Set<Integer> ids = flashcards.keySet();
92110
return max(ids);
93111
}
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+
*/
95116
@Override
96117
public void editFlashcard(FlashcardDsRequestModel flashcard) {
97118
int id = flashcard.getFlashcardId();
98119
flashcards.replace(id, flashcard);
99120
save();
100121
}
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+
*/
102126
@Override
103127
public void deleteFlashcard(Integer flashcardID) {
104128
flashcards.remove(flashcardID);

0 commit comments

Comments
 (0)