- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
154 lines
6.4 KiB
Java
154 lines
6.4 KiB
Java
package androidx.room.util;
|
|
|
|
import android.database.Cursor;
|
|
import android.database.CursorWrapper;
|
|
import android.database.MatrixCursor;
|
|
import androidx.annotation.RestrictTo;
|
|
import androidx.annotation.VisibleForTesting;
|
|
import kotlin.collections.ArraysKt___ArraysKt;
|
|
import kotlin.io.CloseableKt;
|
|
import kotlin.jvm.functions.Function1;
|
|
import kotlin.jvm.internal.InlineMarker;
|
|
import kotlin.jvm.internal.Intrinsics;
|
|
import kotlin.jvm.internal.SourceDebugExtension;
|
|
import kotlin.text.StringsKt__StringsJVMKt;
|
|
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
@SourceDebugExtension({"SMAP\nCursorUtil.kt\nKotlin\n*S Kotlin\n*F\n+ 1 CursorUtil.kt\nandroidx/room/util/CursorUtil\n+ 2 _Arrays.kt\nkotlin/collections/ArraysKt___ArraysKt\n+ 3 fake.kt\nkotlin/jvm/internal/FakeKt\n*L\n1#1,184:1\n145#1,7:185\n13644#2,3:192\n1#3:195\n*S KotlinDebug\n*F\n+ 1 CursorUtil.kt\nandroidx/room/util/CursorUtil\n*L\n39#1:185,7\n127#1:192,3\n*E\n"})
|
|
/* loaded from: classes.dex */
|
|
public final class CursorUtil {
|
|
private static final int findColumnIndexBySuffix(Cursor cursor, String str) {
|
|
return -1;
|
|
}
|
|
|
|
public static final Cursor copyAndClose(Cursor c) {
|
|
Intrinsics.checkNotNullParameter(c, "c");
|
|
try {
|
|
MatrixCursor matrixCursor = new MatrixCursor(c.getColumnNames(), c.getCount());
|
|
while (c.moveToNext()) {
|
|
Object[] objArr = new Object[c.getColumnCount()];
|
|
int columnCount = c.getColumnCount();
|
|
for (int i = 0; i < columnCount; i++) {
|
|
int type = c.getType(i);
|
|
if (type == 0) {
|
|
objArr[i] = null;
|
|
} else if (type == 1) {
|
|
objArr[i] = Long.valueOf(c.getLong(i));
|
|
} else if (type == 2) {
|
|
objArr[i] = Double.valueOf(c.getDouble(i));
|
|
} else if (type == 3) {
|
|
objArr[i] = c.getString(i);
|
|
} else if (type == 4) {
|
|
objArr[i] = c.getBlob(i);
|
|
} else {
|
|
throw new IllegalStateException();
|
|
}
|
|
}
|
|
matrixCursor.addRow(objArr);
|
|
}
|
|
CloseableKt.closeFinally(c, null);
|
|
return matrixCursor;
|
|
} finally {
|
|
}
|
|
}
|
|
|
|
public static final int getColumnIndex(Cursor c, String name) {
|
|
Intrinsics.checkNotNullParameter(c, "c");
|
|
Intrinsics.checkNotNullParameter(name, "name");
|
|
int columnIndex = c.getColumnIndex(name);
|
|
if (columnIndex >= 0) {
|
|
return columnIndex;
|
|
}
|
|
int columnIndex2 = c.getColumnIndex('`' + name + '`');
|
|
return columnIndex2 >= 0 ? columnIndex2 : findColumnIndexBySuffix(c, name);
|
|
}
|
|
|
|
public static final int getColumnIndexOrThrow(Cursor c, String name) {
|
|
String str;
|
|
Intrinsics.checkNotNullParameter(c, "c");
|
|
Intrinsics.checkNotNullParameter(name, "name");
|
|
int columnIndex = getColumnIndex(c, name);
|
|
if (columnIndex >= 0) {
|
|
return columnIndex;
|
|
}
|
|
try {
|
|
String[] columnNames = c.getColumnNames();
|
|
Intrinsics.checkNotNullExpressionValue(columnNames, "c.columnNames");
|
|
str = ArraysKt___ArraysKt.joinToString$default(columnNames, (CharSequence) null, (CharSequence) null, (CharSequence) null, 0, (CharSequence) null, (Function1) null, 63, (Object) null);
|
|
} catch (Exception unused) {
|
|
str = "unknown";
|
|
}
|
|
throw new IllegalArgumentException("column '" + name + "' does not exist. Available columns: " + str);
|
|
}
|
|
|
|
@VisibleForTesting
|
|
public static final int findColumnIndexBySuffix(String[] columnNames, String name) {
|
|
Intrinsics.checkNotNullParameter(columnNames, "columnNames");
|
|
Intrinsics.checkNotNullParameter(name, "name");
|
|
String str = '.' + name;
|
|
String str2 = '.' + name + '`';
|
|
int length = columnNames.length;
|
|
int i = 0;
|
|
int i2 = 0;
|
|
while (i < length) {
|
|
String str3 = columnNames[i];
|
|
int i3 = i2 + 1;
|
|
if (str3.length() >= name.length() + 2) {
|
|
if (StringsKt__StringsJVMKt.endsWith$default(str3, str, false, 2, null)) {
|
|
return i2;
|
|
}
|
|
if (str3.charAt(0) == '`' && StringsKt__StringsJVMKt.endsWith$default(str3, str2, false, 2, null)) {
|
|
return i2;
|
|
}
|
|
}
|
|
i++;
|
|
i2 = i3;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
public static final <R> R useCursor(Cursor cursor, Function1 block) {
|
|
Intrinsics.checkNotNullParameter(cursor, "<this>");
|
|
Intrinsics.checkNotNullParameter(block, "block");
|
|
try {
|
|
R r = (R) block.invoke(cursor);
|
|
InlineMarker.finallyStart(1);
|
|
CloseableKt.closeFinally(cursor, null);
|
|
InlineMarker.finallyEnd(1);
|
|
return r;
|
|
} finally {
|
|
}
|
|
}
|
|
|
|
public static final Cursor wrapMappedColumns(final Cursor cursor, final String[] columnNames, final int[] mapping) {
|
|
Intrinsics.checkNotNullParameter(cursor, "cursor");
|
|
Intrinsics.checkNotNullParameter(columnNames, "columnNames");
|
|
Intrinsics.checkNotNullParameter(mapping, "mapping");
|
|
if (columnNames.length != mapping.length) {
|
|
throw new IllegalStateException("Expected columnNames.length == mapping.length".toString());
|
|
}
|
|
return new CursorWrapper(cursor) { // from class: androidx.room.util.CursorUtil$wrapMappedColumns$2
|
|
@Override // android.database.CursorWrapper, android.database.Cursor
|
|
public int getColumnIndex(String columnName) {
|
|
boolean equals;
|
|
Intrinsics.checkNotNullParameter(columnName, "columnName");
|
|
String[] strArr = columnNames;
|
|
int[] iArr = mapping;
|
|
int length = strArr.length;
|
|
int i = 0;
|
|
int i2 = 0;
|
|
while (i < length) {
|
|
int i3 = i2 + 1;
|
|
equals = StringsKt__StringsJVMKt.equals(strArr[i], columnName, true);
|
|
if (equals) {
|
|
return iArr[i2];
|
|
}
|
|
i++;
|
|
i2 = i3;
|
|
}
|
|
return super.getColumnIndex(columnName);
|
|
}
|
|
};
|
|
}
|
|
}
|