Skip to content

Commit

Permalink
refactor: make getStoredQueue more concise
Browse files Browse the repository at this point in the history
  • Loading branch information
wzieba committed Nov 3, 2023
1 parent 38e0c2e commit 407429c
Showing 1 changed file with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,25 @@ internal open class LocalStorageRepository(private val context: Context) {
* @return The stored queue of events.
*/
open fun getStoredQueue(): ArrayList<Map<String, Any?>?> {
var storedQueue: ArrayList<Map<String, Any?>?>? = null
try {
val fis = context.applicationContext.openFileInput(STORAGE_KEY)
val ois = ObjectInputStream(fis)
storedQueue = ois.readObject() as ArrayList<Map<String, Any?>?>
ois.close()
} catch (ex: EOFException) {
// Nothing to do here.
} catch (ex: FileNotFoundException) {
// Nothing to do here. Means there was no saved queue.
} catch (ex: Exception) {
ParselyTracker.PLog(
"Exception thrown during queue deserialization: %s",
ex.toString()
)
}
if (storedQueue == null) {
storedQueue = ArrayList()
}
return storedQueue
var storedQueue: ArrayList<Map<String, Any?>?> = ArrayList()
try {
val fis = context.applicationContext.openFileInput(STORAGE_KEY)
val ois = ObjectInputStream(fis)
@Suppress("UNCHECKED_CAST")
storedQueue = ois.readObject() as ArrayList<Map<String, Any?>?>
ois.close()
} catch (ex: EOFException) {
// Nothing to do here.
} catch (ex: FileNotFoundException) {
// Nothing to do here. Means there was no saved queue.
} catch (ex: Exception) {
ParselyTracker.PLog(
"Exception thrown during queue deserialization: %s",
ex.toString()
)
}
return storedQueue
}

/**
* Delete an event from the stored queue.
Expand Down

0 comments on commit 407429c

Please sign in to comment.