alex.hart
08/17/2017, 1:04 PMsealed class DString {
class Empty private constructor() : DString() {
companion object {
val empty = Empty()
}
}
class NonEmpty private constructor(val s: String) : DString() {
companion object {
@Deprecated("Use [DString.create]")
fun create(s: String) = if (s.isNotEmpty()) NonEmpty(s) else Empty.empty
}
}
companion object {
@Suppress("DEPRECATION")
fun create(s: String?) = s?.let { NonEmpty.create(it) } ?: Empty.empty
}
}