alexandroid/decompiled/jadx/sources/com/google/common/net/HostAndPort.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

201 lines
6.9 KiB
Java

package com.google.common.net;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.annotations.J2ktIncompatible;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Immutable;
import java.io.Serializable;
import kotlinx.serialization.json.internal.AbstractJsonLexerKt;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
@Immutable
@GwtCompatible
/* loaded from: classes8.dex */
public final class HostAndPort implements Serializable {
private static final int NO_PORT = -1;
@J2ktIncompatible
@GwtIncompatible
private static final long serialVersionUID = 0;
private final boolean hasBracketlessColons;
private final String host;
private final int port;
private HostAndPort(String str, int i, boolean z) {
this.host = str;
this.port = i;
this.hasBracketlessColons = z;
}
public static HostAndPort fromHost(String str) {
HostAndPort fromString = fromString(str);
Preconditions.checkArgument(!fromString.hasPort(), "Host has a port: %s", str);
return fromString;
}
public static HostAndPort fromParts(String str, int i) {
Preconditions.checkArgument(isValidPort(i), "Port out of range: %s", i);
HostAndPort fromString = fromString(str);
Preconditions.checkArgument(!fromString.hasPort(), "Host has a port: %s", str);
return new HostAndPort(fromString.host, i, fromString.hasBracketlessColons);
}
/* JADX WARN: Removed duplicated region for block: B:11:0x0047 */
/* JADX WARN: Removed duplicated region for block: B:7:0x0042 */
@com.google.errorprone.annotations.CanIgnoreReturnValue
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public static com.google.common.net.HostAndPort fromString(java.lang.String r7) {
/*
com.google.common.base.Preconditions.checkNotNull(r7)
java.lang.String r0 = "["
boolean r0 = r7.startsWith(r0)
r1 = -1
r2 = 1
r3 = 0
if (r0 == 0) goto L19
java.lang.String[] r0 = getHostAndPortFromBracketedHost(r7)
r4 = r0[r3]
r0 = r0[r2]
L16:
r5 = r4
r4 = r3
goto L3c
L19:
r0 = 58
int r4 = r7.indexOf(r0)
if (r4 < 0) goto L32
int r5 = r4 + 1
int r0 = r7.indexOf(r0, r5)
if (r0 != r1) goto L32
java.lang.String r4 = r7.substring(r3, r4)
java.lang.String r0 = r7.substring(r5)
goto L16
L32:
if (r4 < 0) goto L36
r0 = r2
goto L37
L36:
r0 = r3
L37:
r4 = 0
r5 = r4
r4 = r0
r0 = r5
r5 = r7
L3c:
boolean r6 = com.google.common.base.Strings.isNullOrEmpty(r0)
if (r6 == 0) goto L47
java.lang.Integer r7 = java.lang.Integer.valueOf(r1)
goto L62
L47:
java.lang.Integer r0 = com.google.common.primitives.Ints.tryParse(r0)
if (r0 == 0) goto L4e
goto L4f
L4e:
r2 = r3
L4f:
java.lang.String r1 = "Unparseable port number: %s"
com.google.common.base.Preconditions.checkArgument(r2, r1, r7)
int r1 = r0.intValue()
boolean r1 = isValidPort(r1)
java.lang.String r2 = "Port number out of range: %s"
com.google.common.base.Preconditions.checkArgument(r1, r2, r7)
r7 = r0
L62:
com.google.common.net.HostAndPort r0 = new com.google.common.net.HostAndPort
int r7 = r7.intValue()
r0.<init>(r5, r7, r4)
return r0
*/
throw new UnsupportedOperationException("Method not decompiled: com.google.common.net.HostAndPort.fromString(java.lang.String):com.google.common.net.HostAndPort");
}
private static String[] getHostAndPortFromBracketedHost(String str) {
Preconditions.checkArgument(str.charAt(0) == '[', "Bracketed host-port string must start with a bracket: %s", str);
int indexOf = str.indexOf(58);
int lastIndexOf = str.lastIndexOf(93);
Preconditions.checkArgument(indexOf > -1 && lastIndexOf > indexOf, "Invalid bracketed host/port: %s", str);
String substring = str.substring(1, lastIndexOf);
int i = lastIndexOf + 1;
if (i == str.length()) {
return new String[]{substring, ""};
}
Preconditions.checkArgument(str.charAt(i) == ':', "Only a colon may follow a close bracket: %s", str);
int i2 = lastIndexOf + 2;
for (int i3 = i2; i3 < str.length(); i3++) {
Preconditions.checkArgument(Character.isDigit(str.charAt(i3)), "Port must be numeric: %s", str);
}
return new String[]{substring, str.substring(i2)};
}
private static boolean isValidPort(int i) {
return i >= 0 && i <= 65535;
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof HostAndPort) {
HostAndPort hostAndPort = (HostAndPort) obj;
if (Objects.equal(this.host, hostAndPort.host) && this.port == hostAndPort.port) {
return true;
}
}
return false;
}
public String getHost() {
return this.host;
}
public int getPort() {
Preconditions.checkState(hasPort());
return this.port;
}
public int getPortOrDefault(int i) {
return hasPort() ? this.port : i;
}
public boolean hasPort() {
return this.port >= 0;
}
public int hashCode() {
return Objects.hashCode(this.host, Integer.valueOf(this.port));
}
@CanIgnoreReturnValue
public HostAndPort requireBracketsForIPv6() {
Preconditions.checkArgument(!this.hasBracketlessColons, "Possible bracketless IPv6 literal: %s", this.host);
return this;
}
public String toString() {
StringBuilder sb = new StringBuilder(this.host.length() + 8);
if (this.host.indexOf(58) >= 0) {
sb.append(AbstractJsonLexerKt.BEGIN_LIST);
sb.append(this.host);
sb.append(AbstractJsonLexerKt.END_LIST);
} else {
sb.append(this.host);
}
if (hasPort()) {
sb.append(AbstractJsonLexerKt.COLON);
sb.append(this.port);
}
return sb.toString();
}
public HostAndPort withDefaultPort(int i) {
Preconditions.checkArgument(isValidPort(i));
return hasPort() ? this : new HostAndPort(this.host, i, this.hasBracketlessColons);
}
}