sop.util.Optional.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sop-java Show documentation
Show all versions of sop-java Show documentation
Stateless OpenPGP Protocol API for Java
// SPDX-FileCopyrightText: 2023 Paul Schaub
//
// SPDX-License-Identifier: Apache-2.0
package sop.util
/**
* Backport of java.util.Optional for older Android versions.
*
* @param item type
*/
data class Optional(val item: T? = null) {
val isPresent: Boolean = item != null
val isEmpty: Boolean = item == null
fun get() = item
companion object {
@JvmStatic fun of(item: T) = Optional(item!!)
@JvmStatic fun ofNullable(item: T?) = Optional(item)
@JvmStatic fun ofEmpty() = Optional(null as T?)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy