All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sop.util.Optional.kt Maven / Gradle / Ivy

There is a newer version: 10.0.3
Show newest version
// 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