Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
This is the official Firebase Admin Java SDK. Build extraordinary native JVM apps in
minutes with Firebase. The Firebase platform can power your app’s backend, user
authentication, static hosting, and more.
/*
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.firebase.database.snapshot;
import com.google.firebase.database.collection.ImmutableSortedMap;
import com.google.firebase.database.collection.LLRBNode;
import com.google.firebase.database.core.Path;
import com.google.firebase.database.utilities.Utilities;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/** User: greg Date: 5/16/13 Time: 4:47 PM */
public class ChildrenNode implements Node {
public static final Comparator NAME_ONLY_COMPARATOR =
new Comparator() {
@Override
public int compare(ChildKey o1, ChildKey o2) {
return o1.compareTo(o2);
}
};
private final ImmutableSortedMap children;
private final Node priority;
private String lazyHash = null;
protected ChildrenNode() {
this.children = ImmutableSortedMap.Builder.emptyMap(NAME_ONLY_COMPARATOR);
this.priority = PriorityUtilities.NullPriority();
}
protected ChildrenNode(ImmutableSortedMap children, Node priority) {
if (children.isEmpty() && !priority.isEmpty()) {
throw new IllegalArgumentException("Can't create empty ChildrenNode with priority!");
}
this.priority = priority;
this.children = children;
}
private static void addIndentation(StringBuilder builder, int indentation) {
for (int i = 0; i < indentation; i++) {
builder.append(" ");
}
}
@Override
public boolean hasChild(ChildKey name) {
return !this.getImmediateChild(name).isEmpty();
}
@Override
public boolean isEmpty() {
return children.isEmpty();
}
@Override
public int getChildCount() {
return children.size();
}
@Override
public Object getValue() {
return getValue(false);
}
@Override
public Object getValue(boolean useExportFormat) {
if (isEmpty()) {
return null;
}
int numKeys = 0;
int maxKey = 0;
boolean allIntegerKeys = true;
Map result = new HashMap<>();
for (Map.Entry 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