Rabbit-R1/switch port/java/sources/com/google/common/hash/Funnels.java
2024-05-21 17:08:36 -04:00

214 lines
6.8 KiB
Java

package com.google.common.hash;
import com.google.common.base.Preconditions;
import java.io.OutputStream;
import java.io.Serializable;
import java.nio.charset.Charset;
import java.util.Iterator;
import javax.annotation.CheckForNull;
@ElementTypesAreNonnullByDefault
/* loaded from: classes3.dex */
public final class Funnels {
private Funnels() {
}
public static Funnel<byte[]> byteArrayFunnel() {
return ByteArrayFunnel.INSTANCE;
}
/* loaded from: classes3.dex */
private enum ByteArrayFunnel implements Funnel<byte[]> {
INSTANCE;
@Override // java.lang.Enum
public String toString() {
return "Funnels.byteArrayFunnel()";
}
@Override // com.google.common.hash.Funnel
public void funnel(byte[] bArr, PrimitiveSink primitiveSink) {
primitiveSink.putBytes(bArr);
}
}
public static Funnel<CharSequence> unencodedCharsFunnel() {
return UnencodedCharsFunnel.INSTANCE;
}
/* loaded from: classes3.dex */
private enum UnencodedCharsFunnel implements Funnel<CharSequence> {
INSTANCE;
@Override // java.lang.Enum
public String toString() {
return "Funnels.unencodedCharsFunnel()";
}
@Override // com.google.common.hash.Funnel
public void funnel(CharSequence charSequence, PrimitiveSink primitiveSink) {
primitiveSink.putUnencodedChars(charSequence);
}
}
public static Funnel<CharSequence> stringFunnel(Charset charset) {
return new StringCharsetFunnel(charset);
}
/* JADX INFO: Access modifiers changed from: private */
/* loaded from: classes3.dex */
public static class StringCharsetFunnel implements Funnel<CharSequence>, Serializable {
private final Charset charset;
StringCharsetFunnel(Charset charset) {
this.charset = (Charset) Preconditions.checkNotNull(charset);
}
@Override // com.google.common.hash.Funnel
public void funnel(CharSequence charSequence, PrimitiveSink primitiveSink) {
primitiveSink.putString(charSequence, this.charset);
}
public String toString() {
String name = this.charset.name();
return new StringBuilder(String.valueOf(name).length() + 22).append("Funnels.stringFunnel(").append(name).append(")").toString();
}
public boolean equals(@CheckForNull Object obj) {
if (obj instanceof StringCharsetFunnel) {
return this.charset.equals(((StringCharsetFunnel) obj).charset);
}
return false;
}
public int hashCode() {
return this.charset.hashCode() ^ StringCharsetFunnel.class.hashCode();
}
Object writeReplace() {
return new SerializedForm(this.charset);
}
/* loaded from: classes3.dex */
private static class SerializedForm implements Serializable {
private static final long serialVersionUID = 0;
private final String charsetCanonicalName;
SerializedForm(Charset charset) {
this.charsetCanonicalName = charset.name();
}
private Object readResolve() {
return Funnels.stringFunnel(Charset.forName(this.charsetCanonicalName));
}
}
}
public static Funnel<Integer> integerFunnel() {
return IntegerFunnel.INSTANCE;
}
/* loaded from: classes3.dex */
private enum IntegerFunnel implements Funnel<Integer> {
INSTANCE;
@Override // java.lang.Enum
public String toString() {
return "Funnels.integerFunnel()";
}
@Override // com.google.common.hash.Funnel
public void funnel(Integer num, PrimitiveSink primitiveSink) {
primitiveSink.putInt(num.intValue());
}
}
public static <E> Funnel<Iterable<? extends E>> sequentialFunnel(Funnel<E> funnel) {
return new SequentialFunnel(funnel);
}
/* loaded from: classes3.dex */
private static class SequentialFunnel<E> implements Funnel<Iterable<? extends E>>, Serializable {
private final Funnel<E> elementFunnel;
SequentialFunnel(Funnel<E> funnel) {
this.elementFunnel = (Funnel) Preconditions.checkNotNull(funnel);
}
@Override // com.google.common.hash.Funnel
public void funnel(Iterable<? extends E> iterable, PrimitiveSink primitiveSink) {
Iterator<? extends E> it = iterable.iterator();
while (it.hasNext()) {
this.elementFunnel.funnel(it.next(), primitiveSink);
}
}
public String toString() {
String valueOf = String.valueOf(this.elementFunnel);
return new StringBuilder(String.valueOf(valueOf).length() + 26).append("Funnels.sequentialFunnel(").append(valueOf).append(")").toString();
}
public boolean equals(@CheckForNull Object obj) {
if (obj instanceof SequentialFunnel) {
return this.elementFunnel.equals(((SequentialFunnel) obj).elementFunnel);
}
return false;
}
public int hashCode() {
return this.elementFunnel.hashCode() ^ SequentialFunnel.class.hashCode();
}
}
public static Funnel<Long> longFunnel() {
return LongFunnel.INSTANCE;
}
/* loaded from: classes3.dex */
private enum LongFunnel implements Funnel<Long> {
INSTANCE;
@Override // java.lang.Enum
public String toString() {
return "Funnels.longFunnel()";
}
@Override // com.google.common.hash.Funnel
public void funnel(Long l, PrimitiveSink primitiveSink) {
primitiveSink.putLong(l.longValue());
}
}
public static OutputStream asOutputStream(PrimitiveSink primitiveSink) {
return new SinkAsStream(primitiveSink);
}
/* loaded from: classes3.dex */
private static class SinkAsStream extends OutputStream {
final PrimitiveSink sink;
SinkAsStream(PrimitiveSink primitiveSink) {
this.sink = (PrimitiveSink) Preconditions.checkNotNull(primitiveSink);
}
@Override // java.io.OutputStream
public void write(int i) {
this.sink.putByte((byte) i);
}
@Override // java.io.OutputStream
public void write(byte[] bArr) {
this.sink.putBytes(bArr);
}
@Override // java.io.OutputStream
public void write(byte[] bArr, int i, int i2) {
this.sink.putBytes(bArr, i, i2);
}
public String toString() {
String valueOf = String.valueOf(this.sink);
return new StringBuilder(String.valueOf(valueOf).length() + 24).append("Funnels.asOutputStream(").append(valueOf).append(")").toString();
}
}
}