-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathFloatStrategy.kt
30 lines (27 loc) · 1.16 KB
/
FloatStrategy.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.sipios.springsearch.strategies
import com.sipios.springsearch.SearchOperation
import jakarta.persistence.criteria.CriteriaBuilder
import jakarta.persistence.criteria.Path
import jakarta.persistence.criteria.Predicate
import kotlin.reflect.KClass
class FloatStrategy : ParsingStrategy {
override fun buildPredicate(
builder: CriteriaBuilder,
path: Path<*>,
fieldName: String,
ops: SearchOperation?,
value: Any?
): Predicate? {
return when (ops) {
SearchOperation.GREATER_THAN -> builder.greaterThan(path[fieldName], value as Float)
SearchOperation.LESS_THAN -> builder.lessThan(path[fieldName], value as Float)
SearchOperation.GREATER_THAN_EQUALS -> builder.greaterThanOrEqualTo(path[fieldName], value as Float)
SearchOperation.LESS_THAN_EQUALS -> builder.lessThanOrEqualTo(path[fieldName], value as Float)
else -> super.buildPredicate(builder, path, fieldName, ops, value)
}
}
override fun parse(value: String?, fieldClass: KClass<out Any>): Any? {
if (value == SearchOperation.NULL) return value
return value?.toFloat()
}
}