Add utility functions
This commit is contained in:
@@ -76,6 +76,10 @@ class Manga(
|
||||
val hasRating: Boolean
|
||||
get() = rating in 0f..1f
|
||||
|
||||
fun getChapters(branch: String?): List<MangaChapter>? {
|
||||
return chapters?.filter { x -> x.branch == branch }
|
||||
}
|
||||
|
||||
@InternalParsersApi
|
||||
fun copy(
|
||||
title: String = this.title,
|
||||
|
||||
@@ -94,6 +94,16 @@ fun JSONObject.getDoubleOrDefault(name: String, defaultValue: Double): Double {
|
||||
}
|
||||
}
|
||||
|
||||
fun JSONObject.getFloatOrDefault(name: String, defaultValue: Float): Float {
|
||||
return when (val rawValue = opt(name)) {
|
||||
null, JSONObject.NULL -> defaultValue
|
||||
is Float -> rawValue
|
||||
is Number -> rawValue.toFloat()
|
||||
is String -> rawValue.toFloatOrNull() ?: defaultValue
|
||||
else -> defaultValue
|
||||
}
|
||||
}
|
||||
|
||||
fun JSONArray.JSONIterator(): Iterator<JSONObject> = JSONIterator(this)
|
||||
|
||||
fun JSONArray.stringIterator(): Iterator<String> = JSONStringIterator(this)
|
||||
|
||||
Reference in New Issue
Block a user