本文整理了Java中java.util.Objects.equals()
方法的一些代码示例,展示了Objects.equals()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Objects.equals()
方法的具体详情如下:
包路径:java.util.Objects
类名称:Objects
方法名:equals
[英]Null-safe equivalent of a.equals(b).
[中]a.equals(b)的空安全等价物。
代码示例来源:origin: skylot/jadx
@Override
public int indexOf(Object o) {
int len = arr.length;
for (int i = 0; i < len; i++) {
E e = arr[i];
if (Objects.equals(e, o)) {
return i;
}
}
return -1;
}
代码示例来源:origin: skylot/jadx
@Override
public int lastIndexOf(Object o) {
for (int i = arr.length - 1; i > 0; i--) {
E e = arr[i];
if (Objects.equals(e, o)) {
return i;
}
}
return -1;
}
代码示例来源:origin: stackoverflow.com
// These two have the same value
new String("test").equals("test") // --> true
// ... but they are not the same object
new String("test") == "test" // --> false
// ... neither are these
new String("test") == new String("test") // --> false
// ... but these are because literals are interned by
// the compiler and thus refer to the same object
"test" == "test" // --> true
// ... but you should really just call Objects.equals()
Objects.equals("test", new String("test")) // --> true
Objects.equals(null, "test") // --> false
代码示例来源:origin: spring-projects/spring-framework
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Entry entry = (Entry) o;
return Objects.equals(this.metadata, entry.metadata) &&
Objects.equals(this.importClassName, entry.importClassName);
}
代码示例来源:origin: stackoverflow.com
public static <T, E> T getKeyByValue(Map<T, E> map, E value) {
for (Entry<T, E> entry : map.entrySet()) {
if (Objects.equals(value, entry.getValue())) {
return entry.getKey();
}
}
return null;
}
代码示例来源:origin: square/okhttp
@Override public boolean equals(@Nullable Object other) {
if (other == this) return true;
return other instanceof CertificatePinner
&& (Objects.equals(certificateChainCleaner,
((CertificatePinner) other).certificateChainCleaner)
&& pins.equals(((CertificatePinner) other).pins));
}
代码示例来源:origin: skylot/jadx
/**
* 'Hard' equals, compare all arguments
*/
public boolean isDeepEquals(InsnNode other) {
if (this == other) {
return true;
}
return isSame(other)
&& Objects.equals(result, other.result)
&& Objects.equals(arguments, other.arguments);
}
代码示例来源:origin: stackoverflow.com
public static <T, E> Set<T> getKeysByValue(Map<T, E> map, E value) {
Set<T> keys = new HashSet<T>();
for (Entry<T, E> entry : map.entrySet()) {
if (Objects.equals(value, entry.getValue())) {
keys.add(entry.getKey());
}
}
return keys;
}
代码示例来源:origin: stackoverflow.com
public static <T, E> Set<T> getKeysByValue(Map<T, E> map, E value) {
return map.entrySet()
.stream()
.filter(entry -> Objects.equals(entry.getValue(), value))
.map(Map.Entry::getKey)
.collect(Collectors.toSet());
}
代码示例来源:origin: skylot/jadx
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ExceptionHandler that = (ExceptionHandler) o;
return handleOffset == that.handleOffset &&
catchTypes.equals(that.catchTypes) &&
Objects.equals(tryBlock, that.tryBlock);
}
代码示例来源:origin: square/okhttp
boolean equalsNonHost(Address that) {
return this.dns.equals(that.dns)
&& this.proxyAuthenticator.equals(that.proxyAuthenticator)
&& this.protocols.equals(that.protocols)
&& this.connectionSpecs.equals(that.connectionSpecs)
&& this.proxySelector.equals(that.proxySelector)
&& Objects.equals(this.proxy, that.proxy)
&& Objects.equals(this.sslSocketFactory, that.sslSocketFactory)
&& Objects.equals(this.hostnameVerifier, that.hostnameVerifier)
&& Objects.equals(this.certificatePinner, that.certificatePinner)
&& this.url().port() == that.url().port();
}
代码示例来源:origin: square/okhttp
/** Returns a certificate pinner that uses {@code certificateChainCleaner}. */
CertificatePinner withCertificateChainCleaner(
@Nullable CertificateChainCleaner certificateChainCleaner) {
return Objects.equals(this.certificateChainCleaner, certificateChainCleaner)
? this
: new CertificatePinner(pins, certificateChainCleaner);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Return the {@link DataUnit} matching the specified {@code suffix}.
* @param suffix one of the standard suffix
* @return the {@link DataUnit} matching the specified {@code suffix}
* @throws IllegalArgumentException if the suffix does not match any
* of this enum's constants
*/
public static DataUnit fromSuffix(String suffix) {
for (DataUnit candidate : values()) {
if (Objects.equals(candidate.suffix, suffix)) {
return candidate;
}
}
throw new IllegalArgumentException("Unknown unit '" + suffix + "'");
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ConstructorDependency that = (ConstructorDependency) o;
return spouseAge == that.spouseAge &&
Objects.equals(spouse, that.spouse) &&
Objects.equals(beanName, that.beanName);
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof ServiceDefinition)) {
return false;
}
ServiceDefinition that = (ServiceDefinition) o;
return Objects.equals(getCanonicalName(), that.getCanonicalName()) &&
Objects.equals(getCodeSource(), that.getCodeSource()) &&
Objects.equals(getMethods(), that.getMethods()) &&
Objects.equals(getTypes(), that.getTypes());
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof ServiceDefinition)) {
return false;
}
ServiceDefinition that = (ServiceDefinition) o;
return Objects.equals(getCanonicalName(), that.getCanonicalName()) &&
Objects.equals(getCodeSource(), that.getCodeSource()) &&
Objects.equals(getMethods(), that.getMethods()) &&
Objects.equals(getTypes(), that.getTypes());
}
代码示例来源:origin: skylot/jadx
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof RegisterArg)) {
return false;
}
RegisterArg other = (RegisterArg) obj;
return regNum == other.regNum
&& type.equals(other.type)
&& Objects.equals(sVar, other.getSVar());
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof MethodDefinition)) {
return false;
}
MethodDefinition that = (MethodDefinition) o;
return Objects.equals(getName(), that.getName()) &&
Arrays.equals(getParameterTypes(), that.getParameterTypes()) &&
Objects.equals(getReturnType(), that.getReturnType()) &&
Objects.equals(getParameters(), that.getParameters());
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof MethodDefinition)) {
return false;
}
MethodDefinition that = (MethodDefinition) o;
return Objects.equals(getName(), that.getName()) &&
Arrays.equals(getParameterTypes(), that.getParameterTypes()) &&
Objects.equals(getReturnType(), that.getReturnType()) &&
Objects.equals(getParameters(), that.getParameters());
}
代码示例来源:origin: square/okhttp
/**
* Returns true if none of the Vary headers have changed between {@code cachedRequest} and {@code
* newRequest}.
*/
public static boolean varyMatches(
Response cachedResponse, Headers cachedRequest, Request newRequest) {
for (String field : varyFields(cachedResponse)) {
if (!Objects.equals(cachedRequest.values(field), newRequest.headers(field))) return false;
}
return true;
}
内容来源于网络,如有侵权,请联系作者删除!