Skip to content

Commit 38b3f59

Browse files
committed
use Objects.equals()
1 parent 843730d commit 38b3f59

File tree

9 files changed

+26
-34
lines changed

9 files changed

+26
-34
lines changed

visualvm/caching.api/src/org/graalvm/visualvm/api/caching/Entry.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
*/
2525
package org.graalvm.visualvm.api.caching;
2626

27+
import java.util.Objects;
28+
2729
/**
2830
* Generic representation of a cache entry
2931
* Supports operations based on TTL (time-to-live)
@@ -88,7 +90,7 @@ public boolean equals(Object obj) {
8890
if (this.updateTs != other.updateTs) {
8991
return false;
9092
}
91-
if (this.object != other.object && (this.object == null || !this.object.equals(other.object))) {
93+
if (!Objects.equals(object, other.object)) {
9294
return false;
9395
}
9496
return true;

visualvm/caching.api/src/org/graalvm/visualvm/api/caching/impl/SoftReferenceEx.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import java.lang.ref.ReferenceQueue;
2929
import java.lang.ref.SoftReference;
30+
import java.util.Objects;
3031

3132
/**
3233
* Extended {@linkplain SoftReference} to allow euqals() and hashCode()
@@ -51,8 +52,7 @@ class SoftReferenceEx<T> extends SoftReference<T> {
5152
public boolean equals(Object obj) {
5253
if (!(obj instanceof SoftReferenceEx)) return false;
5354
SoftReferenceEx other = (SoftReferenceEx)obj;
54-
if (get() == null || other.get() == null) return false;
55-
return get().equals(other.get());
55+
return Objects.equals(get(), other.get());
5656
}
5757

5858
@Override

visualvm/caching.api/src/org/graalvm/visualvm/api/caching/impl/WeakReferenceEx.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import java.lang.ref.ReferenceQueue;
2929
import java.lang.ref.WeakReference;
30+
import java.util.Objects;
3031

3132
/**
3233
* Extended {@linkplain WeakReference} to allow euqals() and hashCode()
@@ -51,8 +52,7 @@ class WeakReferenceEx<T> extends WeakReference<T> {
5152
public boolean equals(Object obj) {
5253
if (!(obj instanceof WeakReferenceEx)) return false;
5354
WeakReferenceEx other = (WeakReferenceEx)obj;
54-
if (get() == null || other.get() == null) return false;
55-
return get().equals(other.get());
55+
return Objects.equals(get(), other.get());
5656
}
5757

5858
@Override

visualvm/core/src/org/graalvm/visualvm/core/datasupport/ComparableWeakReference.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import java.lang.ref.ReferenceQueue;
2828
import java.lang.ref.WeakReference;
29+
import java.util.Objects;
2930

3031
/**
3132
* WeakReference delegating hashCode() and equals(Object) methods to the referenced object.
@@ -71,9 +72,6 @@ public boolean equals(Object o) {
7172
if (!(o instanceof ComparableWeakReference)) {
7273
return false;
7374
}
74-
try {
75-
return this.get().equals(((ComparableWeakReference) o).get());
76-
} catch (Exception e) {}
77-
return false;
75+
return Objects.equals(get(), ((ComparableWeakReference) o).get());
7876
}
7977
}

visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/client/ClientUtils.java

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
package org.graalvm.visualvm.lib.jfluid.client;
2727

28+
import java.util.Objects;
2829
import java.util.regex.Pattern;
2930
import org.graalvm.visualvm.lib.jfluid.global.CommonConstants;
3031
import org.graalvm.visualvm.lib.jfluid.utils.formatting.DefaultMethodNameFormatter;
@@ -206,24 +207,11 @@ public boolean equals(Object obj) {
206207
// }
207208
if (!getNormalizedClassName().equals(other.getNormalizedClassName())) return false;
208209

209-
if (this.methodName != null) {
210-
if (!this.methodName.equals(other.methodName)) {
211-
return false;
212-
}
213-
} else {
214-
if (other.methodName != null) {
215-
return false;
216-
}
210+
if (!Objects.equals(methodName, other.methodName)) {
211+
return false;
217212
}
218-
219-
if (this.methodSignature != null) {
220-
if (!this.methodSignature.equals(other.methodSignature)) {
221-
return false;
222-
}
223-
} else {
224-
if (other.methodSignature != null) {
225-
return false;
226-
}
213+
if (!Objects.equals(methodSignature, other.methodSignature)) {
214+
return false;
227215
}
228216

229217
return true;

visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/results/cpu/StackTraceSnapshotBuilder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.List;
3535
import java.util.ListIterator;
3636
import java.util.Map;
37+
import java.util.Objects;
3738
import java.util.Set;
3839
import java.util.concurrent.atomic.AtomicReference;
3940
import org.graalvm.visualvm.lib.jfluid.filters.InstrumentationFilter;
@@ -157,10 +158,10 @@ public boolean equals(Object obj) {
157158
return false;
158159
}
159160
final MethodInfo other = (MethodInfo) obj;
160-
if ((className == null) ? (other.className != null) : !className.equals(other.className)) {
161+
if (!Objects.equals(className, other.className)) {
161162
return false;
162163
}
163-
if ((methodName == null) ? (other.methodName != null) : !methodName.equals(other.methodName)) {
164+
if (!Objects.equals(methodName, other.methodName)) {
164165
return false;
165166
}
166167
return true;

visualvm/libs.profiler/profiler.api/src/org/graalvm/visualvm/lib/profiler/api/java/SourceClassInfo.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
package org.graalvm.visualvm.lib.profiler.api.java;
2626

2727
import java.util.Comparator;
28+
import java.util.Objects;
2829
import java.util.Set;
2930
import java.util.regex.Pattern;
3031
import org.openide.filesystems.FileObject;
@@ -63,7 +64,7 @@ public boolean equals(Object obj) {
6364
return false;
6465
}
6566
final SourceClassInfo other = (SourceClassInfo) obj;
66-
if ((this.vmName == null) ? (other.vmName != null) : !this.vmName.equals(other.vmName)) {
67+
if (!Objects.equals(vmName, other.vmName)) {
6768
return false;
6869
}
6970
return true;

visualvm/libs.profiler/profiler.api/src/org/graalvm/visualvm/lib/profiler/api/java/SourceMethodInfo.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
package org.graalvm.visualvm.lib.profiler.api.java;
2626

2727
import java.lang.reflect.Modifier;
28+
import java.util.Objects;
2829

2930
/**
3031
* A simplified java method descriptor
@@ -56,13 +57,13 @@ public boolean equals(Object obj) {
5657
return false;
5758
}
5859
final SourceMethodInfo other = (SourceMethodInfo) obj;
59-
if ((this.className == null) ? (other.className != null) : !this.className.equals(other.className)) {
60+
if (!Objects.equals(className, other.className)) {
6061
return false;
6162
}
62-
if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
63+
if (!Objects.equals(name, other.name)) {
6364
return false;
6465
}
65-
if ((this.signature == null) ? (other.signature != null) : !this.signature.equals(other.signature)) {
66+
if (!Objects.equals(signature, other.signature)) {
6667
return false;
6768
}
6869
return true;

visualvm/libs.profiler/profiler.oql/src/org/graalvm/visualvm/lib/profiler/oql/engine/api/ReferenceChain.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
package org.graalvm.visualvm.lib.profiler.oql.engine.api;
2626

2727
import java.lang.ref.WeakReference;
28+
import java.util.Objects;
2829
import org.graalvm.visualvm.lib.jfluid.heap.Heap;
2930
import org.graalvm.visualvm.lib.jfluid.heap.Instance;
3031
import org.graalvm.visualvm.lib.jfluid.heap.JavaClass;
@@ -115,10 +116,10 @@ public boolean equals(Object obj) {
115116
return false;
116117
}
117118
final ReferenceChain other = (ReferenceChain) obj;
118-
if (this.obj != other.obj && (this.obj == null || !this.obj.equals(other.obj))) {
119+
if (!Objects.equals(obj, other.obj)) {
119120
return false;
120121
}
121-
if (this.next != other.next && (this.next == null || !this.next.equals(other.next))) {
122+
if (!Objects.equals(next, other.next)) {
122123
return false;
123124
}
124125
return true;

0 commit comments

Comments
 (0)