You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by gg...@apache.org on 2022/08/25 12:36:04 UTC
[httpcomponents-core] 02/02: Deprecate org.apache.hc.core5.util.LangUtils.equals(Object, Object) in favor or java.util.Objects.equals(Object, Object).
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git
commit 06c480b0fd15bc78781bf6505e4a5d0f8eb09905
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Aug 25 08:35:54 2022 -0400
Deprecate org.apache.hc.core5.util.LangUtils.equals(Object, Object) in
favor or java.util.Objects.equals(Object, Object).
---
RELEASE_NOTES.txt | 1 +
.../main/java/org/apache/hc/core5/http2/hpack/HPackEncoder.java | 4 ++--
httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java | 3 ++-
.../java/org/apache/hc/core5/http/message/BasicNameValuePair.java | 3 ++-
.../main/java/org/apache/hc/core5/http/message/HeaderGroup.java | 4 ++--
httpcore5/src/main/java/org/apache/hc/core5/net/URIAuthority.java | 5 +++--
httpcore5/src/main/java/org/apache/hc/core5/pool/LaxConnPool.java | 4 ++--
.../src/main/java/org/apache/hc/core5/pool/StrictConnPool.java | 4 ++--
httpcore5/src/main/java/org/apache/hc/core5/util/LangUtils.java | 2 ++
.../src/test/java/org/apache/hc/core5/http/HeaderMatcher.java | 5 +++--
.../src/test/java/org/apache/hc/core5/http/HeadersMatcher.java | 5 +++--
.../java/org/apache/hc/core5/http/NameValuePairListMatcher.java | 6 +++---
.../src/test/java/org/apache/hc/core5/util/TestLangUtils.java | 8 +++++---
13 files changed, 32 insertions(+), 22 deletions(-)
diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt
index 4aaf4ef6e..92f2b5439 100644
--- a/RELEASE_NOTES.txt
+++ b/RELEASE_NOTES.txt
@@ -2,6 +2,7 @@ Release 5.2 BETA3
------------------
* Deprecate org.apache.hc.core5.util.LangUtils.equals(Object[], Object[]) in favor or java.util.Arrays.equals(Object[], Object[]).
+* Deprecate org.apache.hc.core5.util.LangUtils.equals(Object, Object) in favor or java.util.Objects.equals(Object, Object).
Release 5.2 BETA2
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/hpack/HPackEncoder.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/hpack/HPackEncoder.java
index c58218792..b64b27a51 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/hpack/HPackEncoder.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/hpack/HPackEncoder.java
@@ -35,12 +35,12 @@ import java.nio.charset.CharsetEncoder;
import java.nio.charset.CoderResult;
import java.nio.charset.StandardCharsets;
import java.util.List;
+import java.util.Objects;
import org.apache.hc.core5.annotation.Internal;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.util.Args;
import org.apache.hc.core5.util.ByteArrayBuffer;
-import org.apache.hc.core5.util.LangUtils;
/**
* HPACK encoder.
@@ -245,7 +245,7 @@ public final class HPackEncoder {
}
for (int i = 0; i < entries.size(); i++) {
final HPackEntry entry = entries.get(i);
- if (LangUtils.equals(value, entry.getHeader().getValue())) {
+ if (Objects.equals(value, entry.getHeader().getValue())) {
return entry.getIndex();
}
}
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java b/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java
index 97baf76cf..52938cddb 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java
@@ -31,6 +31,7 @@ import java.io.Serializable;
import java.net.InetAddress;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.Objects;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
@@ -333,7 +334,7 @@ public final class HttpHost implements NamedEndpoint, Serializable {
final HttpHost that = (HttpHost) obj;
return this.schemeName.equals(that.schemeName) &&
this.host.equals(that.host) &&
- LangUtils.equals(this.address, that.address);
+ Objects.equals(this.address, that.address);
}
return false;
}
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/message/BasicNameValuePair.java b/httpcore5/src/main/java/org/apache/hc/core5/http/message/BasicNameValuePair.java
index b121cf2fb..ff21d4b3d 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/message/BasicNameValuePair.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/message/BasicNameValuePair.java
@@ -28,6 +28,7 @@
package org.apache.hc.core5.http.message;
import java.io.Serializable;
+import java.util.Objects;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
@@ -93,7 +94,7 @@ public class BasicNameValuePair implements NameValuePair, Serializable {
}
if (obj instanceof BasicNameValuePair) {
final BasicNameValuePair that = (BasicNameValuePair) obj;
- return this.name.equalsIgnoreCase(that.name) && LangUtils.equals(this.value, that.value);
+ return this.name.equalsIgnoreCase(that.name) && Objects.equals(this.value, that.value);
}
return false;
}
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/message/HeaderGroup.java b/httpcore5/src/main/java/org/apache/hc/core5/http/message/HeaderGroup.java
index 465f963d9..072ea7ca5 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/message/HeaderGroup.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/message/HeaderGroup.java
@@ -32,12 +32,12 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import java.util.Objects;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.MessageHeaders;
import org.apache.hc.core5.http.ProtocolException;
import org.apache.hc.core5.util.CharArrayBuffer;
-import org.apache.hc.core5.util.LangUtils;
import org.apache.hc.core5.util.TextUtils;
/**
@@ -105,7 +105,7 @@ public class HeaderGroup implements MessageHeaders, Serializable {
private boolean headerEquals(final Header header1, final Header header2) {
return header2 == header1 || header2.getName().equalsIgnoreCase(header1.getName())
- && LangUtils.equals(header1.getValue(), header2.getValue());
+ && Objects.equals(header1.getValue(), header2.getValue());
}
/**
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/net/URIAuthority.java b/httpcore5/src/main/java/org/apache/hc/core5/net/URIAuthority.java
index 5fa2553d4..a9fed758c 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/net/URIAuthority.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/net/URIAuthority.java
@@ -29,6 +29,7 @@ package org.apache.hc.core5.net;
import java.io.Serializable;
import java.net.URISyntaxException;
+import java.util.Objects;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
@@ -179,8 +180,8 @@ public final class URIAuthority implements NamedEndpoint, Serializable {
}
if (obj instanceof URIAuthority) {
final URIAuthority that = (URIAuthority) obj;
- return LangUtils.equals(this.userInfo, that.userInfo) &&
- LangUtils.equals(this.host, that.host);
+ return Objects.equals(this.userInfo, that.userInfo) &&
+ Objects.equals(this.host, that.host);
}
return false;
}
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/pool/LaxConnPool.java b/httpcore5/src/main/java/org/apache/hc/core5/pool/LaxConnPool.java
index f14a998e9..4a40470ee 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/pool/LaxConnPool.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/pool/LaxConnPool.java
@@ -29,6 +29,7 @@ package org.apache.hc.core5.pool;
import java.util.Deque;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedDeque;
@@ -55,7 +56,6 @@ import org.apache.hc.core5.util.Args;
import org.apache.hc.core5.util.Asserts;
import org.apache.hc.core5.util.Deadline;
import org.apache.hc.core5.util.DeadlineTimeoutException;
-import org.apache.hc.core5.util.LangUtils;
import org.apache.hc.core5.util.TimeValue;
import org.apache.hc.core5.util.Timeout;
@@ -445,7 +445,7 @@ public class LaxConnPool<T, C extends ModalCloseable> implements ManagedConnPool
if (entry.getExpiryDeadline().isExpired()) {
entry.discardConnection(CloseMode.GRACEFUL);
}
- if (!LangUtils.equals(entry.getState(), state)) {
+ if (!Objects.equals(entry.getState(), state)) {
entry.discardConnection(CloseMode.GRACEFUL);
}
return entry;
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/pool/StrictConnPool.java b/httpcore5/src/main/java/org/apache/hc/core5/pool/StrictConnPool.java
index 93e1b3193..9801cf82e 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/pool/StrictConnPool.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/pool/StrictConnPool.java
@@ -32,6 +32,7 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutionException;
@@ -53,7 +54,6 @@ import org.apache.hc.core5.util.Args;
import org.apache.hc.core5.util.Asserts;
import org.apache.hc.core5.util.Deadline;
import org.apache.hc.core5.util.DeadlineTimeoutException;
-import org.apache.hc.core5.util.LangUtils;
import org.apache.hc.core5.util.TimeValue;
import org.apache.hc.core5.util.Timeout;
@@ -531,7 +531,7 @@ public class StrictConnPool<T, C extends ModalCloseable> implements ManagedConnP
final PerRoutePool<T, C> pool = getPool(route);
int pendingCount = 0;
for (final LeaseRequest<T, C> request: pendingRequests) {
- if (LangUtils.equals(route, request.getRoute())) {
+ if (Objects.equals(route, request.getRoute())) {
pendingCount++;
}
}
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/util/LangUtils.java b/httpcore5/src/main/java/org/apache/hc/core5/util/LangUtils.java
index eca1b7f16..48b9d095d 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/util/LangUtils.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/util/LangUtils.java
@@ -64,7 +64,9 @@ public final class LangUtils {
* @param obj1 first object to compare, may be {@code null}
* @param obj2 second object to compare, may be {@code null}
* @return {@code true} if the objects are equal or both null
+ * @deprecated Use {@link Objects#equals(Object)}.
*/
+ @Deprecated
public static boolean equals(final Object obj1, final Object obj2) {
return Objects.equals(obj1, obj2);
}
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/HeaderMatcher.java b/httpcore5/src/test/java/org/apache/hc/core5/http/HeaderMatcher.java
index 31b247ffe..df7e04865 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/HeaderMatcher.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/HeaderMatcher.java
@@ -26,7 +26,8 @@
*/
package org.apache.hc.core5.http;
-import org.apache.hc.core5.util.LangUtils;
+import java.util.Objects;
+
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
@@ -45,7 +46,7 @@ public class HeaderMatcher extends BaseMatcher<Header> {
public boolean matches(final Object item) {
if (item instanceof Header) {
final Header header = (Header) item;
- if (headerName.equalsIgnoreCase(header.getName()) && LangUtils.equals(headerValue, header.getValue())) {
+ if (headerName.equalsIgnoreCase(header.getName()) && Objects.equals(headerValue, header.getValue())) {
return true;
}
}
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/HeadersMatcher.java b/httpcore5/src/test/java/org/apache/hc/core5/http/HeadersMatcher.java
index d958d6e93..b4108428f 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/HeadersMatcher.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/HeadersMatcher.java
@@ -26,7 +26,8 @@
*/
package org.apache.hc.core5.http;
-import org.apache.hc.core5.util.LangUtils;
+import java.util.Objects;
+
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
@@ -48,7 +49,7 @@ public class HeadersMatcher extends BaseMatcher<Header[]> {
final Header h1 = headers[i];
final Header h2 = expectedHeaders[i];
if (!h1.getName().equalsIgnoreCase(h2.getName())
- || !LangUtils.equals(h1.getValue(), h2.getValue())) {
+ || !Objects.equals(h1.getValue(), h2.getValue())) {
return false;
}
}
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/NameValuePairListMatcher.java b/httpcore5/src/test/java/org/apache/hc/core5/http/NameValuePairListMatcher.java
index 4600c4f21..b802e8d82 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/NameValuePairListMatcher.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/NameValuePairListMatcher.java
@@ -29,8 +29,8 @@ package org.apache.hc.core5.http;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.Objects;
-import org.apache.hc.core5.util.LangUtils;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
@@ -55,8 +55,8 @@ public class NameValuePairListMatcher extends BaseMatcher<List<NameValuePair>> {
if (obj instanceof NameValuePair) {
final NameValuePair nvp = (NameValuePair) obj;
final NameValuePair expected = nvps.get(i);
- if (!LangUtils.equals(nvp.getName(), expected.getName())
- || !LangUtils.equals(nvp.getValue(), expected.getValue())) {
+ if (!Objects.equals(nvp.getName(), expected.getName())
+ || !Objects.equals(nvp.getValue(), expected.getValue())) {
return false;
}
}
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/util/TestLangUtils.java b/httpcore5/src/test/java/org/apache/hc/core5/util/TestLangUtils.java
index f7e05595e..5a0f2072e 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/util/TestLangUtils.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/util/TestLangUtils.java
@@ -27,6 +27,8 @@
package org.apache.hc.core5.util;
+import java.util.Objects;
+
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@@ -65,9 +67,9 @@ public class TestLangUtils {
@Test
public void testBasicEquality() {
Assertions.assertTrue(LangUtils.equals(null, null));
- Assertions.assertFalse(LangUtils.equals(null, "abc"));
- Assertions.assertFalse(LangUtils.equals("abc", null));
- Assertions.assertTrue(LangUtils.equals("abc", "abc"));
+ Assertions.assertFalse(Objects.equals(null, "abc"));
+ Assertions.assertFalse(Objects.equals("abc", null));
+ Assertions.assertTrue(Objects.equals("abc", "abc"));
}
@Test