what-the-bank/sources/com/google/gson/internal/JavaVersion.java

59 lines
1.6 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package com.google.gson.internal;
/* loaded from: classes.dex */
public final class JavaVersion {
private static final int majorJavaVersion = determineMajorJavaVersion();
private static int determineMajorJavaVersion() {
return getMajorJavaVersion(System.getProperty("java.version"));
}
static int getMajorJavaVersion(String str) {
int parseDotted = parseDotted(str);
if (parseDotted == -1) {
parseDotted = extractBeginningInt(str);
}
if (parseDotted == -1) {
return 6;
}
return parseDotted;
}
private static int parseDotted(String str) {
try {
String[] split = str.split("[._]");
int parseInt = Integer.parseInt(split[0]);
return (parseInt != 1 || split.length <= 1) ? parseInt : Integer.parseInt(split[1]);
} catch (NumberFormatException unused) {
return -1;
}
}
private static int extractBeginningInt(String str) {
try {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < str.length(); i++) {
char charAt = str.charAt(i);
if (!Character.isDigit(charAt)) {
break;
}
sb.append(charAt);
}
return Integer.parseInt(sb.toString());
} catch (NumberFormatException unused) {
return -1;
}
}
private JavaVersion() {
}
public static boolean isJava9OrLater() {
return majorJavaVersion >= 9;
}
public static int getMajorJavaVersion() {
return majorJavaVersion;
}
}