Skip to content

Commit

Permalink
feat: add getSimplified to expr class
Browse files Browse the repository at this point in the history
  • Loading branch information
lbressler13 committed Feb 29, 2024
1 parent 2fa0f69 commit 24095dd
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ sealed class Expression : Number() {
// abstract operator fun div(other: Expression): Expression

abstract fun toTerm(): Term
abstract fun getSimplified(): Expression

companion object {
val ZERO: Expression = SimpleExpression(Term.ZERO)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ internal class AdditiveExpression private constructor(private val expressions: C

// TODO
override fun getValue(): BigDecimal = BigDecimal.ZERO
// TODO
override fun getSimplified(): Expression = this

override fun hashCode(): Int = createHashCode(listOf(expressions, "AdditiveExpression"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ internal class MultiplicativeExpression private constructor(expressions: ConstMu
}
}

fun getSimplified(): Expression = SimpleExpression(toTerm())
override fun getSimplified(): Expression = SimpleExpression(toTerm())
override fun getValue(): BigDecimal = getSimplified().getValue()

override fun hashCode(): Int = createHashCode(listOf(expressions, "MultiplicativeExpression"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal class SimpleExpression(private val term: Term) : ExpressionImpl() {
override fun inverse(): Expression = SimpleExpression(term.inverse())

override fun toTerm(): Term = term
fun getSimplified(): Expression = getOrSet({ simplified }, { simplified = it }) { SimpleExpression(term.getSimplified()) }
override fun getSimplified(): Expression = getOrSet({ simplified }, { simplified = it }) { SimpleExpression(term.getSimplified()) }
override fun getValue(): BigDecimal = term.getValue()

override fun hashCode(): Int = createHashCode(listOf(term, "Expression"))
Expand Down

0 comments on commit 24095dd

Please sign in to comment.