385 lines
12 KiB
Java
385 lines
12 KiB
Java
|
package com.google.common.primitives;
|
||
|
|
||
|
import com.google.common.base.Preconditions;
|
||
|
import java.io.Serializable;
|
||
|
import java.util.AbstractList;
|
||
|
import java.util.Arrays;
|
||
|
import java.util.Collection;
|
||
|
import java.util.Collections;
|
||
|
import java.util.Comparator;
|
||
|
import java.util.List;
|
||
|
import java.util.RandomAccess;
|
||
|
|
||
|
/* loaded from: classes2.dex */
|
||
|
public final class Booleans {
|
||
|
public static int compare(boolean z, boolean z2) {
|
||
|
if (z == z2) {
|
||
|
return 0;
|
||
|
}
|
||
|
return z ? 1 : -1;
|
||
|
}
|
||
|
|
||
|
public static int hashCode(boolean z) {
|
||
|
return z ? 1231 : 1237;
|
||
|
}
|
||
|
|
||
|
private Booleans() {
|
||
|
}
|
||
|
|
||
|
/* loaded from: classes2.dex */
|
||
|
enum BooleanComparator implements Comparator<Boolean> {
|
||
|
TRUE_FIRST(1, "Booleans.trueFirst()"),
|
||
|
FALSE_FIRST(-1, "Booleans.falseFirst()");
|
||
|
|
||
|
private final String toString;
|
||
|
private final int trueValue;
|
||
|
|
||
|
BooleanComparator(int i, String str) {
|
||
|
this.trueValue = i;
|
||
|
this.toString = str;
|
||
|
}
|
||
|
|
||
|
@Override // java.util.Comparator
|
||
|
public final int compare(Boolean bool, Boolean bool2) {
|
||
|
return (bool2.booleanValue() ? this.trueValue : 0) - (bool.booleanValue() ? this.trueValue : 0);
|
||
|
}
|
||
|
|
||
|
@Override // java.lang.Enum
|
||
|
public final String toString() {
|
||
|
return this.toString;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static Comparator<Boolean> trueFirst() {
|
||
|
return BooleanComparator.TRUE_FIRST;
|
||
|
}
|
||
|
|
||
|
public static Comparator<Boolean> falseFirst() {
|
||
|
return BooleanComparator.FALSE_FIRST;
|
||
|
}
|
||
|
|
||
|
public static boolean contains(boolean[] zArr, boolean z) {
|
||
|
for (boolean z2 : zArr) {
|
||
|
if (z2 == z) {
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
public static int indexOf(boolean[] zArr, boolean z) {
|
||
|
return indexOf(zArr, z, 0, zArr.length);
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: private */
|
||
|
public static int indexOf(boolean[] zArr, boolean z, int i, int i2) {
|
||
|
while (i < i2) {
|
||
|
if (zArr[i] == z) {
|
||
|
return i;
|
||
|
}
|
||
|
i++;
|
||
|
}
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
/* JADX WARN: Code restructure failed: missing block: B:15:0x0023, code lost:
|
||
|
|
||
|
r0 = r0 + 1;
|
||
|
*/
|
||
|
/*
|
||
|
Code decompiled incorrectly, please refer to instructions dump.
|
||
|
To view partially-correct add '--show-bad-code' argument
|
||
|
*/
|
||
|
public static int indexOf(boolean[] r5, boolean[] r6) {
|
||
|
/*
|
||
|
java.lang.String r0 = "array"
|
||
|
com.google.common.base.Preconditions.checkNotNull(r5, r0)
|
||
|
java.lang.String r0 = "target"
|
||
|
com.google.common.base.Preconditions.checkNotNull(r6, r0)
|
||
|
int r0 = r6.length
|
||
|
r1 = 0
|
||
|
if (r0 != 0) goto Lf
|
||
|
return r1
|
||
|
Lf:
|
||
|
r0 = r1
|
||
|
L10:
|
||
|
int r2 = r5.length
|
||
|
int r3 = r6.length
|
||
|
int r2 = r2 - r3
|
||
|
int r2 = r2 + 1
|
||
|
if (r0 >= r2) goto L2a
|
||
|
r2 = r1
|
||
|
L18:
|
||
|
int r3 = r6.length
|
||
|
if (r2 >= r3) goto L29
|
||
|
int r3 = r0 + r2
|
||
|
boolean r3 = r5[r3]
|
||
|
boolean r4 = r6[r2]
|
||
|
if (r3 == r4) goto L26
|
||
|
int r0 = r0 + 1
|
||
|
goto L10
|
||
|
L26:
|
||
|
int r2 = r2 + 1
|
||
|
goto L18
|
||
|
L29:
|
||
|
return r0
|
||
|
L2a:
|
||
|
r5 = -1
|
||
|
return r5
|
||
|
*/
|
||
|
throw new UnsupportedOperationException("Method not decompiled: com.google.common.primitives.Booleans.indexOf(boolean[], boolean[]):int");
|
||
|
}
|
||
|
|
||
|
public static int lastIndexOf(boolean[] zArr, boolean z) {
|
||
|
return lastIndexOf(zArr, z, 0, zArr.length);
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: private */
|
||
|
public static int lastIndexOf(boolean[] zArr, boolean z, int i, int i2) {
|
||
|
for (int i3 = i2 - 1; i3 >= i; i3--) {
|
||
|
if (zArr[i3] == z) {
|
||
|
return i3;
|
||
|
}
|
||
|
}
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
public static boolean[] concat(boolean[]... zArr) {
|
||
|
int i = 0;
|
||
|
for (boolean[] zArr2 : zArr) {
|
||
|
i += zArr2.length;
|
||
|
}
|
||
|
boolean[] zArr3 = new boolean[i];
|
||
|
int i2 = 0;
|
||
|
for (boolean[] zArr4 : zArr) {
|
||
|
System.arraycopy(zArr4, 0, zArr3, i2, zArr4.length);
|
||
|
i2 += zArr4.length;
|
||
|
}
|
||
|
return zArr3;
|
||
|
}
|
||
|
|
||
|
public static boolean[] ensureCapacity(boolean[] zArr, int i, int i2) {
|
||
|
Preconditions.checkArgument(i >= 0, "Invalid minLength: %s", i);
|
||
|
Preconditions.checkArgument(i2 >= 0, "Invalid padding: %s", i2);
|
||
|
return zArr.length < i ? Arrays.copyOf(zArr, i + i2) : zArr;
|
||
|
}
|
||
|
|
||
|
public static String join(String str, boolean... zArr) {
|
||
|
Preconditions.checkNotNull(str);
|
||
|
if (zArr.length == 0) {
|
||
|
return "";
|
||
|
}
|
||
|
StringBuilder sb = new StringBuilder(zArr.length * 7);
|
||
|
sb.append(zArr[0]);
|
||
|
for (int i = 1; i < zArr.length; i++) {
|
||
|
sb.append(str);
|
||
|
sb.append(zArr[i]);
|
||
|
}
|
||
|
return sb.toString();
|
||
|
}
|
||
|
|
||
|
public static Comparator<boolean[]> lexicographicalComparator() {
|
||
|
return LexicographicalComparator.INSTANCE;
|
||
|
}
|
||
|
|
||
|
/* loaded from: classes2.dex */
|
||
|
enum LexicographicalComparator implements Comparator<boolean[]> {
|
||
|
INSTANCE;
|
||
|
|
||
|
@Override // java.util.Comparator
|
||
|
public final int compare(boolean[] zArr, boolean[] zArr2) {
|
||
|
int min = Math.min(zArr.length, zArr2.length);
|
||
|
for (int i = 0; i < min; i++) {
|
||
|
int compare = Booleans.compare(zArr[i], zArr2[i]);
|
||
|
if (compare != 0) {
|
||
|
return compare;
|
||
|
}
|
||
|
}
|
||
|
return zArr.length - zArr2.length;
|
||
|
}
|
||
|
|
||
|
@Override // java.lang.Enum
|
||
|
public final String toString() {
|
||
|
return "Booleans.lexicographicalComparator()";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static boolean[] toArray(Collection<Boolean> collection) {
|
||
|
if (collection instanceof BooleanArrayAsList) {
|
||
|
return ((BooleanArrayAsList) collection).toBooleanArray();
|
||
|
}
|
||
|
Object[] array = collection.toArray();
|
||
|
int length = array.length;
|
||
|
boolean[] zArr = new boolean[length];
|
||
|
for (int i = 0; i < length; i++) {
|
||
|
zArr[i] = ((Boolean) Preconditions.checkNotNull(array[i])).booleanValue();
|
||
|
}
|
||
|
return zArr;
|
||
|
}
|
||
|
|
||
|
public static List<Boolean> asList(boolean... zArr) {
|
||
|
if (zArr.length == 0) {
|
||
|
return Collections.emptyList();
|
||
|
}
|
||
|
return new BooleanArrayAsList(zArr);
|
||
|
}
|
||
|
|
||
|
/* loaded from: classes2.dex */
|
||
|
static class BooleanArrayAsList extends AbstractList<Boolean> implements RandomAccess, Serializable {
|
||
|
private static final long serialVersionUID = 0;
|
||
|
final boolean[] array;
|
||
|
final int end;
|
||
|
final int start;
|
||
|
|
||
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.List
|
||
|
public boolean isEmpty() {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
BooleanArrayAsList(boolean[] zArr) {
|
||
|
this(zArr, 0, zArr.length);
|
||
|
}
|
||
|
|
||
|
BooleanArrayAsList(boolean[] zArr, int i, int i2) {
|
||
|
this.array = zArr;
|
||
|
this.start = i;
|
||
|
this.end = i2;
|
||
|
}
|
||
|
|
||
|
@Override // java.util.AbstractList, java.util.List
|
||
|
public Boolean get(int i) {
|
||
|
Preconditions.checkElementIndex(i, size());
|
||
|
return Boolean.valueOf(this.array[this.start + i]);
|
||
|
}
|
||
|
|
||
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.List
|
||
|
public boolean contains(Object obj) {
|
||
|
return (obj instanceof Boolean) && Booleans.indexOf(this.array, ((Boolean) obj).booleanValue(), this.start, this.end) != -1;
|
||
|
}
|
||
|
|
||
|
@Override // java.util.AbstractList, java.util.List
|
||
|
public int indexOf(Object obj) {
|
||
|
int indexOf;
|
||
|
if (!(obj instanceof Boolean) || (indexOf = Booleans.indexOf(this.array, ((Boolean) obj).booleanValue(), this.start, this.end)) < 0) {
|
||
|
return -1;
|
||
|
}
|
||
|
return indexOf - this.start;
|
||
|
}
|
||
|
|
||
|
@Override // java.util.AbstractList, java.util.List
|
||
|
public int lastIndexOf(Object obj) {
|
||
|
int lastIndexOf;
|
||
|
if (!(obj instanceof Boolean) || (lastIndexOf = Booleans.lastIndexOf(this.array, ((Boolean) obj).booleanValue(), this.start, this.end)) < 0) {
|
||
|
return -1;
|
||
|
}
|
||
|
return lastIndexOf - this.start;
|
||
|
}
|
||
|
|
||
|
@Override // java.util.AbstractList, java.util.List
|
||
|
public Boolean set(int i, Boolean bool) {
|
||
|
Preconditions.checkElementIndex(i, size());
|
||
|
boolean[] zArr = this.array;
|
||
|
int i2 = this.start + i;
|
||
|
boolean z = zArr[i2];
|
||
|
zArr[i2] = ((Boolean) Preconditions.checkNotNull(bool)).booleanValue();
|
||
|
return Boolean.valueOf(z);
|
||
|
}
|
||
|
|
||
|
@Override // java.util.AbstractList, java.util.List
|
||
|
public List<Boolean> subList(int i, int i2) {
|
||
|
Preconditions.checkPositionIndexes(i, i2, size());
|
||
|
if (i == i2) {
|
||
|
return Collections.emptyList();
|
||
|
}
|
||
|
boolean[] zArr = this.array;
|
||
|
int i3 = this.start;
|
||
|
return new BooleanArrayAsList(zArr, i + i3, i3 + i2);
|
||
|
}
|
||
|
|
||
|
@Override // java.util.AbstractList, java.util.Collection, java.util.List
|
||
|
public boolean equals(Object obj) {
|
||
|
if (obj == this) {
|
||
|
return true;
|
||
|
}
|
||
|
if (obj instanceof BooleanArrayAsList) {
|
||
|
BooleanArrayAsList booleanArrayAsList = (BooleanArrayAsList) obj;
|
||
|
int size = size();
|
||
|
if (booleanArrayAsList.size() != size) {
|
||
|
return false;
|
||
|
}
|
||
|
for (int i = 0; i < size; i++) {
|
||
|
if (this.array[this.start + i] != booleanArrayAsList.array[booleanArrayAsList.start + i]) {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
return super.equals(obj);
|
||
|
}
|
||
|
|
||
|
@Override // java.util.AbstractList, java.util.Collection, java.util.List
|
||
|
public int hashCode() {
|
||
|
int i = 1;
|
||
|
for (int i2 = this.start; i2 < this.end; i2++) {
|
||
|
i = (i * 31) + Booleans.hashCode(this.array[i2]);
|
||
|
}
|
||
|
return i;
|
||
|
}
|
||
|
|
||
|
@Override // java.util.AbstractCollection
|
||
|
public String toString() {
|
||
|
StringBuilder sb = new StringBuilder(size() * 7);
|
||
|
sb.append(this.array[this.start] ? "[true" : "[false");
|
||
|
int i = this.start;
|
||
|
while (true) {
|
||
|
i++;
|
||
|
if (i < this.end) {
|
||
|
sb.append(this.array[i] ? ", true" : ", false");
|
||
|
} else {
|
||
|
sb.append(']');
|
||
|
return sb.toString();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
boolean[] toBooleanArray() {
|
||
|
return Arrays.copyOfRange(this.array, this.start, this.end);
|
||
|
}
|
||
|
|
||
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.List
|
||
|
public int size() {
|
||
|
return this.end - this.start;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static int countTrue(boolean... zArr) {
|
||
|
int i = 0;
|
||
|
for (boolean z : zArr) {
|
||
|
if (z) {
|
||
|
i++;
|
||
|
}
|
||
|
}
|
||
|
return i;
|
||
|
}
|
||
|
|
||
|
public static void reverse(boolean[] zArr) {
|
||
|
Preconditions.checkNotNull(zArr);
|
||
|
reverse(zArr, 0, zArr.length);
|
||
|
}
|
||
|
|
||
|
public static void reverse(boolean[] zArr, int i, int i2) {
|
||
|
Preconditions.checkNotNull(zArr);
|
||
|
Preconditions.checkPositionIndexes(i, i2, zArr.length);
|
||
|
while (true) {
|
||
|
i2--;
|
||
|
if (i >= i2) {
|
||
|
return;
|
||
|
}
|
||
|
boolean z = zArr[i];
|
||
|
zArr[i] = zArr[i2];
|
||
|
zArr[i2] = z;
|
||
|
i++;
|
||
|
}
|
||
|
}
|
||
|
}
|