Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #85 from Dmitry-Me/equalitycomparison

Comparison for equality was heavily duplicated.
  • Loading branch information...
commit 7a796ee50f000ca010a3656109e61111bcb5accd 2 parents dbd2994 + 9d51bcc
@joezeng joezeng authored
View
9 ...com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/math/arithmetics/IntegerDivider.java
@@ -1,7 +1,6 @@
package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.math.arithmetics;
-import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.comparators.integercomparator.ThreeWayIntegerComparator;
-import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.comparators.integercomparator.ThreeWayIntegerComparisonResult;
+import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.comparators.integercomparator.IntegerForEqualityComparator;
import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.comparators.doublecomparator.FirstIsSmallerThanSecondDoubleComparator;
import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.comparators.doublecomparator.FirstIsLargerThanSecondDoubleComparator;
import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.converters.primitivetypesconverters.DoubleToIntConverter;
@@ -12,9 +11,9 @@
public static final int INTEGER_DIVIDE_ZERO_VALUE = 0;
public static int divide(int nFirstInteger, int nSecondInteger){
- ThreeWayIntegerComparisonResult denominatorEqualsZeroResult =
- ThreeWayIntegerComparator.Compare(nSecondInteger, INTEGER_DIVIDE_ZERO_VALUE);
- if(denominatorEqualsZeroResult == ThreeWayIntegerComparisonResult.FirstEqualsSecond){
+ boolean denominatorEqualsZero =
+ IntegerForEqualityComparator.areTwoIntegersEqual(nSecondInteger, INTEGER_DIVIDE_ZERO_VALUE);
+ if (denominatorEqualsZero) {
throw new ArithmeticException("An attempt was made to divide by zero.");
}else{
double dbFirstNumber = IntToDoubleConverter.Convert(nFirstInteger);
View
11 ...ss/java/fizzbuzz/packagenamingpackage/impl/math/arithmetics/NumberIsMultipleOfAnotherNumberVerifier.java
@@ -1,14 +1,15 @@
package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.math.arithmetics;
-import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.comparators.integercomparator.ThreeWayIntegerComparisonResult;
-import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.comparators.integercomparator.ThreeWayIntegerComparator;
+import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.comparators.integercomparator.IntegerForEqualityComparator;
public class NumberIsMultipleOfAnotherNumberVerifier {
public static boolean numberIsMultipleOfAnotherNumber(int nFirstNumber, int nSecondNumber) {
try{
- ThreeWayIntegerComparisonResult validationResult =
- ThreeWayIntegerComparator.Compare((IntegerDivider.divide(nFirstNumber, nSecondNumber)) * nSecondNumber, nFirstNumber);
- if (validationResult == ThreeWayIntegerComparisonResult.FirstEqualsSecond) {
+ int nDivideFirstIntegerBySecondIntegerResult =
+ (IntegerDivider.divide(nFirstNumber, nSecondNumber));
+ int nMultiplyDivisionResultBySecondIntegerResult =
+ nDivideFirstIntegerBySecondIntegerResult * nSecondNumber;
+ if (IntegerForEqualityComparator.areTwoIntegersEqual(nMultiplyDivisionResultBySecondIntegerResult, nFirstNumber)) {
return true;
} else {
return false;
View
13 ...uzz/packagenamingpackage/impl/strategies/comparators/integercomparator/IntegerForEqualityComparator.java
@@ -0,0 +1,13 @@
+package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.comparators.integercomparator;
+
+public class IntegerForEqualityComparator {
+ public static boolean areTwoIntegersEqual(int nFirstInteger, int nSecondInteger) {
+ ThreeWayIntegerComparisonResult comparisonResult =
+ ThreeWayIntegerComparator.Compare(nFirstInteger, nSecondInteger);
+ if (comparisonResult == ThreeWayIntegerComparisonResult.FirstEqualsSecond) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.