what-the-bank/sources/com/google/common/primitives/Bytes.java

297 lines
9.2 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
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.List;
import java.util.RandomAccess;
/* loaded from: classes2.dex */
public final class Bytes {
public static int hashCode(byte b) {
return b;
}
private Bytes() {
}
public static boolean contains(byte[] bArr, byte b) {
for (byte b2 : bArr) {
if (b2 == b) {
return true;
}
}
return false;
}
public static int indexOf(byte[] bArr, byte b) {
return indexOf(bArr, b, 0, bArr.length);
}
/* JADX INFO: Access modifiers changed from: private */
public static int indexOf(byte[] bArr, byte b, int i, int i2) {
while (i < i2) {
if (bArr[i] == b) {
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(byte[] r5, byte[] 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
r3 = r5[r3]
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.Bytes.indexOf(byte[], byte[]):int");
}
public static int lastIndexOf(byte[] bArr, byte b) {
return lastIndexOf(bArr, b, 0, bArr.length);
}
/* JADX INFO: Access modifiers changed from: private */
public static int lastIndexOf(byte[] bArr, byte b, int i, int i2) {
for (int i3 = i2 - 1; i3 >= i; i3--) {
if (bArr[i3] == b) {
return i3;
}
}
return -1;
}
public static byte[] concat(byte[]... bArr) {
int i = 0;
for (byte[] bArr2 : bArr) {
i += bArr2.length;
}
byte[] bArr3 = new byte[i];
int i2 = 0;
for (byte[] bArr4 : bArr) {
System.arraycopy(bArr4, 0, bArr3, i2, bArr4.length);
i2 += bArr4.length;
}
return bArr3;
}
public static byte[] ensureCapacity(byte[] bArr, int i, int i2) {
Preconditions.checkArgument(i >= 0, "Invalid minLength: %s", i);
Preconditions.checkArgument(i2 >= 0, "Invalid padding: %s", i2);
return bArr.length < i ? Arrays.copyOf(bArr, i + i2) : bArr;
}
public static byte[] toArray(Collection<? extends Number> collection) {
if (collection instanceof ByteArrayAsList) {
return ((ByteArrayAsList) collection).toByteArray();
}
Object[] array = collection.toArray();
int length = array.length;
byte[] bArr = new byte[length];
for (int i = 0; i < length; i++) {
bArr[i] = ((Number) Preconditions.checkNotNull(array[i])).byteValue();
}
return bArr;
}
public static List<Byte> asList(byte... bArr) {
if (bArr.length == 0) {
return Collections.emptyList();
}
return new ByteArrayAsList(bArr);
}
/* loaded from: classes2.dex */
static class ByteArrayAsList extends AbstractList<Byte> implements RandomAccess, Serializable {
private static final long serialVersionUID = 0;
final byte[] array;
final int end;
final int start;
@Override // java.util.AbstractCollection, java.util.Collection, java.util.List
public boolean isEmpty() {
return false;
}
ByteArrayAsList(byte[] bArr) {
this(bArr, 0, bArr.length);
}
ByteArrayAsList(byte[] bArr, int i, int i2) {
this.array = bArr;
this.start = i;
this.end = i2;
}
@Override // java.util.AbstractList, java.util.List
public Byte get(int i) {
Preconditions.checkElementIndex(i, size());
return Byte.valueOf(this.array[this.start + i]);
}
@Override // java.util.AbstractCollection, java.util.Collection, java.util.List
public boolean contains(Object obj) {
return (obj instanceof Byte) && Bytes.indexOf(this.array, ((Byte) obj).byteValue(), this.start, this.end) != -1;
}
@Override // java.util.AbstractList, java.util.List
public int indexOf(Object obj) {
int indexOf;
if (!(obj instanceof Byte) || (indexOf = Bytes.indexOf(this.array, ((Byte) obj).byteValue(), 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 Byte) || (lastIndexOf = Bytes.lastIndexOf(this.array, ((Byte) obj).byteValue(), this.start, this.end)) < 0) {
return -1;
}
return lastIndexOf - this.start;
}
@Override // java.util.AbstractList, java.util.List
public Byte set(int i, Byte b) {
Preconditions.checkElementIndex(i, size());
byte[] bArr = this.array;
int i2 = this.start + i;
byte b2 = bArr[i2];
bArr[i2] = ((Byte) Preconditions.checkNotNull(b)).byteValue();
return Byte.valueOf(b2);
}
@Override // java.util.AbstractList, java.util.List
public List<Byte> subList(int i, int i2) {
Preconditions.checkPositionIndexes(i, i2, size());
if (i == i2) {
return Collections.emptyList();
}
byte[] bArr = this.array;
int i3 = this.start;
return new ByteArrayAsList(bArr, 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 ByteArrayAsList) {
ByteArrayAsList byteArrayAsList = (ByteArrayAsList) obj;
int size = size();
if (byteArrayAsList.size() != size) {
return false;
}
for (int i = 0; i < size; i++) {
if (this.array[this.start + i] != byteArrayAsList.array[byteArrayAsList.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) + Bytes.hashCode(this.array[i2]);
}
return i;
}
@Override // java.util.AbstractCollection
public String toString() {
StringBuilder sb = new StringBuilder(size() * 5);
sb.append('[');
sb.append((int) this.array[this.start]);
int i = this.start;
while (true) {
i++;
if (i < this.end) {
sb.append(", ");
sb.append((int) this.array[i]);
} else {
sb.append(']');
return sb.toString();
}
}
}
byte[] toByteArray() {
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 void reverse(byte[] bArr) {
Preconditions.checkNotNull(bArr);
reverse(bArr, 0, bArr.length);
}
public static void reverse(byte[] bArr, int i, int i2) {
Preconditions.checkNotNull(bArr);
Preconditions.checkPositionIndexes(i, i2, bArr.length);
while (true) {
i2--;
if (i >= i2) {
return;
}
byte b = bArr[i];
bArr[i] = bArr[i2];
bArr[i2] = b;
i++;
}
}
}