in src/main/java/com/google/firebase/database/snapshot/ChildrenNode.java [88:133]
public Object getValue(boolean useExportFormat) {
if (isEmpty()) {
return null;
}
int numKeys = 0;
int maxKey = 0;
boolean allIntegerKeys = true;
Map<String, Object> result = new HashMap<>();
for (Map.Entry<ChildKey, Node> entry : children) {
String key = entry.getKey().asString();
result.put(key, entry.getValue().getValue(useExportFormat));
numKeys++;
// If we already found a string key, don't bother with any of this
if (allIntegerKeys) {
if (key.length() > 1 && key.charAt(0) == '0') {
allIntegerKeys = false;
} else {
Integer keyAsInt = Utilities.tryParseInt(key);
if (keyAsInt != null && keyAsInt >= 0) {
if (keyAsInt > maxKey) {
maxKey = keyAsInt;
}
} else {
allIntegerKeys = false;
}
}
}
}
if (!useExportFormat && allIntegerKeys && maxKey < 2 * numKeys) {
// convert to an array
List<Object> arrayResult = new ArrayList<>(maxKey + 1);
for (int i = 0; i <= maxKey; ++i) {
// Map.get will return null for non-existent values, so we don't have to worry about
// filling them in manually
arrayResult.add(result.get("" + i));
}
return arrayResult;
} else {
if (useExportFormat && !priority.isEmpty()) {
result.put(".priority", priority.getValue());
}
return result;
}
}