🎨 Extract asOptional() into its own file
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 20 Sep 2020 16:36:01 +0000 (18:36 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 20 Sep 2020 16:36:01 +0000 (18:36 +0200)
src/main/kotlin/net/pterodactylus/rhynodge/filters/comics/SoggyCardboardComicFilter.kt
src/main/kotlin/net/pterodactylus/rhynodge/utils/Optionals.kt [new file with mode: 0644]

index 59ffb6b..d779a9c 100644 (file)
@@ -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> T?.asOptional(): Optional<T> = 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 (file)
index 0000000..00e9fea
--- /dev/null
@@ -0,0 +1,6 @@
+package net.pterodactylus.rhynodge.utils
+
+import com.google.common.base.Optional
+
+fun <T> T?.asOptional(): Optional<T> = Optional.fromNullable(this)
+fun String?.asOptional(): Optional<String> = if ((this == null) || (this.isEmpty())) Optional.absent() else Optional.of(this)