Skip to content

Commit

Permalink
Handle equals and hashCode delegating its calls to the InvocationHand…
Browse files Browse the repository at this point in the history
…ler objects

Signed-off-by: Steffen Nießing <[email protected]>
  • Loading branch information
zUniQueX authored and senivam committed May 10, 2023
1 parent 3381fe0 commit 99042d6
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -18,6 +18,7 @@

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.concurrent.atomic.AtomicBoolean;

import javax.ws.rs.client.Client;
Expand Down Expand Up @@ -56,6 +57,18 @@ public Object invoke(Object proxy, Method method, Object[] args) {
if (method.getName().equals("toString") && (args == null || args.length == 0)) {
return restClientModel.toString();
}

if (args == null && method.getName().equals("hashCode")) {
return hashCode();
}

if (args != null && args.length == 1 && method.getName().equals("equals")) {
if (!(args[0] instanceof Proxy)) {
return false;
}
return equals(Proxy.getInvocationHandler(args[0]));
}

if (method.getName().equals("close") && (args == null || args.length == 0)) {
closed.set(true);
if (null != client) {
Expand Down

0 comments on commit 99042d6

Please sign in to comment.