ArrayList<QueryNode> nodes = new ArrayList<QueryNode>();
for(Object entryObj : map.entrySet()) {
Map.Entry entry = (Map.Entry) entryObj;
String key = (String)entry.getKey();
Object value = entry.getValue();
Bytes curPrefix = new CompoundBytes(prefix, sencodeMapKey(key));
curPrefix = new CompoundBytes(curPrefix, HEADER_BYTE_COLON);
QueryNodeTemplate templ = applyPatternToBagIndex(curPrefix, value, index, revNum);
nodes.add(templ.queryNode);
vars.putAll(templ.varMappings);
}
if (map.isEmpty()) {
queryNode = index.getRange(new Range(prefix, null, null, true, true), revNum);
} else {
queryNode = AndQueryNode.make(nodes);
}
} else if (pattern instanceof List) {
List list = (List)pattern;
if (list.size() > 0 && list.get(0) != null &&
list.get(0) instanceof String &&
SYMBOLS.contains(list.get(0).hashCode())) {
return applyQueryToBagIndex(prefix, list, index, revNum);
} else if (list.size() > 1) {
throw new ApiException("QueryFormatError", "malformed list structure in query: "+pattern);
} else {
prefix = new CompoundBytes(prefix, HEADER_BYTE_LISTOPEN);
if (list.isEmpty()) {
queryNode = index.getTerm(prefix, revNum);
} else {
QueryNodeTemplate templ = applyPatternToBagIndex(prefix, list.get(0), index, revNum);
queryNode = templ.queryNode;
vars.putAll(templ.varMappings);
}
}
} else {
Bytes matchingBytes = new CompoundBytes(prefix,sencode(pattern));
queryNode = index.getTerm(matchingBytes, revNum);
// System.out.println(matchingBytes.toString()+" -> "+queryNode+" in "+revNum);
}
return new QueryNodeTemplate(queryNode, vars);
}