private static boolean isBinaryOperation(FormulaNode node, FormulaFunction operator) { if(node instanceof FunctionCallNode) { FunctionCallNode callNode = (FunctionCallNode) node; return callNode.getArgumentCount() == 2 && callNode.getFunction() == operator; } return false; }
private boolean parseComparison(FormulaNode node, Multimap<Integer, FilterConfig> result) { if(!(node instanceof FunctionCallNode)) { return false; } // Check that this is a binary FunctionCallNode callNode = (FunctionCallNode) node; if(callNode.getArgumentCount() != 2) { return false; } // Does this comparison involve one of our fields? Integer columnIndex = findColumnIndex(callNode.getArgument(0)); if(columnIndex == null) { return false; } // Is it compared with a constant value? FieldValue value = parseLiteral(callNode.getArgument(1)); if(value == null) { return false; } FilterConfig config; if(value instanceof Quantity) { config = numericFilter(callNode, (Quantity) value); } else if(value instanceof LocalDate) { config = dateFilter(callNode, (LocalDate) value); } else { return false; } result.put(columnIndex, config); return true; }
return false; if(searchCall.getArgumentCount() != 2) { return false;
private static boolean filterContainsPartner(String filter, ResourceId partnerFormId, ResourceId partnerId) { FormulaNode filterFormula = FormulaParser.parse(filter); SymbolNode expectedPartnerForm = new SymbolNode(partnerFormId); ConstantNode expectedPartnerRecord = new ConstantNode(partnerId.asString()); if (!(filterFormula instanceof FunctionCallNode)) { return false; } if (!(((FunctionCallNode) filterFormula).getFunction() instanceof EqualFunction)) { return false; } if (((FunctionCallNode) filterFormula).getArgumentCount() != 2) { return false; } FunctionCallNode equalFunctionCall = (FunctionCallNode) filterFormula; if (!(equalFunctionCall.getArgument(0 ) instanceof SymbolNode)) { return false; } if (!(equalFunctionCall.getArgument(1) instanceof ConstantNode)) { return false; } SymbolNode partnerFormNode = (SymbolNode) equalFunctionCall.getArgument(0); ConstantNode partnerFieldNode = (ConstantNode) equalFunctionCall.getArgument(1); if (!partnerFormNode.equals(expectedPartnerForm)) { return false; } if (!partnerFieldNode.equals(expectedPartnerRecord)) { return false; } return true; }