- Notifications
You must be signed in to change notification settings - Fork1.9k
Open
Description
In the files FenwickTree.java, Matrix.java and SegmentTree.java (all in the folder\src\com\jwetherell\algorithms\data_structures), there are comments sayingTODO: This is ugly and how to handle number overflow?. See example below.
These functions do the same things, therefore some refactoring could decrease code repetition. Specifically, a class could be created which holds functions for adding, subtracting, multiplying and comparing the different types BigDecimal, BigInteger, Long, Double, Float and Integer.
Furthermore, there seems to be no branch coverage for using these different types, since all tests just use Integers. Tests for the different types should be added.
/* TODO: This is ugly and how to handle number overflow? */if (this.suminstanceofBigDecimal ||data.suminstanceofBigDecimal) {BigDecimalresult = ((BigDecimal)this.sum).subtract((BigDecimal)data.sum);this.sum = (N)result;}elseif (this.suminstanceofBigInteger ||data.suminstanceofBigInteger) {BigIntegerresult = ((BigInteger)this.sum).subtract((BigInteger)data.sum);this.sum = (N)result;}elseif (this.suminstanceofLong ||data.suminstanceofLong) {Longresult = (this.sum.longValue() -data.sum.longValue());this.sum = (N)result;}elseif (this.suminstanceofDouble ||data.suminstanceofDouble) {Doubleresult = (this.sum.doubleValue() -data.sum.doubleValue());this.sum = (N)result;}elseif (this.suminstanceofFloat ||data.suminstanceofFloat) {Floatresult = (this.sum.floatValue() -data.sum.floatValue());this.sum = (N)result;}else {// IntegerIntegerresult = (this.sum.intValue() -data.sum.intValue());this.sum = (N)result;}
Metadata
Metadata
Assignees
Labels
No labels