java.net.URL.equals()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(10.5k)|赞(0)|评价(0)|浏览(214)

本文整理了Java中java.net.URL.equals()方法的一些代码示例,展示了URL.equals()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。URL.equals()方法的具体详情如下:
包路径:java.net.URL
类名称:URL
方法名:equals

URL.equals介绍

[英]Returns true if this URL equals o. URLs are equal if they have the same protocol, host, port, file, and reference.

Network I/O Warning

Some implementations of URL.equals() resolve host names over the network. This is problematic:

  • The network may be slow. Many classes, including core collections like java.util.Map and java.util.Set expect that equals and hashCode will return quickly. By violating this assumption, this method posed potential performance problems.
  • Equal IP addresses do not imply equal content. Virtual hosting permits unrelated sites to share an IP address. This method could report two otherwise unrelated URLs to be equal because they're hosted on the same server.
  • The network many not be available. Two URLs could be equal when a network is available and unequal otherwise.
  • The network may change. The IP address for a given host name varies by network and over time. This is problematic for mobile devices. Two URLs could be equal on some networks and unequal on others.

This problem is fixed in Android 4.0 (Ice Cream Sandwich). In that release, URLs are only equal if their host names are equal (ignoring case).
[中]如果此URL等于o,则返回true。如果URL具有相同的协议、主机、端口、文件和引用,则返回true。
####网络I/O警告
URL的一些实现。equals()通过网络解析主机名。这是有问题的:
*网络可能很慢。许多类,包括像java这样的核心集合。util。地图和java。util。Set预期equals和hashCode将快速返回。由于违反了这一假设,这种方法带来了潜在的性能问题。
*相同的IP地址并不意味着内容相同。虚拟主机允许无关站点共享IP地址。此方法可以报告两个不相关的URL相等,因为它们位于同一服务器上。
*网络可能不可用。当网络可用时,两个URL可能相等,否则可能不相等。
*网络可能会改变。给定主机名的IP地址因网络和时间而异。这对于移动设备来说是有问题的。两个URL在某些网络上可能相等,而在其他网络上可能不相等。
这个问题在Android 4.0(冰激凌三明治)中得到了修复。在该版本中,URL只有在主机名相等时才相等(忽略大小写)。

代码示例

代码示例来源:origin: spring-projects/spring-framework

/**
 * This implementation compares the underlying URL references.
 */
@Override
public boolean equals(Object other) {
  return (this == other || (other instanceof UrlResource &&
      this.cleanedUrl.equals(((UrlResource) other).cleanedUrl)));
}

代码示例来源:origin: org.springframework/spring-core

/**
 * This implementation compares the underlying URL references.
 */
@Override
public boolean equals(Object other) {
  return (this == other || (other instanceof UrlResource &&
      this.cleanedUrl.equals(((UrlResource) other).cleanedUrl)));
}

代码示例来源:origin: micronaut-projects/micronaut-core

/**
 * This implementation compares the underlying URL references.
 */
@Override
public boolean equals(Object obj) {
  return (obj == this ||
    (obj instanceof UrlResource && cleanedUrl.equals(((UrlResource) obj).cleanedUrl)));
}

代码示例来源:origin: org.freemarker/freemarker

@Override
public boolean equals(Object o) {
  if (o instanceof URLTemplateSource) {
    return url.equals(((URLTemplateSource) o).url);
  } else {
    return false;
  }
}

代码示例来源:origin: spotbugs/spotbugs

static boolean g(URL u1, URL u2) {
  return u1.equals(u2);
}

代码示例来源:origin: redisson/redisson

@Override
  @SuppressFBWarnings(value = "DMI_BLOCKING_METHODS_ON_URL", justification = "Package sealing relies on URL equality")
  public boolean equals(Object other) {
    if (this == other) {
      return true;
    } else if (other == null || getClass() != other.getClass()) {
      return false;
    }
    ForFixedValue forFixedValue = (ForFixedValue) other;
    return sealBase.equals(forFixedValue.sealBase);
  }
}

代码示例来源:origin: gocd/gocd

@Override
public boolean equals(Object o) {
  if (this == o) return true;
  if (o == null || getClass() != o.getClass()) return false;
  AgentBootstrapperArgs that = (AgentBootstrapperArgs) o;
  if (serverUrl != null ? !serverUrl.equals(that.serverUrl) : that.serverUrl != null) return false;
  if (rootCertFile != null ? !rootCertFile.getAbsoluteFile().equals(that.rootCertFile.getAbsoluteFile()) : that.rootCertFile != null) return false;
  return sslVerificationMode == that.sslVerificationMode;
}

代码示例来源:origin: HotswapProjects/HotswapAgent

@Override
public boolean equals(Object o) {
  if (this == o) return true;
  if (o == null || getClass() != o.getClass()) return false;
  XmlBeanRefreshCommand that = (XmlBeanRefreshCommand) o;
  return this.url.equals(that.url);
}

代码示例来源:origin: redisson/redisson

@Override
  @SuppressFBWarnings(value = "DMI_BLOCKING_METHODS_ON_URL", justification = "Package sealing relies on URL equality")
  public boolean equals(Object other) {
    if (this == other) {
      return true;
    } else if (other == null || getClass() != other.getClass()) {
      return false;
    }
    Simple simple = (Simple) other;
    return !(specificationTitle != null ? !specificationTitle.equals(simple.specificationTitle) : simple.specificationTitle != null)
        && !(specificationVersion != null ? !specificationVersion.equals(simple.specificationVersion) : simple.specificationVersion != null)
        && !(specificationVendor != null ? !specificationVendor.equals(simple.specificationVendor) : simple.specificationVendor != null)
        && !(implementationTitle != null ? !implementationTitle.equals(simple.implementationTitle) : simple.implementationTitle != null)
        && !(implementationVersion != null ? !implementationVersion.equals(simple.implementationVersion) : simple.implementationVersion != null)
        && !(implementationVendor != null ? !implementationVendor.equals(simple.implementationVendor) : simple.implementationVendor != null)
        && !(sealBase != null ? !sealBase.equals(simple.sealBase) : simple.sealBase != null);
  }
}

代码示例来源:origin: HotswapProjects/HotswapAgent

@Override
public boolean equals(Object o) {
  if (this == o) return true;
  if (o == null || getClass() != o.getClass()) return false;
  BeanClassRefreshCommand that = (BeanClassRefreshCommand) o;
  if (!appClassLoader.equals(that.appClassLoader)) return false;
  if (beanArchiveUrl != null && !beanArchiveUrl.equals(that.beanArchiveUrl)) return false;
  return true;
}

代码示例来源:origin: org.apache.logging.log4j/log4j-api

@Override
public boolean equals(final Object o) {
  if (this == o) {
    return true;
  }
  if (o == null || getClass() != o.getClass()) {
    return false;
  }
  final UrlResource that = (UrlResource) o;
  if (classLoader != null ? !classLoader.equals(that.classLoader) : that.classLoader != null) {
    return false;
  }
  if (url != null ? !url.equals(that.url) : that.url != null) {
    return false;
  }
  return true;
}

代码示例来源:origin: gocd/gocd

@Override
public boolean equals(Object o) {
  if (this == o) {
    return true;
  }
  if (o == null || getClass() != o.getClass()) {
    return false;
  }
  PluginNamespace that = (PluginNamespace) o;
  if (prefix != null ? !prefix.equals(that.prefix) : that.prefix != null) {
    return false;
  }
  if (uri != null ? !uri.equals(that.uri) : that.uri != null) {
    return false;
  }
  if (xsdResource != null ? !xsdResource.equals(that.xsdResource) : that.xsdResource != null) {
    return false;
  }
  return true;
}

代码示例来源:origin: cloudfoundry/uaa

@Override
public boolean equals(Object o) {
  if (this == o) return true;
  if (o == null || getClass() != o.getClass()) return false;
  if (!super.equals(o)) return false;
  OIDCIdentityProviderDefinition that = (OIDCIdentityProviderDefinition) o;
  if (userInfoUrl != null ? !userInfoUrl.equals(that.userInfoUrl) : that.userInfoUrl != null) return false;
  if (this.passwordGrantEnabled != that.passwordGrantEnabled) return false;
  return discoveryUrl != null ? discoveryUrl.equals(that.discoveryUrl) : that.discoveryUrl == null;
}

代码示例来源:origin: stackoverflow.com

new URL("http://www.yahoo.com").equals(new URL("http://209.191.93.52"))

代码示例来源:origin: org.netbeans.api/org-openide-util

@Override
public boolean equals(Object obj) {
  if (obj == null) {
    return false;
  }
  if (getClass() != obj.getClass()) {
    return false;
  }
  final HelpCtx other = (HelpCtx) obj;
  if (this.helpCtx != other.helpCtx && (this.helpCtx == null || !this.helpCtx.equals(other.helpCtx))) {
    return false;
  }
  if ((this.helpID == null) ? (other.helpID != null) : !this.helpID.equals(other.helpID)) {
    return false;
  }
  return true;
}

代码示例来源:origin: apache/geode

/**
 * Returns true if the specified location is in the JVM classpath. This may ignore additions to
 * the classpath that are not reflected by the value in
 * {@code System.getProperty("java.class.path")}.
 *
 * @param location the directory or jar URL to test for
 * @return true if location is in the JVM classpath
 */
public static boolean isInClassPath(URL location) throws MalformedURLException {
 String classPath = getClassPath();
 StringTokenizer st = new StringTokenizer(classPath, File.pathSeparator);
 while (st.hasMoreTokens()) {
  String path = st.nextToken();
  if (location.equals(new File(path).toURI().toURL())) {
   return true;
  }
 }
 return false;
}

代码示例来源:origin: org.apache.ant/ant

private boolean isOneOf(Object o, Resource importedResource,
            File importedFile, URL importedURL) {
  if (o.equals(importedResource) || o.equals(importedFile)
    || o.equals(importedURL)) {
    return true;
  }
  if (o instanceof Resource) {
    if (importedFile != null) {
      FileProvider fp = ((Resource) o).as(FileProvider.class);
      if (fp != null && fp.getFile().equals(importedFile)) {
        return true;
      }
    }
    if (importedURL != null) {
      URLProvider up = ((Resource) o).as(URLProvider.class);
      return up != null && up.getURL().equals(importedURL);
    }
  }
  return false;
}

代码示例来源:origin: spotbugs/spotbugs

@ExpectWarning("Dm")
  public BadApplet() {
    URL u1 = getDocumentBase();
    URL u2 = getCodeBase();

    if (u1.equals(u2))
      return;

    if (getParameter("bad") != null)
      return;

    if (getAppletContext() != null)
      return;
  }
}

代码示例来源:origin: org.apache.ant/ant

/**
 * Test whether an Object equals this URLResource.
 * @param another the other Object to compare.
 * @return true if the specified Object is equal to this Resource.
 */
public synchronized boolean equals(Object another) {
  if (this == another) {
    return true;
  }
  if (isReference()) {
    return getCheckedRef().equals(another);
  }
  if (another == null || another.getClass() != getClass()) {
    return false;
  }
  URLResource other = (URLResource) another;
  return getURL() == null
    ? other.getURL() == null
    : getURL().equals(other.getURL());
}

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
@SuppressWarnings({"BigDecimalEquals", "EqualsHashCodeCalledOnUrl", "RedundantIfStatement"})
@Override public boolean equals(Object o) {
  if (this == o) return true;
  if (o == null || getClass() != o.getClass()) return false;
  TestObject that = (TestObject)o;
  if (id != that.id) return false;
  if (!Arrays.equals(arrVal, that.arrVal)) return false;
  if (bigVal != null ? !bigVal.equals(that.bigVal) : that.bigVal != null) return false;
  if (boolVal != null ? !boolVal.equals(that.boolVal) : that.boolVal != null) return false;
  if (byteVal != null ? !byteVal.equals(that.byteVal) : that.byteVal != null) return false;
  if (dateVal != null ? !dateVal.equals(that.dateVal) : that.dateVal != null) return false;
  if (doubleVal != null ? !doubleVal.equals(that.doubleVal) : that.doubleVal != null) return false;
  if (f1 != null ? !f1.equals(that.f1) : that.f1 != null) return false;
  if (f2 != null ? !f2.equals(that.f2) : that.f2 != null) return false;
  if (f3 != null ? !f3.equals(that.f3) : that.f3 != null) return false;
  if (floatVal != null ? !floatVal.equals(that.floatVal) : that.floatVal != null) return false;
  if (intVal != null ? !intVal.equals(that.intVal) : that.intVal != null) return false;
  if (longVal != null ? !longVal.equals(that.longVal) : that.longVal != null) return false;
  if (shortVal != null ? !shortVal.equals(that.shortVal) : that.shortVal != null) return false;
  if (strVal != null ? !strVal.equals(that.strVal) : that.strVal != null) return false;
  if (timeVal != null ? !timeVal.equals(that.timeVal) : that.timeVal != null) return false;
  if (tsVal != null ? !tsVal.equals(that.tsVal) : that.tsVal != null) return false;
  if (urlVal != null ? !urlVal.equals(that.urlVal) : that.urlVal != null) return false;
  return true;
}

相关文章