}
public void apply(Bytes prefix, Bytes suffix, Object pattern) {
if (pattern instanceof Map) {
Map<String,Object> map = (Map<String,Object>)pattern;
handleMap(prefix, suffix, map);
prefix = new CompoundBytes(prefix, HEADER_BYTE_MAPOPEN);
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);
handleMapEntry(prefix, suffix, key, value);
apply(curPrefix, suffix, value);
}
} else if (pattern instanceof List) {
List<Object> list = (List<Object>)pattern;
if (list.size() > 0) {
Object first = list.get(0);
if (first != null && first instanceof String && isOperationLead((String)first)) {
handleOperation(prefix, suffix, (String)first, list);
}
} else if (list.size() > 1) {
throw new ApiException("QueryFormatError", "malformed list structure; only 1 element is allowed here: "+pattern);
} else {
prefix = new CompoundBytes(prefix, HEADER_BYTE_LISTOPEN);
handleList(prefix, suffix, list);
}
} else {
handleAtomic(prefix, suffix, pattern);
}