java.util.Objects类的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(5.1k)|赞(0)|评价(0)|浏览(197)

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

Objects介绍

[英]Utility methods for objects.
[中]对象的实用方法。

代码示例

代码示例来源:origin: skylot/jadx

  1. @Override
  2. public int indexOf(Object o) {
  3. int len = arr.length;
  4. for (int i = 0; i < len; i++) {
  5. E e = arr[i];
  6. if (Objects.equals(e, o)) {
  7. return i;
  8. }
  9. }
  10. return -1;
  11. }

代码示例来源:origin: skylot/jadx

  1. private ResContainer(String name, List<ResContainer> subFiles, Object data, DataType dataType) {
  2. this.name = Objects.requireNonNull(name);
  3. this.subFiles = Objects.requireNonNull(subFiles);
  4. this.data = Objects.requireNonNull(data);
  5. this.dataType = Objects.requireNonNull(dataType);
  6. }

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

  1. @Override
  2. public int hashCode() {
  3. return Objects.hash(this.metadata, this.importClassName);
  4. }
  5. }

代码示例来源:origin: ctripcorp/apollo

  1. public boolean isNamespaceUnique(String appId, String cluster, String namespace) {
  2. Objects.requireNonNull(appId, "AppId must not be null");
  3. Objects.requireNonNull(cluster, "Cluster must not be null");
  4. Objects.requireNonNull(namespace, "Namespace must not be null");
  5. return Objects.isNull(
  6. namespaceRepository.findByAppIdAndClusterNameAndNamespaceName(appId, cluster, namespace));
  7. }

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

  1. @Override
  2. public int hashCode() {
  3. if (hash != 0)
  4. return hash;
  5. final int prime = 31;
  6. int result = 1;
  7. result = prime * result + partition;
  8. result = prime * result + Objects.hashCode(topic);
  9. this.hash = result;
  10. return result;
  11. }

代码示例来源:origin: ctripcorp/apollo

  1. public boolean isAppNamespaceNameUnique(String appId, String namespaceName) {
  2. Objects.requireNonNull(appId, "AppId must not be null");
  3. Objects.requireNonNull(namespaceName, "Namespace must not be null");
  4. return Objects.isNull(appNamespaceRepository.findByAppIdAndName(appId, namespaceName));
  5. }

代码示例来源:origin: square/okhttp

  1. @Override public int hashCode() {
  2. int result = Objects.hashCode(certificateChainCleaner);
  3. result = 31 * result + pins.hashCode();
  4. return result;
  5. }

代码示例来源:origin: skylot/jadx

  1. @Override
  2. public int lastIndexOf(Object o) {
  3. for (int i = arr.length - 1; i > 0; i--) {
  4. E e = arr[i];
  5. if (Objects.equals(e, o)) {
  6. return i;
  7. }
  8. }
  9. return -1;
  10. }

代码示例来源:origin: skylot/jadx

  1. public JadxWarn(String warn) {
  2. this.warn = Objects.requireNonNull(warn);
  3. }

代码示例来源:origin: skylot/jadx

  1. @Override
  2. public int hashCode() {
  3. return Objects.hash(catchTypes, handleOffset /*, tryBlock*/);
  4. }

代码示例来源:origin: ctripcorp/apollo

  1. public boolean isClusterNameUnique(String appId, String clusterName) {
  2. Objects.requireNonNull(appId, "AppId must not be null");
  3. Objects.requireNonNull(clusterName, "ClusterName must not be null");
  4. return Objects.isNull(clusterRepository.findByAppIdAndName(appId, clusterName));
  5. }

代码示例来源:origin: square/okhttp

  1. @Override public int hashCode() {
  2. int result = 17;
  3. result = 31 * result + url.hashCode();
  4. result = 31 * result + dns.hashCode();
  5. result = 31 * result + proxyAuthenticator.hashCode();
  6. result = 31 * result + protocols.hashCode();
  7. result = 31 * result + connectionSpecs.hashCode();
  8. result = 31 * result + proxySelector.hashCode();
  9. result = 31 * result + Objects.hashCode(proxy);
  10. result = 31 * result + Objects.hashCode(sslSocketFactory);
  11. result = 31 * result + Objects.hashCode(hostnameVerifier);
  12. result = 31 * result + Objects.hashCode(certificatePinner);
  13. return result;
  14. }

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

  1. // These two have the same value
  2. new String("test").equals("test") // --> true
  3. // ... but they are not the same object
  4. new String("test") == "test" // --> false
  5. // ... neither are these
  6. new String("test") == new String("test") // --> false
  7. // ... but these are because literals are interned by
  8. // the compiler and thus refer to the same object
  9. "test" == "test" // --> true
  10. // ... but you should really just call Objects.equals()
  11. Objects.equals("test", new String("test")) // --> true
  12. Objects.equals(null, "test") // --> false

代码示例来源:origin: skylot/jadx

  1. public ImmutableList(E[] arr) {
  2. this.arr = Objects.requireNonNull(arr);
  3. }

代码示例来源:origin: jenkinsci/jenkins

  1. @Override
  2. public int hashCode() {
  3. return Objects.hash(userId);
  4. }
  5. }

代码示例来源:origin: ctripcorp/apollo

  1. public boolean isAppNamespaceNameUnique(String appId, String namespaceName) {
  2. Objects.requireNonNull(appId, "AppId must not be null");
  3. Objects.requireNonNull(namespaceName, "Namespace must not be null");
  4. return Objects.isNull(appNamespaceRepository.findByAppIdAndName(appId, namespaceName));
  5. }

代码示例来源:origin: org.apache.commons/commons-lang3

  1. /**
  2. * {@inheritDoc}
  3. */
  4. @Override
  5. public int hashCode() {
  6. int result = super.hashCode();
  7. result = HASH_SEED * result + Objects.hashCode(registry);
  8. result = HASH_SEED * result + Objects.hashCode(toPattern);
  9. return result;
  10. }

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

  1. @Override
  2. public boolean equals(Object o) {
  3. if (this == o) {
  4. return true;
  5. }
  6. if (o == null || getClass() != o.getClass()) {
  7. return false;
  8. }
  9. Entry entry = (Entry) o;
  10. return Objects.equals(this.metadata, entry.metadata) &&
  11. Objects.equals(this.importClassName, entry.importClassName);
  12. }

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

  1. public Builder(Map<ConfigResource, Config> configs, boolean validateOnly) {
  2. super(ApiKeys.ALTER_CONFIGS);
  3. this.configs = Objects.requireNonNull(configs, "configs");
  4. this.validateOnly = validateOnly;
  5. }

代码示例来源:origin: jenkinsci/jenkins

  1. /**
  2. * @since 1.515
  3. */
  4. @Override
  5. public int hashCode() {
  6. return Objects.hash(upstreamCauses, upstreamBuild, upstreamUrl, upstreamProject);
  7. }

相关文章