package com.google.common.net; import com.google.common.base.Preconditions; import java.net.InetAddress; import java.text.ParseException; /* loaded from: classes2.dex */ public final class HostSpecifier { private final String canonicalForm; private HostSpecifier(String str) { this.canonicalForm = str; } public static HostSpecifier fromValid(String str) { InetAddress inetAddress; HostAndPort fromString = HostAndPort.fromString(str); Preconditions.checkArgument(!fromString.hasPort()); String host = fromString.getHost(); try { inetAddress = InetAddresses.forString(host); } catch (IllegalArgumentException unused) { inetAddress = null; } if (inetAddress != null) { return new HostSpecifier(InetAddresses.toUriString(inetAddress)); } InternetDomainName from = InternetDomainName.from(host); if (from.hasPublicSuffix()) { return new HostSpecifier(from.toString()); } String valueOf = String.valueOf(host); throw new IllegalArgumentException(valueOf.length() != 0 ? "Domain name does not have a recognized public suffix: ".concat(valueOf) : new String("Domain name does not have a recognized public suffix: ")); } public static HostSpecifier from(String str) throws ParseException { try { return fromValid(str); } catch (IllegalArgumentException e) { String valueOf = String.valueOf(str); ParseException parseException = new ParseException(valueOf.length() != 0 ? "Invalid host specifier: ".concat(valueOf) : new String("Invalid host specifier: "), 0); parseException.initCause(e); throw parseException; } } public static boolean isValid(String str) { try { fromValid(str); return true; } catch (IllegalArgumentException unused) { return false; } } public final boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof HostSpecifier) { return this.canonicalForm.equals(((HostSpecifier) obj).canonicalForm); } return false; } public final int hashCode() { return this.canonicalForm.hashCode(); } public final String toString() { return this.canonicalForm; } }