Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Refactor: centralize type handling for simple operations such as add and subtract, and add branch coverage for this #167

Open
@akerfel

Description

@akerfel

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp