alexandroid/decompiled/jadx/sources/com/google/common/hash/HashCode.java
KaKi87 a47fad5135 📦 Add decompiled Alexa 2.2.730155.0 (jadx, apktool, Hermes strings)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 00:04:16 +01:00

277 lines
9.1 KiB
Java

package com.google.common.hash;
import androidx.compose.runtime.BitVector$$ExternalSyntheticOutline0;
import com.google.common.base.Preconditions;
import com.google.common.primitives.UnsignedInts;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.io.Serializable;
import rx.Single$$ExternalSyntheticBUOutline0;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
/* loaded from: classes8.dex */
public abstract class HashCode {
private static final char[] hexDigits = "0123456789abcdef".toCharArray();
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
public static final class BytesHashCode extends HashCode implements Serializable {
private static final long serialVersionUID = 0;
final byte[] bytes;
public BytesHashCode(byte[] bArr) {
this.bytes = (byte[]) Preconditions.checkNotNull(bArr);
}
@Override // com.google.common.hash.HashCode
public byte[] asBytes() {
return (byte[]) this.bytes.clone();
}
@Override // com.google.common.hash.HashCode
public int asInt() {
byte[] bArr = this.bytes;
Preconditions.checkState(bArr.length >= 4, "HashCode#asInt() requires >= 4 bytes (it only has %s bytes).", bArr.length);
byte[] bArr2 = this.bytes;
return ((bArr2[3] & 255) << 24) | (bArr2[0] & 255) | ((bArr2[1] & 255) << 8) | ((bArr2[2] & 255) << 16);
}
@Override // com.google.common.hash.HashCode
public long asLong() {
byte[] bArr = this.bytes;
Preconditions.checkState(bArr.length >= 8, "HashCode#asLong() requires >= 8 bytes (it only has %s bytes).", bArr.length);
return padToLong();
}
@Override // com.google.common.hash.HashCode
public int bits() {
return this.bytes.length * 8;
}
@Override // com.google.common.hash.HashCode
public boolean equalsSameBits(HashCode hashCode) {
if (this.bytes.length != hashCode.getBytesInternal().length) {
return false;
}
boolean z = true;
int i = 0;
while (true) {
byte[] bArr = this.bytes;
if (i >= bArr.length) {
return z;
}
z &= bArr[i] == hashCode.getBytesInternal()[i];
i++;
}
}
@Override // com.google.common.hash.HashCode
public byte[] getBytesInternal() {
return this.bytes;
}
@Override // com.google.common.hash.HashCode
public long padToLong() {
long j = this.bytes[0] & 255;
for (int i = 1; i < Math.min(this.bytes.length, 8); i++) {
j |= (this.bytes[i] & 255) << (i * 8);
}
return j;
}
@Override // com.google.common.hash.HashCode
public void writeBytesToImpl(byte[] bArr, int i, int i2) {
System.arraycopy(this.bytes, 0, bArr, i, i2);
}
}
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
public static final class IntHashCode extends HashCode implements Serializable {
private static final long serialVersionUID = 0;
final int hash;
public IntHashCode(int i) {
this.hash = i;
}
@Override // com.google.common.hash.HashCode
public byte[] asBytes() {
int i = this.hash;
return new byte[]{(byte) i, (byte) (i >> 8), (byte) (i >> 16), (byte) (i >> 24)};
}
@Override // com.google.common.hash.HashCode
public int asInt() {
return this.hash;
}
@Override // com.google.common.hash.HashCode
public long asLong() {
throw new IllegalStateException("this HashCode only has 32 bits; cannot create a long");
}
@Override // com.google.common.hash.HashCode
public int bits() {
return 32;
}
@Override // com.google.common.hash.HashCode
public boolean equalsSameBits(HashCode hashCode) {
return this.hash == hashCode.asInt();
}
@Override // com.google.common.hash.HashCode
public long padToLong() {
return UnsignedInts.toLong(this.hash);
}
@Override // com.google.common.hash.HashCode
public void writeBytesToImpl(byte[] bArr, int i, int i2) {
for (int i3 = 0; i3 < i2; i3++) {
bArr[i + i3] = (byte) (this.hash >> (i3 * 8));
}
}
}
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
public static final class LongHashCode extends HashCode implements Serializable {
private static final long serialVersionUID = 0;
final long hash;
public LongHashCode(long j) {
this.hash = j;
}
@Override // com.google.common.hash.HashCode
public byte[] asBytes() {
return new byte[]{(byte) this.hash, (byte) (r0 >> 8), (byte) (r0 >> 16), (byte) (r0 >> 24), (byte) (r0 >> 32), (byte) (r0 >> 40), (byte) (r0 >> 48), (byte) (r0 >> 56)};
}
@Override // com.google.common.hash.HashCode
public int asInt() {
return (int) this.hash;
}
@Override // com.google.common.hash.HashCode
public long asLong() {
return this.hash;
}
@Override // com.google.common.hash.HashCode
public int bits() {
return 64;
}
@Override // com.google.common.hash.HashCode
public boolean equalsSameBits(HashCode hashCode) {
return this.hash == hashCode.asLong();
}
@Override // com.google.common.hash.HashCode
public long padToLong() {
return this.hash;
}
@Override // com.google.common.hash.HashCode
public void writeBytesToImpl(byte[] bArr, int i, int i2) {
for (int i3 = 0; i3 < i2; i3++) {
bArr[i + i3] = (byte) (this.hash >> (i3 * 8));
}
}
}
private static int decode(char c) {
if (c >= '0' && c <= '9') {
return c - '0';
}
if (c >= 'a' && c <= 'f') {
return c - 'W';
}
Single$$ExternalSyntheticBUOutline0.m$3(BitVector$$ExternalSyntheticOutline0.m("Illegal hexadecimal character: ", c));
return 0;
}
public static HashCode fromBytes(byte[] bArr) {
Preconditions.checkArgument(bArr.length >= 1, "A HashCode must contain at least 1 byte.");
return fromBytesNoCopy((byte[]) bArr.clone());
}
public static HashCode fromBytesNoCopy(byte[] bArr) {
return new BytesHashCode(bArr);
}
public static HashCode fromInt(int i) {
return new IntHashCode(i);
}
public static HashCode fromLong(long j) {
return new LongHashCode(j);
}
public static HashCode fromString(String str) {
Preconditions.checkArgument(str.length() >= 2, "input string (%s) must have at least 2 characters", str);
Preconditions.checkArgument(str.length() % 2 == 0, "input string (%s) must have an even number of characters", str);
byte[] bArr = new byte[str.length() / 2];
for (int i = 0; i < str.length(); i += 2) {
bArr[i / 2] = (byte) ((decode(str.charAt(i)) << 4) + decode(str.charAt(i + 1)));
}
return fromBytesNoCopy(bArr);
}
public abstract byte[] asBytes();
public abstract int asInt();
public abstract long asLong();
public abstract int bits();
public final boolean equals(Object obj) {
if (obj instanceof HashCode) {
HashCode hashCode = (HashCode) obj;
if (bits() == hashCode.bits() && equalsSameBits(hashCode)) {
return true;
}
}
return false;
}
public abstract boolean equalsSameBits(HashCode hashCode);
public byte[] getBytesInternal() {
return asBytes();
}
public final int hashCode() {
if (bits() >= 32) {
return asInt();
}
byte[] bytesInternal = getBytesInternal();
int i = bytesInternal[0] & 255;
for (int i2 = 1; i2 < bytesInternal.length; i2++) {
i |= (bytesInternal[i2] & 255) << (i2 * 8);
}
return i;
}
public abstract long padToLong();
public final String toString() {
byte[] bytesInternal = getBytesInternal();
StringBuilder sb = new StringBuilder(bytesInternal.length * 2);
for (byte b : bytesInternal) {
char[] cArr = hexDigits;
sb.append(cArr[(b >> 4) & 15]);
sb.append(cArr[b & 15]);
}
return sb.toString();
}
@CanIgnoreReturnValue
public int writeBytesTo(byte[] bArr, int i, int i2) {
int min = Math.min(i2, bits() / 8);
Preconditions.checkPositionIndexes(i, i + min, bArr.length);
writeBytesToImpl(bArr, i, min);
return min;
}
public abstract void writeBytesToImpl(byte[] bArr, int i, int i2);
}