mirror of
https://github.com/Pinball3D/Rabbit-R1.git
synced 2024-12-26 09:02:34 -06:00
153 lines
7.8 KiB
Java
153 lines
7.8 KiB
Java
package androidx.room.util;
|
|
|
|
import android.database.Cursor;
|
|
import android.database.CursorWrapper;
|
|
import android.database.MatrixCursor;
|
|
import android.util.Log;
|
|
import kotlin.Metadata;
|
|
import kotlin.collections.ArraysKt;
|
|
import kotlin.io.CloseableKt;
|
|
import kotlin.jvm.functions.Function1;
|
|
import kotlin.jvm.internal.InlineMarker;
|
|
import kotlin.jvm.internal.Intrinsics;
|
|
import kotlin.text.StringsKt;
|
|
|
|
/* compiled from: CursorUtil.kt */
|
|
@Metadata(d1 = {"\u00000\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\b\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0000\n\u0002\u0010\u0011\n\u0002\b\u0005\n\u0002\u0010\u0015\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u0002\u001a\u000e\u0010\u0000\u001a\u00020\u00012\u0006\u0010\u0002\u001a\u00020\u0001\u001a\u0018\u0010\u0003\u001a\u00020\u00042\u0006\u0010\u0005\u001a\u00020\u00012\u0006\u0010\u0006\u001a\u00020\u0007H\u0002\u001a#\u0010\u0003\u001a\u00020\u00042\f\u0010\b\u001a\b\u0012\u0004\u0012\u00020\u00070\t2\u0006\u0010\u0006\u001a\u00020\u0007H\u0007¢\u0006\u0002\u0010\n\u001a\u0016\u0010\u000b\u001a\u00020\u00042\u0006\u0010\u0002\u001a\u00020\u00012\u0006\u0010\u0006\u001a\u00020\u0007\u001a\u0016\u0010\f\u001a\u00020\u00042\u0006\u0010\u0002\u001a\u00020\u00012\u0006\u0010\u0006\u001a\u00020\u0007\u001a)\u0010\r\u001a\u00020\u00012\u0006\u0010\u0005\u001a\u00020\u00012\f\u0010\b\u001a\b\u0012\u0004\u0012\u00020\u00070\t2\u0006\u0010\u000e\u001a\u00020\u000f¢\u0006\u0002\u0010\u0010\u001a/\u0010\u0011\u001a\u0002H\u0012\"\u0004\b\u0000\u0010\u0012*\u00020\u00012\u0012\u0010\u0013\u001a\u000e\u0012\u0004\u0012\u00020\u0001\u0012\u0004\u0012\u0002H\u00120\u0014H\u0086\bø\u0001\u0000¢\u0006\u0002\u0010\u0015\u0082\u0002\u0007\n\u0005\b\u009920\u0001¨\u0006\u0016"}, d2 = {"copyAndClose", "Landroid/database/Cursor;", "c", "findColumnIndexBySuffix", "", "cursor", "name", "", "columnNames", "", "([Ljava/lang/String;Ljava/lang/String;)I", "getColumnIndex", "getColumnIndexOrThrow", "wrapMappedColumns", "mapping", "", "(Landroid/database/Cursor;[Ljava/lang/String;[I)Landroid/database/Cursor;", "useCursor", "R", "block", "Lkotlin/Function1;", "(Landroid/database/Cursor;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;", "room-runtime_release"}, k = 2, mv = {1, 7, 1}, xi = 48)
|
|
/* loaded from: classes2.dex */
|
|
public final class CursorUtil {
|
|
private static final int findColumnIndexBySuffix(Cursor cursor, String str) {
|
|
return -1;
|
|
}
|
|
|
|
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.joinToString$default(columnNames, (CharSequence) null, (CharSequence) null, (CharSequence) null, 0, (CharSequence) null, (Function1) null, 63, (Object) null);
|
|
} catch (Exception e) {
|
|
Log.d("RoomCursorUtil", "Cannot collect column names for debug purposes", e);
|
|
str = "unknown";
|
|
}
|
|
throw new IllegalArgumentException("column '" + name + "' does not exist. Available columns: " + str);
|
|
}
|
|
|
|
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.endsWith$default(str3, str, false, 2, (Object) null)) {
|
|
return i2;
|
|
}
|
|
if (str3.charAt(0) == '`' && StringsKt.endsWith$default(str3, str2, false, 2, (Object) null)) {
|
|
return i2;
|
|
}
|
|
}
|
|
i++;
|
|
i2 = i3;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
public static final <R> R useCursor(Cursor cursor, Function1<? super Cursor, ? extends R> block) {
|
|
Intrinsics.checkNotNullParameter(cursor, "<this>");
|
|
Intrinsics.checkNotNullParameter(block, "block");
|
|
Cursor cursor2 = cursor;
|
|
try {
|
|
R invoke = block.invoke(cursor2);
|
|
InlineMarker.finallyStart(1);
|
|
CloseableKt.closeFinally(cursor2, null);
|
|
InlineMarker.finallyEnd(1);
|
|
return invoke;
|
|
} 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) {
|
|
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;
|
|
if (StringsKt.equals(strArr[i], columnName, true)) {
|
|
return iArr[i2];
|
|
}
|
|
i++;
|
|
i2 = i3;
|
|
}
|
|
return super.getColumnIndex(columnName);
|
|
}
|
|
};
|
|
}
|
|
|
|
public static final Cursor copyAndClose(Cursor c) {
|
|
Intrinsics.checkNotNullParameter(c, "c");
|
|
Cursor cursor = c;
|
|
try {
|
|
Cursor cursor2 = cursor;
|
|
MatrixCursor matrixCursor = new MatrixCursor(cursor2.getColumnNames(), cursor2.getCount());
|
|
while (cursor2.moveToNext()) {
|
|
Object[] objArr = new Object[cursor2.getColumnCount()];
|
|
int columnCount = c.getColumnCount();
|
|
for (int i = 0; i < columnCount; i++) {
|
|
int type = cursor2.getType(i);
|
|
if (type == 0) {
|
|
objArr[i] = null;
|
|
} else if (type == 1) {
|
|
objArr[i] = Long.valueOf(cursor2.getLong(i));
|
|
} else if (type == 2) {
|
|
objArr[i] = Double.valueOf(cursor2.getDouble(i));
|
|
} else if (type == 3) {
|
|
objArr[i] = cursor2.getString(i);
|
|
} else if (type == 4) {
|
|
objArr[i] = cursor2.getBlob(i);
|
|
} else {
|
|
throw new IllegalStateException();
|
|
}
|
|
}
|
|
matrixCursor.addRow(objArr);
|
|
}
|
|
CloseableKt.closeFinally(cursor, null);
|
|
return matrixCursor;
|
|
} finally {
|
|
}
|
|
}
|
|
}
|