🚸 Add method that turns any object into a java.util.Optional
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 13 Nov 2024 21:40:02 +0000 (22:40 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 13 Nov 2024 21:40:02 +0000 (22:40 +0100)
src/main/kotlin/net/pterodactylus/rhynodge/utils/Optionals.kt

index 00e9fea..e51b36d 100644 (file)
@@ -4,3 +4,4 @@ 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)
+fun String?.toOptional(): java.util.Optional<String> = java.util.Optional.ofNullable(this)