fun previousLess()

in dnq-transient-store/src/main/kotlin/com/jetbrains/teamsys/dnq/association/PrimitiveAssociationSemantics.kt [272:311]


    fun previousLess(value: Comparable<*>, clazz: Class<*>): Comparable<*>? {
        return when (clazz) {
            Byte::class.javaPrimitiveType,
            Byte::class.javaObjectType ->
                value as Byte - 1
            Short::class.javaPrimitiveType,
            Short::class.javaObjectType ->
                value as Short - 1
            Int::class.javaPrimitiveType,
            Int::class.javaObjectType ->
                value as Int - 1
            Long::class.javaPrimitiveType,
            Long::class.javaObjectType ->
                value as Long - 1
            Float::class.javaPrimitiveType,
            Float::class.javaObjectType -> {
                var result: Float
                var subtrahend = FLOAT_PRECISION
                do {
                    result = value as Float - subtrahend
                    subtrahend *= 2f
                } while (value == result)
                result
            }
            Double::class.javaPrimitiveType,
            Double::class.javaObjectType -> {
                var result: Double
                var subtrahend = DOUBLE_PRECISION
                do {
                    result = value as Double - subtrahend
                    subtrahend *= 2.0
                } while (value == result)
                result
            }
            Boolean::class.javaPrimitiveType,
            Boolean::class.javaObjectType ->
                false
            else -> null
        }
    }