what-the-bank/sources/com/google/firebase/firestore/model/DocumentKey.java

108 lines
3.4 KiB
Java

package com.google.firebase.firestore.model;
import com.google.firebase.database.collection.ImmutableSortedSet;
import com.google.firebase.firestore.util.Assert;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/* loaded from: classes2.dex */
public final class DocumentKey implements Comparable<DocumentKey> {
private static final Comparator<DocumentKey> COMPARATOR;
private static final ImmutableSortedSet<DocumentKey> EMPTY_KEY_SET;
private final ResourcePath path;
static {
Comparator<DocumentKey> comparator = new Comparator() { // from class: com.google.firebase.firestore.model.DocumentKey$$ExternalSyntheticLambda0
@Override // java.util.Comparator
public final int compare(Object obj, Object obj2) {
return ((DocumentKey) obj).compareTo((DocumentKey) obj2);
}
};
COMPARATOR = comparator;
EMPTY_KEY_SET = new ImmutableSortedSet<>(Collections.emptyList(), comparator);
}
public static DocumentKey empty() {
return fromSegments(Collections.emptyList());
}
public static DocumentKey fromName(String str) {
ResourcePath fromString = ResourcePath.fromString(str);
boolean z = false;
if (fromString.length() > 4 && fromString.getSegment(0).equals("projects") && fromString.getSegment(2).equals("databases") && fromString.getSegment(4).equals("documents")) {
z = true;
}
Assert.hardAssert(z, "Tried to parse an invalid key: %s", fromString);
return fromPath(fromString.popFirst(5));
}
public static DocumentKey fromPath(ResourcePath resourcePath) {
return new DocumentKey(resourcePath);
}
public static DocumentKey fromSegments(List<String> list) {
return new DocumentKey(ResourcePath.fromSegments(list));
}
public static boolean isDocumentKey(ResourcePath resourcePath) {
return resourcePath.length() % 2 == 0;
}
private DocumentKey(ResourcePath resourcePath) {
Assert.hardAssert(isDocumentKey(resourcePath), "Not a document key path: %s", resourcePath);
this.path = resourcePath;
}
public final String getCollectionGroup() {
return this.path.getSegment(r0.length() - 2);
}
public final ResourcePath getCollectionPath() {
return this.path.popLast();
}
public final String getDocumentId() {
return this.path.getLastSegment();
}
public final boolean hasCollectionId(String str) {
return this.path.length() >= 2 && this.path.segments.get(this.path.length() - 2).equals(str);
}
@Override // java.lang.Comparable
public final int compareTo(DocumentKey documentKey) {
return this.path.compareTo(documentKey.path);
}
public final boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
return this.path.equals(((DocumentKey) obj).path);
}
public final int hashCode() {
return this.path.hashCode();
}
public final String toString() {
return this.path.toString();
}
public final ResourcePath getPath() {
return this.path;
}
public static ImmutableSortedSet<DocumentKey> emptyKeySet() {
return EMPTY_KEY_SET;
}
public static Comparator<DocumentKey> comparator() {
return COMPARATOR;
}
}