Created
April 16, 2017 14:07
-
-
Save john77eipe/342ca8eee12e961edca9d25a406c6089 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
//Vendor code | |
static class IntegerAddition implements BinaryOperator<Integer> { | |
static private IntegerAddition instance = new IntegerAddition() ; | |
private IntegerAddition() {} | |
@Override | |
public Integer apply(Integer t, Integer u) { | |
return t + u; | |
} | |
public static IntegerAddition instance() { | |
return instance; | |
} | |
} | |
public static <T extends Number> Optional<T> sum(List<T> list, Predicate<T> condition, BinaryOperator<T> operation){ | |
return list.parallelStream() | |
.filter(condition) | |
.map(i -> i) | |
.reduce(operation); | |
} | |
//client | |
int result = MathUtility.sum(listOfInts, i->i<4, MathUtility.IntegerAddition.instance()).get(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment