@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; }
@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; }
// 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
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; }
@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)); }
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; }
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()); }
@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); }
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(); }
/** Returns a certificate pinner that uses {@code certificateChainCleaner}. */ CertificatePinner withCertificateChainCleaner( @Nullable CertificateChainCleaner certificateChainCleaner) { return Objects.equals(this.certificateChainCleaner, certificateChainCleaner) ? this : new CertificatePinner(pins, certificateChainCleaner); }
/** * 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 + "'"); }
@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); }
@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()); }
@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()); }
@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()); }
@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()); }
@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()); }
/** * 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; }