Skip to content

Commit

Permalink
refactor: use constants instead of plain strings to declare built-in …
Browse files Browse the repository at this point in the history
…operators (#33)
  • Loading branch information
rapatao authored Jul 25, 2024
1 parent 905b772 commit 5b2b115
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.rapatao.projects.ruleset.engine.types.builder

import com.rapatao.projects.ruleset.engine.types.Expression
import com.rapatao.projects.ruleset.engine.types.operators.BuiltInOperators

/**
* A builder class for constructing expressions representing a between condition.
Expand All @@ -18,7 +19,7 @@ data class BetweenBuilder(val left: Any, val from: Any, val operator: String) {
*/
infix fun to(to: Any): Expression = MatcherBuilder.allMatch(
ExpressionBuilder.expression(left = left, operator = operator, right = from),
ExpressionBuilder.expression(left = left, operator = "less_than", right = to),
ExpressionBuilder.expression(left = left, operator = BuiltInOperators.LESS_THAN, right = to),
)

/**
Expand All @@ -29,7 +30,6 @@ data class BetweenBuilder(val left: Any, val from: Any, val operator: String) {
*/
infix fun toInclusive(to: Any): Expression = MatcherBuilder.allMatch(
ExpressionBuilder.expression(left = left, operator = operator, right = from),
ExpressionBuilder.expression(left = left, operator = "less_or_equal_than", right = to),
ExpressionBuilder.expression(left = left, operator = BuiltInOperators.LESS_OR_EQUAL_THAN, right = to),
)
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.rapatao.projects.ruleset.engine.types.builder.extensions

import com.rapatao.projects.ruleset.engine.types.builder.BetweenBuilder
import com.rapatao.projects.ruleset.engine.types.operators.BuiltInOperators

/**
* Creates a [BetweenBuilder] object to build a between condition.
Expand All @@ -9,7 +10,7 @@ import com.rapatao.projects.ruleset.engine.types.builder.BetweenBuilder
* @return A [BetweenBuilder] object to build the between condition.
*/
infix fun Any.from(from: Any): BetweenBuilder = BetweenBuilder(
left = this, from = from, operator = "greater_than",
left = this, from = from, operator = BuiltInOperators.GREATER_THAN,
)

/**
Expand All @@ -19,5 +20,5 @@ infix fun Any.from(from: Any): BetweenBuilder = BetweenBuilder(
* @return The [BetweenBuilder] instance for further chaining
*/
infix fun Any.fromInclusive(from: Any): BetweenBuilder = BetweenBuilder(
left = this, from = from, operator = "greater_or_equal_than",
left = this, from = from, operator = BuiltInOperators.GREATER_OR_EQUAL_THAN,
)

0 comments on commit 5b2b115

Please sign in to comment.