Created
December 18, 2019 10:52
-
-
Save kaspernielsen/463921e0326c87205dc1c37e2559fae6 to your computer and use it in GitHub Desktop.
Query Example
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 class FilterMapToDoubleSortedSum extends Processor { | |
public Object process(int[] arr, TerminalQueryOperationNode node) { | |
// Original Query: C_FILTER->C_MAP_TO_DOUBLE->C_SORTED_NATURAL->CT_MATH_SUM | |
// Simplified : C_FILTER->C_MAP_TO_DOUBLE->CT_MATH_SUM | |
// Extract all functions from a linked list of query objects | |
SI_MapToDouble on = (SI_MapToDouble) node.previous().previous(); | |
IntToDoubleFunction mapper = on.getMapper(); | |
IntPredicate intPredicate = ((SI_Filter) on.previous()).getIntPredicate(); | |
double sum = 0.0d; | |
for (int i = 0; i < arr.length; i++) { | |
int e = arr[i]; | |
if (intPredicate.test(e)) { | |
double mapped = mapper.applyAsDouble(e); | |
sum += mapped; | |
} | |
} | |
return Double.valueOf(sum); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment