Skip to content

Commit

Permalink
Avoid multiple type castings (openhab#946)
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
  • Loading branch information
cweitkamp authored and wborn committed Jul 28, 2019
1 parent c95dfcb commit 95e0190
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,9 @@ public String format(String pattern) {

// The value could be an integer value. Try to convert to BigInteger in
// order to have access to more conversion formats.
BigDecimal bd = toBigDecimal();
try {
return String.format(formatPattern, toBigDecimal().toBigIntegerExact());
return String.format(formatPattern, bd.toBigIntegerExact());
} catch (ArithmeticException ae) {
// Could not convert to integer value without loss of
// information. Fall through to default behavior.
Expand All @@ -252,7 +253,7 @@ public String format(String pattern) {
// integer. Fall through to default behavior.
}

return String.format(formatPattern, toBigDecimal());
return String.format(formatPattern, bd);
}

@Override
Expand Down Expand Up @@ -314,7 +315,7 @@ public String toFullString() {
}
} else if (target == HSBType.class) {
return target.cast(new HSBType(DecimalType.ZERO, PercentType.ZERO,
new PercentType(this.toBigDecimal().multiply(HUNDRED))));
new PercentType(toBigDecimal().multiply(HUNDRED))));
} else if (target == PercentType.class) {
if (SmartHomeUnits.PERCENT.equals(getUnit())) {
return target.cast(new PercentType(toBigDecimal()));
Expand Down

0 comments on commit 95e0190

Please sign in to comment.