Source:
<code>private static QueryNode translateQuery(Map<String, Object> query, Map<String, Object> indexes, TranslatorState state) { ChildrenQueryNode root = null; List<Object> clauses = new ArrayList<Object>(); <START> if (query.keySet().toArray()[0].equals(AND)) { <END> clauses = (ArrayList<Object>) query.get(AND); root = new AndQueryNode(); } else if (query.keySet().toArray()[0].equals(OR)) { clauses = (ArrayList<Object>) query.get(OR); root = new OrQueryNode(); } List<Object> basicClauses = new ArrayList<Object>(); for (Object rawClause: clauses) { Map<String, Object> clause = (Map<String, Object>) rawClause; String field = (String) clause.keySet().toArray()[0]; if (!field.startsWith("$")) { basicClauses.add(rawClause); } } if (query.keySet().toArray()[0].equals(AND)) { String chosenIndex = chooseIndexForAndClause(basicClauses, indexes); if (chosenIndex == null || chosenIndex.isEmpty()) { state.atLeastOneIndexMissing = true; String msg = String.format("No single index contains all of %s; %s", basicClauses.toString(), "add index for these fields to query efficiently."); logger.log(Level.WARNING, msg); } else { state.atLeastOneIndexUsed = true; String select = selectStatementForAndClause(basicClauses, chosenIndex); if (select == null || select.isEmpty()) { String msg = String.format("Error generating SELECT clause for %s", basicClauses); logger.log(Level.SEVERE, msg); return null; } SqlQueryNode sqlNode = new SqlQueryNode(); sqlNode.sql = select; if (root != null) { root.children.add(sqlNode); } } } else if (query.keySet().toArray()[0].equals(OR)) { } return root; }</code><technical_language>fact Map.get(blah) returns null for key present, [objc code](<LINK_0> elsewhere? containsKey</technical_language>

Target:
private static QueryNode translateQuery(Map<String, Object> query, Map<String, Object> indexes, TranslatorState state) { ChildrenQueryNode root = null; List<Object> clauses = new ArrayList<Object>(); if (query.get(AND) != null) { clauses = (ArrayList<Object>) query.get(AND); root = new AndQueryNode(); } else if (query.get(OR) != null) { clauses = (ArrayList<Object>) query.get(OR); root = new OrQueryNode(); } List<Object> basicClauses = new ArrayList<Object>(); for (Object rawClause: clauses) { Map<String, Object> clause = (Map<String, Object>) rawClause; String field = (String) clause.keySet().toArray()[0]; if (!field.startsWith("$")) { basicClauses.add(rawClause); } } if (query.get(AND) != null) { String chosenIndex = chooseIndexForAndClause(basicClauses, indexes); if (chosenIndex == null || chosenIndex.isEmpty()) { state.atLeastOneIndexMissing = true; String msg = String.format("No single index contains all of %s; %s", basicClauses.toString(), "add index for these fields to query efficiently."); logger.log(Level.WARNING, msg); } else { state.atLeastOneIndexUsed = true; SqlParts select = selectStatementForAndClause(basicClauses, chosenIndex); if (select == null) { String msg = String.format("Error generating SELECT clause for %s", basicClauses); logger.log(Level.SEVERE, msg); return null; } SqlQueryNode sqlNode = new SqlQueryNode(); sqlNode.sql = select; if (root != null) { root.children.add(sqlNode); } } } else if (query.get(OR) != null) { } return root; }