package androidx.room; import androidx.annotation.RestrictTo; import androidx.room.AmbiguousColumnResolver; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.NoSuchElementException; import java.util.Set; import kotlin.Unit; import kotlin.collections.CollectionsKt__CollectionsJVMKt; import kotlin.collections.CollectionsKt__CollectionsKt; import kotlin.collections.CollectionsKt__IterablesKt; import kotlin.collections.CollectionsKt__MutableCollectionsKt; import kotlin.collections.CollectionsKt___CollectionsKt; import kotlin.collections.IntIterator; import kotlin.collections.SetsKt__SetsJVMKt; import kotlin.jvm.functions.Function1; import kotlin.jvm.functions.Function3; import kotlin.jvm.internal.DefaultConstructorMarker; import kotlin.jvm.internal.Intrinsics; import kotlin.jvm.internal.Ref; import kotlin.jvm.internal.SourceDebugExtension; import kotlin.ranges.IntRange; @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP}) @SourceDebugExtension({"SMAP\nAmbiguousColumnResolver.kt\nKotlin\n*S Kotlin\n*F\n+ 1 AmbiguousColumnResolver.kt\nandroidx/room/AmbiguousColumnResolver\n+ 2 fake.kt\nkotlin/jvm/internal/FakeKt\n+ 3 _Arrays.kt\nkotlin/collections/ArraysKt___ArraysKt\n+ 4 _Collections.kt\nkotlin/collections/CollectionsKt___CollectionsKt\n+ 5 ArraysJVM.kt\nkotlin/collections/ArraysKt__ArraysJVMKt\n*L\n1#1,253:1\n1#2:254\n13579#3,2:255\n13644#3,3:257\n13644#3,2:260\n11335#3:262\n11670#3,2:263\n11672#3:267\n13646#3:268\n1855#4,2:265\n1726#4,3:269\n1549#4:272\n1620#4,3:273\n1855#4,2:278\n37#5,2:276\n*S KotlinDebug\n*F\n+ 1 AmbiguousColumnResolver.kt\nandroidx/room/AmbiguousColumnResolver\n*L\n85#1:255,2\n87#1:257,3\n96#1:260,2\n118#1:262\n118#1:263,2\n118#1:267\n96#1:268\n120#1:265,2\n141#1:269,3\n151#1:272\n151#1:273,3\n188#1:278,2\n151#1:276,2\n*E\n"}) /* loaded from: classes.dex */ public final class AmbiguousColumnResolver { public static final AmbiguousColumnResolver INSTANCE = new AmbiguousColumnResolver(); private AmbiguousColumnResolver() { } /* JADX WARN: Multi-variable type inference failed */ /* JADX WARN: Type inference failed for: r1v2, types: [T, androidx.room.AmbiguousColumnResolver$Solution] */ public static final int[][] resolve(String[] resultColumns, String[][] mappings) { Set createSetBuilder; Set build; List createListBuilder; List build2; int[] intArray; List createListBuilder2; List build3; Intrinsics.checkNotNullParameter(resultColumns, "resultColumns"); Intrinsics.checkNotNullParameter(mappings, "mappings"); int length = resultColumns.length; int i = 0; for (int i2 = 0; i2 < length; i2++) { String str = resultColumns[i2]; if (str.charAt(0) == '`' && str.charAt(str.length() - 1) == '`') { str = str.substring(1, str.length() - 1); Intrinsics.checkNotNullExpressionValue(str, "this as java.lang.String…ing(startIndex, endIndex)"); } Locale US = Locale.US; Intrinsics.checkNotNullExpressionValue(US, "US"); String lowerCase = str.toLowerCase(US); Intrinsics.checkNotNullExpressionValue(lowerCase, "this as java.lang.String).toLowerCase(locale)"); resultColumns[i2] = lowerCase; } int length2 = mappings.length; for (int i3 = 0; i3 < length2; i3++) { int length3 = mappings[i3].length; for (int i4 = 0; i4 < length3; i4++) { String[] strArr = mappings[i3]; String str2 = strArr[i4]; Locale US2 = Locale.US; Intrinsics.checkNotNullExpressionValue(US2, "US"); String lowerCase2 = str2.toLowerCase(US2); Intrinsics.checkNotNullExpressionValue(lowerCase2, "this as java.lang.String).toLowerCase(locale)"); strArr[i4] = lowerCase2; } } createSetBuilder = SetsKt__SetsJVMKt.createSetBuilder(); for (String[] strArr2 : mappings) { CollectionsKt__MutableCollectionsKt.addAll(createSetBuilder, strArr2); } build = SetsKt__SetsJVMKt.build(createSetBuilder); createListBuilder = CollectionsKt__CollectionsJVMKt.createListBuilder(); int length4 = resultColumns.length; int i5 = 0; int i6 = 0; while (i5 < length4) { String str3 = resultColumns[i5]; int i7 = i6 + 1; if (build.contains(str3)) { createListBuilder.add(new ResultColumn(str3, i6)); } i5++; i6 = i7; } build2 = CollectionsKt__CollectionsJVMKt.build(createListBuilder); int length5 = mappings.length; final ArrayList arrayList = new ArrayList(length5); for (int i8 = 0; i8 < length5; i8++) { arrayList.add(new ArrayList()); } int length6 = mappings.length; int i9 = 0; final int i10 = 0; while (i9 < length6) { final String[] strArr3 = mappings[i9]; int i11 = i10 + 1; INSTANCE.rabinKarpSearch(build2, strArr3, new Function3() { // from class: androidx.room.AmbiguousColumnResolver$resolve$1$1 /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ /* JADX WARN: Multi-variable type inference failed */ { super(3); } @Override // kotlin.jvm.functions.Function3 public /* bridge */ /* synthetic */ Object invoke(Object obj, Object obj2, Object obj3) { invoke(((Number) obj).intValue(), ((Number) obj2).intValue(), (List) obj3); return Unit.INSTANCE; } public final void invoke(int i12, int i13, List resultColumnsSublist) { Object obj; Intrinsics.checkNotNullParameter(resultColumnsSublist, "resultColumnsSublist"); String[] strArr4 = strArr3; ArrayList arrayList2 = new ArrayList(strArr4.length); for (String str4 : strArr4) { Iterator it = resultColumnsSublist.iterator(); while (true) { if (it.hasNext()) { obj = it.next(); if (Intrinsics.areEqual(str4, ((AmbiguousColumnResolver.ResultColumn) obj).component1())) { break; } } else { obj = null; break; } } AmbiguousColumnResolver.ResultColumn resultColumn = (AmbiguousColumnResolver.ResultColumn) obj; if (resultColumn == null) { return; } arrayList2.add(Integer.valueOf(resultColumn.getIndex())); } arrayList.get(i10).add(new AmbiguousColumnResolver.Match(new IntRange(i12, i13 - 1), arrayList2)); } }); if (((List) arrayList.get(i10)).isEmpty()) { ArrayList arrayList2 = new ArrayList(strArr3.length); int length7 = strArr3.length; for (int i12 = i; i12 < length7; i12++) { String str4 = strArr3[i12]; createListBuilder2 = CollectionsKt__CollectionsJVMKt.createListBuilder(); for (ResultColumn resultColumn : build2) { if (Intrinsics.areEqual(str4, resultColumn.getName())) { createListBuilder2.add(Integer.valueOf(resultColumn.getIndex())); } } build3 = CollectionsKt__CollectionsJVMKt.build(createListBuilder2); if (!(!build3.isEmpty())) { throw new IllegalStateException(("Column " + str4 + " not found in result").toString()); } arrayList2.add(build3); } dfs$default(INSTANCE, arrayList2, null, 0, new Function1() { // from class: androidx.room.AmbiguousColumnResolver$resolve$1$2 /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ /* JADX WARN: Multi-variable type inference failed */ { super(1); } @Override // kotlin.jvm.functions.Function1 public /* bridge */ /* synthetic */ Object invoke(Object obj) { invoke((List) obj); return Unit.INSTANCE; } public final void invoke(List indices) { Intrinsics.checkNotNullParameter(indices, "indices"); List list = indices; Iterator it = list.iterator(); if (!it.hasNext()) { throw new NoSuchElementException(); } int intValue = ((Number) it.next()).intValue(); while (it.hasNext()) { int intValue2 = ((Number) it.next()).intValue(); if (intValue > intValue2) { intValue = intValue2; } } Iterator it2 = list.iterator(); if (!it2.hasNext()) { throw new NoSuchElementException(); } int intValue3 = ((Number) it2.next()).intValue(); while (it2.hasNext()) { int intValue4 = ((Number) it2.next()).intValue(); if (intValue3 < intValue4) { intValue3 = intValue4; } } arrayList.get(i10).add(new AmbiguousColumnResolver.Match(new IntRange(intValue, intValue3), indices)); } }, 6, null); } i9++; i10 = i11; i = 0; } if (!arrayList.isEmpty()) { Iterator it = arrayList.iterator(); while (it.hasNext()) { if (!(!((List) it.next()).isEmpty())) { throw new IllegalStateException("Failed to find matches for all mappings".toString()); } } } final Ref.ObjectRef objectRef = new Ref.ObjectRef(); objectRef.element = Solution.Companion.getNO_SOLUTION(); dfs$default(INSTANCE, arrayList, null, 0, new Function1() { // from class: androidx.room.AmbiguousColumnResolver$resolve$4 /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ { super(1); } @Override // kotlin.jvm.functions.Function1 public /* bridge */ /* synthetic */ Object invoke(Object obj) { invoke((List) obj); return Unit.INSTANCE; } /* JADX WARN: Type inference failed for: r2v1, types: [T, androidx.room.AmbiguousColumnResolver$Solution] */ public final void invoke(List it2) { Intrinsics.checkNotNullParameter(it2, "it"); ?? build4 = AmbiguousColumnResolver.Solution.Companion.build(it2); if (build4.compareTo(objectRef.element) < 0) { objectRef.element = build4; } } }, 6, null); List matches = ((Solution) objectRef.element).getMatches(); ArrayList arrayList3 = new ArrayList(CollectionsKt__IterablesKt.collectionSizeOrDefault(matches, 10)); Iterator it2 = matches.iterator(); while (it2.hasNext()) { intArray = CollectionsKt___CollectionsKt.toIntArray(((Match) it2.next()).getResultIndices()); arrayList3.add(intArray); } return (int[][]) arrayList3.toArray(new int[0][]); } private final void rabinKarpSearch(List list, String[] strArr, Function3 function3) { int i = 0; int i2 = 0; for (String str : strArr) { i2 += str.hashCode(); } int length = strArr.length; Iterator it = list.subList(0, length).iterator(); int i3 = 0; while (it.hasNext()) { i3 += ((ResultColumn) it.next()).getName().hashCode(); } while (true) { if (i2 == i3) { function3.invoke(Integer.valueOf(i), Integer.valueOf(length), list.subList(i, length)); } int i4 = i + 1; int i5 = length + 1; if (i5 > list.size()) { return; } i3 = (i3 - list.get(i).getName().hashCode()) + list.get(length).getName().hashCode(); i = i4; length = i5; } } public static /* synthetic */ void dfs$default(AmbiguousColumnResolver ambiguousColumnResolver, List list, List list2, int i, Function1 function1, int i2, Object obj) { if ((i2 & 2) != 0) { list2 = new ArrayList(); } if ((i2 & 4) != 0) { i = 0; } ambiguousColumnResolver.dfs(list, list2, i, function1); } private final void dfs(List> list, List list2, int i, Function1 function1) { if (i == list.size()) { function1.invoke(CollectionsKt___CollectionsKt.toList(list2)); return; } Iterator it = list.get(i).iterator(); while (it.hasNext()) { list2.add(it.next()); INSTANCE.dfs(list, list2, i + 1, function1); CollectionsKt__MutableCollectionsKt.removeLast(list2); } } public static final class ResultColumn { private final int index; private final String name; public static /* synthetic */ ResultColumn copy$default(ResultColumn resultColumn, String str, int i, int i2, Object obj) { if ((i2 & 1) != 0) { str = resultColumn.name; } if ((i2 & 2) != 0) { i = resultColumn.index; } return resultColumn.copy(str, i); } public final String component1() { return this.name; } public final int component2() { return this.index; } public final ResultColumn copy(String name, int i) { Intrinsics.checkNotNullParameter(name, "name"); return new ResultColumn(name, i); } public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof ResultColumn)) { return false; } ResultColumn resultColumn = (ResultColumn) obj; return Intrinsics.areEqual(this.name, resultColumn.name) && this.index == resultColumn.index; } public final int getIndex() { return this.index; } public final String getName() { return this.name; } public int hashCode() { return (this.name.hashCode() * 31) + Integer.hashCode(this.index); } public String toString() { return "ResultColumn(name=" + this.name + ", index=" + this.index + ')'; } public ResultColumn(String name, int i) { Intrinsics.checkNotNullParameter(name, "name"); this.name = name; this.index = i; } } public static final class Match { private final List resultIndices; private final IntRange resultRange; public final List getResultIndices() { return this.resultIndices; } public final IntRange getResultRange() { return this.resultRange; } public Match(IntRange resultRange, List resultIndices) { Intrinsics.checkNotNullParameter(resultRange, "resultRange"); Intrinsics.checkNotNullParameter(resultIndices, "resultIndices"); this.resultRange = resultRange; this.resultIndices = resultIndices; } } public static final class Solution implements Comparable { public static final Companion Companion = new Companion(null); private static final Solution NO_SOLUTION = new Solution(CollectionsKt__CollectionsKt.emptyList(), Integer.MAX_VALUE, Integer.MAX_VALUE); private final int coverageOffset; private final List matches; private final int overlaps; public final int getCoverageOffset() { return this.coverageOffset; } public final List getMatches() { return this.matches; } public final int getOverlaps() { return this.overlaps; } public Solution(List matches, int i, int i2) { Intrinsics.checkNotNullParameter(matches, "matches"); this.matches = matches; this.coverageOffset = i; this.overlaps = i2; } @Override // java.lang.Comparable public int compareTo(Solution other) { Intrinsics.checkNotNullParameter(other, "other"); int compare = Intrinsics.compare(this.overlaps, other.overlaps); return compare != 0 ? compare : Intrinsics.compare(this.coverageOffset, other.coverageOffset); } @SourceDebugExtension({"SMAP\nAmbiguousColumnResolver.kt\nKotlin\n*S Kotlin\n*F\n+ 1 AmbiguousColumnResolver.kt\nandroidx/room/AmbiguousColumnResolver$Solution$Companion\n+ 2 fake.kt\nkotlin/jvm/internal/FakeKt\n+ 3 _Collections.kt\nkotlin/collections/CollectionsKt___CollectionsKt\n*L\n1#1,253:1\n1#2:254\n1774#3,3:255\n1855#3,2:258\n1777#3:260\n*S KotlinDebug\n*F\n+ 1 AmbiguousColumnResolver.kt\nandroidx/room/AmbiguousColumnResolver$Solution$Companion\n*L\n232#1:255,3\n234#1:258,2\n232#1:260\n*E\n"}) public static final class Companion { public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } private Companion() { } public final Solution getNO_SOLUTION() { return Solution.NO_SOLUTION; } public final Solution build(List matches) { Intrinsics.checkNotNullParameter(matches, "matches"); List list = matches; int i = 0; int i2 = 0; for (Match match : list) { i2 += ((match.getResultRange().getLast() - match.getResultRange().getFirst()) + 1) - match.getResultIndices().size(); } Iterator it = list.iterator(); if (!it.hasNext()) { throw new NoSuchElementException(); } int first = ((Match) it.next()).getResultRange().getFirst(); while (it.hasNext()) { int first2 = ((Match) it.next()).getResultRange().getFirst(); if (first > first2) { first = first2; } } Iterator it2 = list.iterator(); if (!it2.hasNext()) { throw new NoSuchElementException(); } int last = ((Match) it2.next()).getResultRange().getLast(); while (it2.hasNext()) { int last2 = ((Match) it2.next()).getResultRange().getLast(); if (last < last2) { last = last2; } } Iterable intRange = new IntRange(first, last); if (!(intRange instanceof Collection) || !((Collection) intRange).isEmpty()) { Iterator it3 = intRange.iterator(); int i3 = 0; while (it3.hasNext()) { int nextInt = ((IntIterator) it3).nextInt(); Iterator it4 = list.iterator(); int i4 = 0; while (true) { if (!it4.hasNext()) { break; } if (((Match) it4.next()).getResultRange().contains(nextInt)) { i4++; } if (i4 > 1) { i3++; if (i3 < 0) { CollectionsKt__CollectionsKt.throwCountOverflow(); } } } } i = i3; } return new Solution(matches, i2, i); } } } }