Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored IntegerDivider.java divide method #644

Open
wants to merge 1 commit into
base: uinverse
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,21 @@ public int divide(final int nFirstInteger, final int nSecondInteger) {
final double dbFirstNumber = IntToDoubleConverter.Convert(nFirstInteger);
final double dbSecondNumber = IntToDoubleConverter.Convert(nSecondInteger);
final double dbQuotient = dbFirstNumber / dbSecondNumber;
double dbRoundedQuotient = (double) Constants.INTEGER_ORIGIN_ZERO_VALUE;
if (this.firstIsSmallerThanSecondDoubleComparator.FirstIsSmallerThanSecond(dbQuotient,
(double) Constants.INTEGER_ORIGIN_ZERO_VALUE)) {
dbRoundedQuotient = Math.ceil(dbQuotient);
} else if (this.firstIsLargerThanSecondDoubleComparator.FirstIsLargerThanSecond(dbQuotient,
(double) Constants.INTEGER_ORIGIN_ZERO_VALUE)) {
dbRoundedQuotient = Math.floor(dbQuotient);
}
final double constantsIntegerOriginZeroValueAsDouble = IntToDoubleConverter.Convert(
Constants.INTEGER_ORIGIN_ZERO_VALUE
);
final boolean dbQuotientIsSmallerThanConstantIntegerOriginZeroValueAsDouble =
this.firstIsSmallerThanSecondDoubleComparator.FirstIsSmallerThanSecond(dbQuotient,
IntToDoubleConverter.Convert(Constants.INTEGER_ORIGIN_ZERO_VALUE));
final boolean dbQuotientIsLargerThanConstantIntegerOriginZeroValueAsDouble =
this.firstIsLargerThanSecondDoubleComparator.FirstIsLargerThanSecond(dbQuotient,
IntToDoubleConverter.Convert(Constant.INTEGER_ORIGIN_ZERO_VALUE));
//TODO: refactor to use ternary operator factory and classes
final double dbRoundedQuotient = dbQuotientIsSmallerThanConstantIntegerOriginZeroValueAsDouble ?
Math.ceil(constantsIntegerOriginZeroValueAsDouble) :
dbQuotientIsLargerThanConstantIntegerOriginZeroValueAsDouble ?
Math.floor(constantsIntegerOriginZeroValueAsDouble :
Constant.INTEGER_ORIGIN_ZERO_VALUE; //if neither smaller nor larger, it must be equal
final int nIntegerQuotient = DoubleToIntConverter.Convert(dbRoundedQuotient);
return nIntegerQuotient;
}
Expand Down