what-the-bank/sources/com/google/gson/JsonPrimitive.java

170 lines
5.4 KiB
Java

package com.google.gson;
import com.google.gson.internal.C$Gson$Preconditions;
import com.google.gson.internal.LazilyParsedNumber;
import java.math.BigDecimal;
import java.math.BigInteger;
/* loaded from: classes.dex */
public final class JsonPrimitive extends JsonElement {
private final Object value;
@Override // com.google.gson.JsonElement
public final JsonPrimitive deepCopy() {
return this;
}
public JsonPrimitive(Boolean bool) {
this.value = C$Gson$Preconditions.checkNotNull(bool);
}
public JsonPrimitive(Number number) {
this.value = C$Gson$Preconditions.checkNotNull(number);
}
public JsonPrimitive(String str) {
this.value = C$Gson$Preconditions.checkNotNull(str);
}
public JsonPrimitive(Character ch) {
this.value = ((Character) C$Gson$Preconditions.checkNotNull(ch)).toString();
}
public final boolean isBoolean() {
return this.value instanceof Boolean;
}
@Override // com.google.gson.JsonElement
public final boolean getAsBoolean() {
if (isBoolean()) {
return ((Boolean) this.value).booleanValue();
}
return Boolean.parseBoolean(getAsString());
}
public final boolean isNumber() {
return this.value instanceof Number;
}
@Override // com.google.gson.JsonElement
public final Number getAsNumber() {
Object obj = this.value;
return obj instanceof String ? new LazilyParsedNumber((String) obj) : (Number) obj;
}
public final boolean isString() {
return this.value instanceof String;
}
@Override // com.google.gson.JsonElement
public final String getAsString() {
if (isNumber()) {
return getAsNumber().toString();
}
if (isBoolean()) {
return ((Boolean) this.value).toString();
}
return (String) this.value;
}
@Override // com.google.gson.JsonElement
public final double getAsDouble() {
return isNumber() ? getAsNumber().doubleValue() : Double.parseDouble(getAsString());
}
@Override // com.google.gson.JsonElement
public final BigDecimal getAsBigDecimal() {
Object obj = this.value;
return obj instanceof BigDecimal ? (BigDecimal) obj : new BigDecimal(this.value.toString());
}
@Override // com.google.gson.JsonElement
public final BigInteger getAsBigInteger() {
Object obj = this.value;
return obj instanceof BigInteger ? (BigInteger) obj : new BigInteger(this.value.toString());
}
@Override // com.google.gson.JsonElement
public final float getAsFloat() {
return isNumber() ? getAsNumber().floatValue() : Float.parseFloat(getAsString());
}
@Override // com.google.gson.JsonElement
public final long getAsLong() {
return isNumber() ? getAsNumber().longValue() : Long.parseLong(getAsString());
}
@Override // com.google.gson.JsonElement
public final short getAsShort() {
return isNumber() ? getAsNumber().shortValue() : Short.parseShort(getAsString());
}
@Override // com.google.gson.JsonElement
public final int getAsInt() {
return isNumber() ? getAsNumber().intValue() : Integer.parseInt(getAsString());
}
@Override // com.google.gson.JsonElement
public final byte getAsByte() {
return isNumber() ? getAsNumber().byteValue() : Byte.parseByte(getAsString());
}
@Override // com.google.gson.JsonElement
public final char getAsCharacter() {
return getAsString().charAt(0);
}
public final int hashCode() {
long doubleToLongBits;
if (this.value == null) {
return 31;
}
if (isIntegral(this)) {
doubleToLongBits = getAsNumber().longValue();
} else {
Object obj = this.value;
if (obj instanceof Number) {
doubleToLongBits = Double.doubleToLongBits(getAsNumber().doubleValue());
} else {
return obj.hashCode();
}
}
return (int) (doubleToLongBits ^ (doubleToLongBits >>> 32));
}
public final boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
JsonPrimitive jsonPrimitive = (JsonPrimitive) obj;
if (this.value == null) {
return jsonPrimitive.value == null;
}
if (isIntegral(this) && isIntegral(jsonPrimitive)) {
return getAsNumber().longValue() == jsonPrimitive.getAsNumber().longValue();
}
Object obj2 = this.value;
if ((obj2 instanceof Number) && (jsonPrimitive.value instanceof Number)) {
double doubleValue = getAsNumber().doubleValue();
double doubleValue2 = jsonPrimitive.getAsNumber().doubleValue();
if (doubleValue != doubleValue2) {
return Double.isNaN(doubleValue) && Double.isNaN(doubleValue2);
}
return true;
}
return obj2.equals(jsonPrimitive.value);
}
private static boolean isIntegral(JsonPrimitive jsonPrimitive) {
Object obj = jsonPrimitive.value;
if (!(obj instanceof Number)) {
return false;
}
Number number = (Number) obj;
return (number instanceof BigInteger) || (number instanceof Long) || (number instanceof Integer) || (number instanceof Short) || (number instanceof Byte);
}
}