what-the-bank/sources/com/google/common/base/MoreObjects.java

167 lines
5.2 KiB
Java

package com.google.common.base;
import com.airbnb.deeplinkdispatch.UrlTreeKt;
import java.util.Arrays;
/* loaded from: classes2.dex */
public final class MoreObjects {
public static <T> T firstNonNull(T t, T t2) {
if (t != null) {
return t;
}
if (t2 != null) {
return t2;
}
throw new NullPointerException("Both parameters are null");
}
public static ToStringHelper toStringHelper(Object obj) {
return new ToStringHelper(obj.getClass().getSimpleName());
}
public static ToStringHelper toStringHelper(Class<?> cls) {
return new ToStringHelper(cls.getSimpleName());
}
public static ToStringHelper toStringHelper(String str) {
return new ToStringHelper(str);
}
/* loaded from: classes2.dex */
public static final class ToStringHelper {
private final String className;
private final ValueHolder holderHead;
private ValueHolder holderTail;
private boolean omitNullValues;
private ToStringHelper(String str) {
ValueHolder valueHolder = new ValueHolder();
this.holderHead = valueHolder;
this.holderTail = valueHolder;
this.omitNullValues = false;
this.className = (String) Preconditions.checkNotNull(str);
}
public final ToStringHelper add(String str, Object obj) {
return addHolder(str, obj);
}
public final ToStringHelper add(String str, boolean z) {
return addHolder(str, String.valueOf(z));
}
public final ToStringHelper add(String str, char c) {
return addHolder(str, String.valueOf(c));
}
public final ToStringHelper add(String str, double d) {
return addHolder(str, String.valueOf(d));
}
public final ToStringHelper add(String str, float f) {
return addHolder(str, String.valueOf(f));
}
public final ToStringHelper add(String str, int i) {
return addHolder(str, String.valueOf(i));
}
public final ToStringHelper add(String str, long j) {
return addHolder(str, String.valueOf(j));
}
public final ToStringHelper addValue(Object obj) {
return addHolder(obj);
}
public final ToStringHelper addValue(boolean z) {
return addHolder(String.valueOf(z));
}
public final ToStringHelper addValue(char c) {
return addHolder(String.valueOf(c));
}
public final ToStringHelper addValue(double d) {
return addHolder(String.valueOf(d));
}
public final ToStringHelper addValue(float f) {
return addHolder(String.valueOf(f));
}
public final ToStringHelper addValue(int i) {
return addHolder(String.valueOf(i));
}
public final ToStringHelper addValue(long j) {
return addHolder(String.valueOf(j));
}
public final String toString() {
boolean z = this.omitNullValues;
StringBuilder sb = new StringBuilder(32);
sb.append(this.className);
sb.append(UrlTreeKt.componentParamPrefixChar);
String str = "";
for (ValueHolder valueHolder = this.holderHead.next; valueHolder != null; valueHolder = valueHolder.next) {
Object obj = valueHolder.value;
if (!z || obj != null) {
sb.append(str);
if (valueHolder.name != null) {
sb.append(valueHolder.name);
sb.append('=');
}
if (obj != null && obj.getClass().isArray()) {
String deepToString = Arrays.deepToString(new Object[]{obj});
sb.append((CharSequence) deepToString, 1, deepToString.length() - 1);
} else {
sb.append(obj);
}
str = ", ";
}
}
sb.append(UrlTreeKt.componentParamSuffixChar);
return sb.toString();
}
private ValueHolder addHolder() {
ValueHolder valueHolder = new ValueHolder();
this.holderTail.next = valueHolder;
this.holderTail = valueHolder;
return valueHolder;
}
private ToStringHelper addHolder(Object obj) {
addHolder().value = obj;
return this;
}
private ToStringHelper addHolder(String str, Object obj) {
ValueHolder addHolder = addHolder();
addHolder.value = obj;
addHolder.name = (String) Preconditions.checkNotNull(str);
return this;
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static final class ValueHolder {
String name;
ValueHolder next;
Object value;
private ValueHolder() {
}
}
public final ToStringHelper omitNullValues() {
this.omitNullValues = true;
return this;
}
}
private MoreObjects() {
}
}