refactor: use ifBlank instead of if isBlank

This commit is contained in:
Gauthier Roebroeck 2020-06-30 21:45:38 +08:00
parent 55b6e86326
commit 94a1f706c8
3 changed files with 4 additions and 8 deletions

View file

@ -56,7 +56,7 @@ class ComicInfoProvider(
comicInfo.publisher,
comicInfo.ageRating?.ageRating,
releaseDate,
if (authors.isEmpty()) null else authors,
authors.ifEmpty { null },
SeriesMetadataPatch(
comicInfo.series,
comicInfo.series,

View file

@ -50,8 +50,8 @@ class EpubMetadataProvider(
val authors = opf.select("metadata > dc|creator")
.map {
val name = it.text()
val opfRole = it.attr("opf|role").orNull()
val id = it.attr("id").orNull()
val opfRole = it.attr("opf|role").ifBlank { null }
val id = it.attr("id").ifBlank { null }
val refineRole = creatorRefines[id]
val role = opfRole ?: refineRole
Author(name, relators[role] ?: "writer")
@ -75,8 +75,6 @@ class EpubMetadataProvider(
return null
}
private fun String.orNull() = if (isBlank()) null else this
private fun parseDate(date: String): LocalDate? =
try {
LocalDate.parse(date, DateTimeFormatter.ISO_DATE)

View file

@ -9,9 +9,7 @@ import javax.servlet.ServletContext
class IndexController(
servletContext: ServletContext
) {
private val baseUrl: String =
if (servletContext.contextPath.isBlank()) "/"
else "${servletContext.contextPath}/"
private val baseUrl: String = "${servletContext.contextPath}/"
@GetMapping("/")
fun index(model: Model): String {