Skip to content

Commit

Permalink
remove redundant class
Browse files Browse the repository at this point in the history
  • Loading branch information
Peva Blanchard committed Jul 23, 2023
1 parent 2ce21fd commit a685a95
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 58 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,43 @@ data class FloatingPointRepresentation(
return FloatingPointRepresentation(isPositive, digits, positionalExponent, nbSignificantDigits)
}
}

override fun toString(): String {
return when (positionalExponent) {
in -2..-1 -> {
val hd = listOf(0).replicate(-positionalExponent - 1).flatten()
.joinToString("")
.let { "0.$it" }
val tl = digits.take(nbSignificantDigits - positionalExponent + 1)
.dropLastWhile { it == 0 }
.joinToString("")
val sign = if (isPositive) "" else "-"
"$sign$hd$tl"
}

in 0..2 -> {
val midpoint = min(positionalExponent + 1, nbSignificantDigits)
val hd = digits.subList(0, midpoint)
.joinToString("")
val tl = digits.subList(midpoint, nbSignificantDigits)
.dropLastWhile { it == 0 }
.joinToString("")
.let { if (it.isEmpty()) "" else ".$it" }
val sign = if (isPositive) "" else "-"
"$sign$hd$tl"
}

else -> {
val hd = digits.subList(0, 1)
.joinToString("")
val tl = digits.subList(1, nbSignificantDigits)
.dropLastWhile { it == 0 }
.joinToString("")
.let { if (it.isEmpty()) "" else ".$it" }
val sign = if (isPositive) "" else "-"
val e = "E$positionalExponent"
"$sign$hd$tl$e"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ch.kleis.lcaplugin.ui.toolwindow

import ch.kleis.lcaplugin.core.assessment.Inventory
import ch.kleis.lcaplugin.core.lang.value.MatrixColumnIndex
import ch.kleis.lcaplugin.core.matrix.ImpactFactorMatrix
import javax.swing.event.TableModelListener
import javax.swing.table.TableModel

Expand Down Expand Up @@ -59,15 +58,15 @@ class InventoryTableModel(

val quantity = inventory.supply.quantityOf(outputProduct)
if (columnIndex == 1) {
return DisplayedNumber(quantity.amount).toString()
return FloatingPointRepresentation.of(quantity.amount).toString()
}
if (columnIndex == 2) {
return "${quantity.unit.symbol}"
}

val inputProduct = sortedControllablePorts[columnIndex - 3]
val ratio = inventory.impactFactors.valueRatio(outputProduct, inputProduct).amount
return DisplayedNumber(quantity.amount * ratio).toString()
return FloatingPointRepresentation.of(quantity.amount * ratio).toString()
}

override fun setValueAt(aValue: Any?, rowIndex: Int, columnIndex: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class DisplayedNumberTest(
@Test
fun run() {
// when
val actual = DisplayedNumber(value).toString()
val actual = FloatingPointRepresentation.of(value).toString()

// then
assertEquals(expected, actual)
Expand Down

0 comments on commit a685a95

Please sign in to comment.