Skip to content
Permalink
Browse files

Issue #570: Fretboard: More idiomatic Kotlin on FlatFileExperimentSto…

…rage and on ExperimentSerializer

Closes #570: Fretboard: More idiomatic Kotlin on FlatFileExperimentStorage and on ExperimentSerializer
  • Loading branch information...
fercarcedo authored and pocmo committed Aug 7, 2018
1 parent 0ba81f5 commit 40d000b7a8815cb6b8786e49b501f8e86bee7ef4
@@ -48,11 +48,10 @@ internal class ExperimentsSerializer {
val jsonParser = JSONExperimentParser()
for (i in 0 until experimentsJsonArray.length())
experiments.add(jsonParser.fromJson(experimentsJsonArray[i] as JSONObject))
val lastModified: Long?
if (experimentsJson.has(LAST_MODIFIED_KEY)) {
lastModified = experimentsJson.getLong(LAST_MODIFIED_KEY)
val lastModified = if (experimentsJson.has(LAST_MODIFIED_KEY)) {
experimentsJson.getLong(LAST_MODIFIED_KEY)
} else {
lastModified = null
null
}
return ExperimentsSnapshot(experiments, lastModified)
}
@@ -14,11 +14,11 @@ class FlatFileExperimentStorage(file: File) : ExperimentStorage {
private val atomicFile: AtomicFile = AtomicFile(file)

override fun retrieve(): ExperimentsSnapshot {
try {
return try {
val experimentsJson = String(atomicFile.readFully())
return ExperimentsSerializer().fromJson(experimentsJson)
ExperimentsSerializer().fromJson(experimentsJson)
} catch (e: FileNotFoundException) {
return ExperimentsSnapshot(listOf(), null)
ExperimentsSnapshot(listOf(), null)
}
}

0 comments on commit 40d000b

Please sign in to comment.
You can’t perform that action at this time.