Skip to content

Commit 4bde5a5

Browse files
ericli3690david-allison
authored andcommitted
docs: Better ReviewRemindersDatabase docstrings
1 parent d2d121a commit 4bde5a5

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

AnkiDroid/src/main/java/com/ichi2/anki/reviewreminders/ReviewRemindersDatabase.kt

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,23 @@ class ReviewRemindersDatabase {
5656
/**
5757
* Decode an encoded HashMap<[ReviewReminderId], [ReviewReminder]> JSON string.
5858
* @see Json.decodeFromString
59-
* @throws SerializationException If the string is not a valid JSON string.
60-
* @throws IllegalArgumentException If the decoded object is not a HashMap<[ReviewReminderId], [ReviewReminder]>.
59+
* @throws SerializationException If the stored string is not a valid JSON string.
60+
* @throws IllegalArgumentException If the decoded reminders map is not a HashMap<[ReviewReminderId], [ReviewReminder]>.
6161
*/
6262
private fun decodeJson(jsonString: String): HashMap<ReviewReminderId, ReviewReminder> =
6363
Json.decodeFromString<HashMap<ReviewReminderId, ReviewReminder>>(jsonString)
6464

6565
/**
6666
* Encode a Map<[ReviewReminderId], [ReviewReminder]> as a JSON string.
6767
* @see Json.encodeToString
68-
* @throws SerializationException If the string is not a valid JSON string.
68+
* @throws SerializationException If the stored string is somehow not a valid JSON string, even though the input parameter is type-checked.
6969
*/
7070
private fun encodeJson(reminders: Map<ReviewReminderId, ReviewReminder>): String = Json.encodeToString(reminders)
7171

7272
/**
7373
* Get the [ReviewReminder]s for a specific key.
74-
* @throws SerializationException If the string is not a valid JSON string.
75-
* @throws IllegalArgumentException If the decoded object is not a HashMap<[ReviewReminderId], [ReviewReminder]>.
74+
* @throws SerializationException If the value associated with this key is not valid JSON string.
75+
* @throws IllegalArgumentException If the decoded reminders map is not a HashMap<[ReviewReminderId], [ReviewReminder]>.
7676
*/
7777
private fun getRemindersForKey(key: String): HashMap<ReviewReminderId, ReviewReminder> {
7878
val jsonString = AnkiDroidApp.sharedPrefs().getString(key, null) ?: return hashMapOf()
@@ -81,22 +81,22 @@ class ReviewRemindersDatabase {
8181

8282
/**
8383
* Get the [ReviewReminder]s for a specific deck.
84-
* @throws SerializationException If the string is not a valid JSON string.
85-
* @throws IllegalArgumentException If the decoded object is not a HashMap<[ReviewReminderId], [ReviewReminder]>.
84+
* @throws SerializationException If the reminders map has not been stored in SharedPreferences as a valid JSON string.
85+
* @throws IllegalArgumentException If the decoded reminders map is not a HashMap<[ReviewReminderId], [ReviewReminder]>.
8686
*/
8787
fun getRemindersForDeck(did: DeckId): HashMap<ReviewReminderId, ReviewReminder> = getRemindersForKey(DECK_SPECIFIC_KEY + did)
8888

8989
/**
9090
* Get the app-wide [ReviewReminder]s.
91-
* @throws SerializationException If the string is not a valid JSON string.
92-
* @throws IllegalArgumentException If the decoded object is not a HashMap<[ReviewReminderId], [ReviewReminder]>.
91+
* @throws SerializationException If the reminders map has not been stored in SharedPreferences as a valid JSON string.
92+
* @throws IllegalArgumentException If the decoded reminders map is not a HashMap<[ReviewReminderId], [ReviewReminder]>.
9393
*/
9494
fun getAllAppWideReminders(): HashMap<ReviewReminderId, ReviewReminder> = getRemindersForKey(APP_WIDE_KEY)
9595

9696
/**
9797
* Get all [ReviewReminder]s that are associated with a specific deck, grouped by deck ID.
98-
* @throws SerializationException If the string is not a valid JSON string.
99-
* @throws IllegalArgumentException If the decoded object is not a HashMap<[ReviewReminderId], [ReviewReminder]>.
98+
* @throws SerializationException If the reminders maps have not been stored in SharedPreferences as valid JSON strings.
99+
* @throws IllegalArgumentException If the decoded reminders maps are not instances of HashMap<[ReviewReminderId], [ReviewReminder]>.
100100
*/
101101
private fun getAllDeckSpecificRemindersGrouped(): Map<DeckId, HashMap<ReviewReminderId, ReviewReminder>> {
102102
return AnkiDroidApp
@@ -112,17 +112,17 @@ class ReviewRemindersDatabase {
112112

113113
/**
114114
* Get all [ReviewReminder]s that are associated with a specific deck, all in a single flattened map.
115-
* @throws SerializationException If the string is not a valid JSON string.
116-
* @throws IllegalArgumentException If the decoded object is not a HashMap<[ReviewReminderId], [ReviewReminder]>.
115+
* @throws SerializationException If the reminders maps have not been stored in SharedPreferences as valid JSON strings.
116+
* @throws IllegalArgumentException If the decoded reminders maps are not instances of HashMap<[ReviewReminderId], [ReviewReminder]>.
117117
*/
118118
fun getAllDeckSpecificReminders(): HashMap<ReviewReminderId, ReviewReminder> = getAllDeckSpecificRemindersGrouped().flatten()
119119

120120
/**
121121
* Edit the [ReviewReminder]s for a specific key.
122122
* @param key
123123
* @param reminderEditor A lambda that takes the current map and returns the updated map.
124-
* @throws SerializationException If the string is not a valid JSON string.
125-
* @throws IllegalArgumentException If the decoded object is not a HashMap<[ReviewReminderId], [ReviewReminder]>.
124+
* @throws SerializationException If the current reminders map has not been stored in SharedPreferences as a valid JSON string.
125+
* @throws IllegalArgumentException If the decoded current reminders map is not a HashMap<[ReviewReminderId], [ReviewReminder]>.
126126
*/
127127
private fun editRemindersForKey(
128128
key: String,
@@ -140,8 +140,8 @@ class ReviewRemindersDatabase {
140140
* This assumes the resulting map contains only reminders of scope [ReviewReminderScope.DeckSpecific].
141141
* @param did
142142
* @param reminderEditor A lambda that takes the current map and returns the updated map.
143-
* @throws SerializationException If the string is not a valid JSON string.
144-
* @throws IllegalArgumentException If the decoded object is not a HashMap<[ReviewReminderId], [ReviewReminder]>.
143+
* @throws SerializationException If the current reminders map has not been stored in SharedPreferences as a valid JSON string.
144+
* @throws IllegalArgumentException If the decoded current reminders map is not a HashMap<[ReviewReminderId], [ReviewReminder]>.
145145
*/
146146
fun editRemindersForDeck(
147147
did: DeckId,
@@ -152,8 +152,8 @@ class ReviewRemindersDatabase {
152152
* Edit the app-wide [ReviewReminder]s.
153153
* This assumes the resulting map contains only reminders of scope [ReviewReminderScope.Global].
154154
* @param reminderEditor A lambda that takes the current map and returns the updated map.
155-
* @throws SerializationException If the string is not a valid JSON string.
156-
* @throws IllegalArgumentException If the decoded object is not a HashMap<[ReviewReminderId], [ReviewReminder]>.
155+
* @throws SerializationException If the current reminders map has not been stored in SharedPreferences as a valid JSON string.
156+
* @throws IllegalArgumentException If the decoded current reminders map is not a HashMap<[ReviewReminderId], [ReviewReminder]>.
157157
*/
158158
fun editAllAppWideReminders(reminderEditor: (HashMap<ReviewReminderId, ReviewReminder>) -> Map<ReviewReminderId, ReviewReminder>) =
159159
editRemindersForKey(APP_WIDE_KEY, reminderEditor)
@@ -162,8 +162,8 @@ class ReviewRemindersDatabase {
162162
* Edit all [ReviewReminder]s that are associated with a specific deck by operating on a single mutable map.
163163
* This assumes the resulting map contains only reminders of scope [ReviewReminderScope.DeckSpecific].
164164
* @param reminderEditor A lambda that takes the current map and returns the updated map.
165-
* @throws SerializationException If the string is not a valid JSON string.
166-
* @throws IllegalArgumentException If the decoded object is not a HashMap<[ReviewReminderId], [ReviewReminder]>.
165+
* @throws SerializationException If the current reminders maps have not been stored in SharedPreferences as valid JSON strings.
166+
* @throws IllegalArgumentException If the decoded current reminders maps are not instances of HashMap<[ReviewReminderId], [ReviewReminder]>.
167167
*/
168168
fun editAllDeckSpecificReminders(reminderEditor: (HashMap<ReviewReminderId, ReviewReminder>) -> Map<ReviewReminderId, ReviewReminder>) {
169169
val existingRemindersGrouped = getAllDeckSpecificRemindersGrouped()
@@ -211,7 +211,7 @@ class ReviewRemindersDatabase {
211211
/**
212212
* Helper method for getting all SharedPreferences that represent app-wide or deck-specific reminder HashMaps.
213213
* For example, may be used for constructing a backup of all review reminders pending a potentially-destructive migration operation.
214-
* Does not return the next-free-ID preference for review reminders used by [ReviewReminder.getAndIncrementNextFreeReminderId].
214+
* Does not return the next-free-ID preference for review reminders used by [ReviewReminderId.getAndIncrementNextFreeReminderId].
215215
*/
216216
fun getAllReviewReminderSharedPrefsAsMap(): Map<String, Any?> =
217217
AnkiDroidApp.sharedPrefs().all.filter {
@@ -221,7 +221,7 @@ class ReviewRemindersDatabase {
221221

222222
/**
223223
* Helper method for deleting all SharedPreferences that represent app-wide or deck-specific reminder HashMaps.
224-
* Does not delete the next-free-ID preference for review reminders used by [ReviewReminder.getAndIncrementNextFreeReminderId].
224+
* Does not delete the next-free-ID preference for review reminders used by [ReviewReminderId.getAndIncrementNextFreeReminderId].
225225
*
226226
* For example, may be used when a potentially-destructive operation, like a failed migration, has been applied to all review reminders.
227227
* This method can be used to delete all potentially-corrupted review reminder shared preferences so that backed-up
@@ -247,8 +247,8 @@ class ReviewRemindersDatabase {
247247
* need to have their data ported to the new schema.
248248
* @param serializer The serializer for the old schema of type [T] implementing [OldReviewReminderSchema]
249249
* @see [OldReviewReminderSchema]
250-
* @throws SerializationException If the string is not a valid JSON string.
251-
* @throws IllegalArgumentException If the decoded object is not a HashMap<[ReviewReminderId], [T]>.
250+
* @throws SerializationException If the current reminders maps have not been stored in SharedPreferences as valid JSON strings.
251+
* @throws IllegalArgumentException If the decoded current reminders maps are not instances of HashMap<[ReviewReminderId], [T]>.
252252
*/
253253
fun <T : OldReviewReminderSchema> attemptSchemaMigration(serializer: KSerializer<T>) {
254254
val mapSerializer = MapSerializer(ReviewReminderId.serializer(), serializer)

0 commit comments

Comments
 (0)