From 4a97d3c4ed4a9fc5de6811ccfb1f2303e3db7a67 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 20 Sep 2020 18:36:01 +0200 Subject: [PATCH] =?utf8?q?=F0=9F=8E=A8=20Extract=20asOptional()=20into=20i?= =?utf8?q?ts=20own=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../rhynodge/filters/comics/SoggyCardboardComicFilter.kt | 3 +-- src/main/kotlin/net/pterodactylus/rhynodge/utils/Optionals.kt | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/net/pterodactylus/rhynodge/utils/Optionals.kt 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) -- 2.7.4