Last active
August 14, 2016 12:49
-
-
Save afcastano/59ea31314f583a40a3a929eb25147417 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract Result<Integer> readIntFromFile(String file); | |
public Result<Integer> adjustValue(Integer value) { | |
if (value > 5) { | |
Result.error("Value " + value + " should no be greater than 5"); | |
} | |
return Result.ok(5 - value); | |
} | |
public Double calculateAverage(Integer val1, Integer val2) { | |
return (val1 + val2)/2d; | |
} | |
/** | |
* Read ints from two files, Adjust the first one and then calculate average. | |
* Returns a Result wrapping the positive outcome or any error. | |
*/ | |
public Result<Double> businessOperation(String fileName, String fileName2) { | |
Result<Integer> val1 = readIntFromFile(fileName); | |
if (val1.isError()) { | |
return Result.error(val1.getError()); | |
} | |
Result<Integer> adjusted1 = adjustValue(val1.getValue()); | |
if (adjusted1.isError()) { | |
return Result.error(adjusted1.getError()); | |
} | |
Result<Integer> val2 = readIntFromFile(fileName2); | |
if (val2.isError()) { | |
return Result.error(val2.getError()); | |
} | |
Double average = calculateAverage(adjusted1.getValue(), val2.getValue()); | |
return Result.ok(average); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment