From: David ‘Bombe’ Roden Date: Sun, 20 Sep 2020 16:36:01 +0000 (+0200) Subject: 🎨 Extract asOptional() into its own file X-Git-Tag: v2~82 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=4a97d3c4ed4a9fc5de6811ccfb1f2303e3db7a67;p=rhynodge.git 🎨 Extract asOptional() into its own file --- diff --git a/src/main/kotlin/net/pterodactylus/rhynodge/filters/comics/SoggyCardboardComicFilter.kt b/src/main/kotlin/net/pterodactylus/rhynodge/filters/comics/SoggyCardboardComicFilter.kt index 59ffb6b..d779a9c 100644 --- a/src/main/kotlin/net/pterodactylus/rhynodge/filters/comics/SoggyCardboardComicFilter.kt +++ b/src/main/kotlin/net/pterodactylus/rhynodge/filters/comics/SoggyCardboardComicFilter.kt @@ -2,6 +2,7 @@ package net.pterodactylus.rhynodge.filters.comics import com.google.common.base.Optional import net.pterodactylus.rhynodge.filters.ComicSiteFilter +import net.pterodactylus.rhynodge.utils.asOptional import org.jsoup.nodes.Document class SoggyCardboardComicFilter : ComicSiteFilter() { @@ -16,5 +17,3 @@ class SoggyCardboardComicFilter : ComicSiteFilter() { listOf(document.select("#comic img").attr("alt")) } - -fun T?.asOptional(): Optional = Optional.fromNullable(this) diff --git a/src/main/kotlin/net/pterodactylus/rhynodge/utils/Optionals.kt b/src/main/kotlin/net/pterodactylus/rhynodge/utils/Optionals.kt new file mode 100644 index 0000000..00e9fea --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/rhynodge/utils/Optionals.kt @@ -0,0 +1,6 @@ +package net.pterodactylus.rhynodge.utils + +import com.google.common.base.Optional + +fun T?.asOptional(): Optional = Optional.fromNullable(this) +fun String?.asOptional(): Optional = if ((this == null) || (this.isEmpty())) Optional.absent() else Optional.of(this)