This is an automated email from the ASF dual-hosted git repository.

tabish121 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-protonj2.git


The following commit(s) were added to refs/heads/main by this push:
     new 5d829741 PROTON-2925 Clean up some equals methods in various types
5d829741 is described below

commit 5d829741083481f1a1eaf1115ec3f3a042268553
Author: Timothy Bish <[email protected]>
AuthorDate: Fri Aug 7 16:13:22 2026 -0400

    PROTON-2925 Clean up some equals methods in various types
    
    Clean up some of the equals methods in various types
---
 .../org/apache/qpid/protonj2/types/Binary.java     | 20 ++++++-----------
 .../org/apache/qpid/protonj2/types/Decimal128.java | 17 +++++----------
 .../org/apache/qpid/protonj2/types/Decimal32.java  | 11 +++-------
 .../org/apache/qpid/protonj2/types/Decimal64.java  | 11 +++-------
 .../qpid/protonj2/types/UnknownDescribedType.java  | 19 ++++++++--------
 .../apache/qpid/protonj2/types/UnsignedByte.java   | 11 +++-------
 .../qpid/protonj2/types/UnsignedInteger.java       | 11 +++-------
 .../apache/qpid/protonj2/types/UnsignedLong.java   | 11 +++-------
 .../apache/qpid/protonj2/types/UnsignedShort.java  | 12 +++--------
 .../protonj2/types/messaging/AmqpSequence.java     | 19 ++++++----------
 .../qpid/protonj2/types/messaging/AmqpValue.java   | 19 ++++++----------
 .../types/messaging/ApplicationProperties.java     | 19 ++++++----------
 .../apache/qpid/protonj2/types/messaging/Data.java | 17 ++++++---------
 .../types/messaging/DeliveryAnnotations.java       | 19 ++++++----------
 .../qpid/protonj2/types/messaging/Footer.java      | 19 ++++++----------
 .../types/messaging/MessageAnnotations.java        | 19 ++++++----------
 .../qpid/protonj2/types/transport/AMQPHeader.java  | 19 ++++++----------
 .../protonj2/types/transport/ErrorCondition.java   | 25 +++++++++++-----------
 .../protonj2/engine/impl/ProtonReceiverTest.java   |  1 +
 19 files changed, 101 insertions(+), 198 deletions(-)

diff --git a/protonj2/src/main/java/org/apache/qpid/protonj2/types/Binary.java 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/Binary.java
index f764c8fb..d28d09ec 100644
--- a/protonj2/src/main/java/org/apache/qpid/protonj2/types/Binary.java
+++ b/protonj2/src/main/java/org/apache/qpid/protonj2/types/Binary.java
@@ -124,8 +124,7 @@ public final class Binary {
     public final int hashCode() {
         int hc = hashCode;
         if (hc == 0 && buffer != null) {
-            hc = buffer.hashCode();
-            hashCode = hc;
+            hc = hashCode = buffer.hashCode();
         }
         return hc;
     }
@@ -136,20 +135,15 @@ public final class Binary {
             return true;
         }
 
-        if (o == null || getClass() != o.getClass()) {
-            return false;
-        }
-
-        Binary other = (Binary) o;
-        if (getLength() != other.getLength()) {
-            return false;
-        }
+        if (o instanceof Binary other) {
+            if (buffer == null) {
+                return other.buffer == null;
+            }
 
-        if (buffer == null) {
-            return other.buffer == null;
+            return buffer.equals(other.buffer);
         }
 
-        return buffer.equals(other.buffer);
+        return false;
     }
 
     public int getLength() {
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/types/Decimal128.java 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/Decimal128.java
index ea7aacf7..7017feca 100644
--- a/protonj2/src/main/java/org/apache/qpid/protonj2/types/Decimal128.java
+++ b/protonj2/src/main/java/org/apache/qpid/protonj2/types/Decimal128.java
@@ -116,20 +116,13 @@ public final class Decimal128 extends Number {
             return true;
         }
 
-        if (o == null || getClass() != o.getClass()) {
-            return false;
+        if (o instanceof Decimal128 other) {
+            if (lsb == other.lsb && msb == other.msb) {
+                return true;
+            }
         }
 
-        final Decimal128 that = (Decimal128) o;
-
-        if (lsb != that.lsb) {
-            return false;
-        }
-        if (msb != that.msb) {
-            return false;
-        }
-
-        return true;
+        return false;
     }
 
     @Override
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/types/Decimal32.java 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/Decimal32.java
index f721c5bf..a8321ffd 100644
--- a/protonj2/src/main/java/org/apache/qpid/protonj2/types/Decimal32.java
+++ b/protonj2/src/main/java/org/apache/qpid/protonj2/types/Decimal32.java
@@ -85,17 +85,12 @@ public final class Decimal32 extends Number {
         if (this == o) {
             return true;
         }
-        if (o == null || getClass() != o.getClass()) {
-            return false;
-        }
-
-        final Decimal32 decimal32 = (Decimal32) o;
 
-        if (bits != decimal32.bits) {
-            return false;
+        if (o instanceof Decimal32 other) {
+            return bits == other.bits;
         }
 
-        return true;
+        return false;
     }
 
     @Override
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/types/Decimal64.java 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/Decimal64.java
index 00e66a0f..935cebd7 100644
--- a/protonj2/src/main/java/org/apache/qpid/protonj2/types/Decimal64.java
+++ b/protonj2/src/main/java/org/apache/qpid/protonj2/types/Decimal64.java
@@ -85,17 +85,12 @@ public final class Decimal64 extends Number {
         if (this == o) {
             return true;
         }
-        if (o == null || getClass() != o.getClass()) {
-            return false;
-        }
-
-        final Decimal64 decimal64 = (Decimal64) o;
 
-        if (bits != decimal64.bits) {
-            return false;
+        if (o instanceof Decimal64 other) {
+            return bits == other.bits;
         }
 
-        return true;
+        return false;
     }
 
     @Override
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/types/UnknownDescribedType.java
 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/UnknownDescribedType.java
index 4ced7b6b..929416f4 100644
--- 
a/protonj2/src/main/java/org/apache/qpid/protonj2/types/UnknownDescribedType.java
+++ 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/UnknownDescribedType.java
@@ -56,20 +56,19 @@ public class UnknownDescribedType implements DescribedType {
         if (this == o) {
             return true;
         }
-        if (o == null || getClass() != o.getClass()) {
-            return false;
-        }
 
-        final UnknownDescribedType that = (UnknownDescribedType) o;
+        if (o instanceof UnknownDescribedType other) {
+            if (described != null ? !described.equals(other.described) : 
other.described != null) {
+                return false;
+            }
+            if (descriptor != null ? !descriptor.equals(other.descriptor) : 
other.descriptor != null) {
+                return false;
+            }
 
-        if (described != null ? !described.equals(that.described) : 
that.described != null) {
-            return false;
-        }
-        if (descriptor != null ? !descriptor.equals(that.descriptor) : 
that.descriptor != null) {
-            return false;
+            return true;
         }
 
-        return true;
+        return false;
     }
 
     @Override
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/types/UnsignedByte.java 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/UnsignedByte.java
index 4fd6fec4..dcd58e49 100644
--- a/protonj2/src/main/java/org/apache/qpid/protonj2/types/UnsignedByte.java
+++ b/protonj2/src/main/java/org/apache/qpid/protonj2/types/UnsignedByte.java
@@ -70,17 +70,12 @@ public final class UnsignedByte extends Number implements 
Comparable<UnsignedByt
         if (this == o) {
             return true;
         }
-        if (o == null || getClass() != o.getClass()) {
-            return false;
-        }
-
-        UnsignedByte that = (UnsignedByte) o;
 
-        if (underlying != that.underlying) {
-            return false;
+        if (o instanceof UnsignedByte other) {
+            return underlying == other.underlying;
         }
 
-        return true;
+        return false;
     }
 
     /**
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/types/UnsignedInteger.java 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/UnsignedInteger.java
index 6fcfe51b..aa4c01d9 100644
--- a/protonj2/src/main/java/org/apache/qpid/protonj2/types/UnsignedInteger.java
+++ b/protonj2/src/main/java/org/apache/qpid/protonj2/types/UnsignedInteger.java
@@ -62,17 +62,12 @@ public final class UnsignedInteger extends Number 
implements Comparable<Unsigned
         if (this == o) {
             return true;
         }
-        if (o == null || getClass() != o.getClass()) {
-            return false;
-        }
-
-        UnsignedInteger that = (UnsignedInteger) o;
 
-        if (underlying != that.underlying) {
-            return false;
+        if (o instanceof UnsignedInteger other) {
+            return underlying == other.underlying;
         }
 
-        return true;
+        return false;
     }
 
     /**
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/types/UnsignedLong.java 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/UnsignedLong.java
index d38d8af7..00ef040b 100644
--- a/protonj2/src/main/java/org/apache/qpid/protonj2/types/UnsignedLong.java
+++ b/protonj2/src/main/java/org/apache/qpid/protonj2/types/UnsignedLong.java
@@ -76,17 +76,12 @@ public final class UnsignedLong extends Number implements 
Comparable<UnsignedLon
         if (this == o) {
             return true;
         }
-        if (o == null || getClass() != o.getClass()) {
-            return false;
-        }
-
-        UnsignedLong that = (UnsignedLong) o;
 
-        if (underlying != that.underlying) {
-            return false;
+        if (o instanceof UnsignedLong other) {
+            return underlying == other.underlying;
         }
 
-        return true;
+        return false;
     }
 
     /**
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/types/UnsignedShort.java 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/UnsignedShort.java
index cb27b500..173a4005 100644
--- a/protonj2/src/main/java/org/apache/qpid/protonj2/types/UnsignedShort.java
+++ b/protonj2/src/main/java/org/apache/qpid/protonj2/types/UnsignedShort.java
@@ -66,17 +66,11 @@ public final class UnsignedShort extends Number implements 
Comparable<UnsignedSh
             return true;
         }
 
-        if (o == null || getClass() != o.getClass()) {
-            return false;
+        if (o instanceof UnsignedShort other) {
+            return underlying == other.underlying;
         }
 
-        UnsignedShort that = (UnsignedShort) o;
-
-        if (underlying != that.underlying) {
-            return false;
-        }
-
-        return true;
+        return false;
     }
 
     /**
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/AmqpSequence.java
 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/AmqpSequence.java
index 36ee0edf..98103cde 100644
--- 
a/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/AmqpSequence.java
+++ 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/AmqpSequence.java
@@ -65,22 +65,15 @@ public final class AmqpSequence<E> implements 
Section<List<E>> {
         if (this == obj) {
             return true;
         }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
 
-        AmqpSequence<?> other = (AmqpSequence<?>) obj;
-        if (value == null) {
-            if (other.value != null) {
-                return false;
+        if (obj instanceof AmqpSequence other) {
+            if (value == null) {
+                return other.value == null;
             }
-        } else if (!value.equals(other.value)) {
-            return false;
+
+            return value.equals(other.value);
         }
 
-        return true;
+        return false;
     }
 }
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/AmqpValue.java
 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/AmqpValue.java
index d2bd26d3..d030849b 100644
--- 
a/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/AmqpValue.java
+++ 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/AmqpValue.java
@@ -62,22 +62,15 @@ public final class AmqpValue<E> implements Section<E> {
         if (this == obj) {
             return true;
         }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
 
-        AmqpValue<?> other = (AmqpValue<?>) obj;
-        if (value == null) {
-            if (other.value != null) {
-                return false;
+        if (obj instanceof AmqpValue other) {
+            if (value == null) {
+                return other.value == null;
             }
-        } else if (!value.equals(other.value)) {
-            return false;
+
+            return value.equals(other.value);
         }
 
-        return true;
+        return false;
     }
 }
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/ApplicationProperties.java
 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/ApplicationProperties.java
index d3e408d5..fef807ac 100644
--- 
a/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/ApplicationProperties.java
+++ 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/ApplicationProperties.java
@@ -66,22 +66,15 @@ public final class ApplicationProperties implements 
Section<Map<String, Object>>
         if (this == obj) {
             return true;
         }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
 
-        ApplicationProperties other = (ApplicationProperties) obj;
-        if (value == null) {
-            if (other.value != null) {
-                return false;
+        if (obj instanceof ApplicationProperties other) {
+            if (value == null) {
+                return other.value == null;
             }
-        } else if (!value.equals(other.value)) {
-            return false;
+
+            return value.equals(other.value);
         }
 
-        return true;
+        return false;
     }
 }
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/Data.java 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/Data.java
index 19e7b8fa..2ecb5cc4 100644
--- a/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/Data.java
+++ b/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/Data.java
@@ -165,18 +165,15 @@ public final class Data implements Section<byte[]> {
         if (this == obj) {
             return true;
         }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
 
-        Data other = (Data) obj;
-        if (buffer == null) {
-            return other.buffer == null;
+        if (obj instanceof Data other) {
+            if (buffer == null) {
+                return other.buffer == null;
+            }
+
+            return buffer.equals(other.buffer);
         }
 
-        return buffer.equals(other.buffer);
+        return false;
     }
 }
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/DeliveryAnnotations.java
 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/DeliveryAnnotations.java
index f0d2cd85..0339fcd1 100644
--- 
a/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/DeliveryAnnotations.java
+++ 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/DeliveryAnnotations.java
@@ -66,22 +66,15 @@ public final class DeliveryAnnotations implements 
Section<Map<Symbol, Object>> {
         if (this == obj) {
             return true;
         }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
 
-        DeliveryAnnotations other = (DeliveryAnnotations) obj;
-        if (value == null) {
-            if (other.value != null) {
-                return false;
+        if (obj instanceof DeliveryAnnotations other) {
+            if (value == null) {
+                return other.value == null;
             }
-        } else if (!value.equals(other.value)) {
-            return false;
+
+            return value.equals(other.value);
         }
 
-        return true;
+        return false;
     }
 }
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/Footer.java 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/Footer.java
index ff1c2d96..60f99fc3 100644
--- 
a/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/Footer.java
+++ 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/Footer.java
@@ -66,22 +66,15 @@ public final class Footer implements Section<Map<Symbol, 
Object>> {
         if (this == obj) {
             return true;
         }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
 
-        Footer other = (Footer) obj;
-        if (value == null) {
-            if (other.value != null) {
-                return false;
+        if (obj instanceof Footer other) {
+            if (value == null) {
+                return other.value == null;
             }
-        } else if (!value.equals(other.value)) {
-            return false;
+
+            return value.equals(other.value);
         }
 
-        return true;
+        return false;
     }
 }
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/MessageAnnotations.java
 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/MessageAnnotations.java
index 9fddadee..0ba7244c 100644
--- 
a/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/MessageAnnotations.java
+++ 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/MessageAnnotations.java
@@ -66,22 +66,15 @@ public final class MessageAnnotations implements 
Section<Map<Symbol, Object>> {
         if (this == obj) {
             return true;
         }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
 
-        MessageAnnotations other = (MessageAnnotations) obj;
-        if (value == null) {
-            if (other.value != null) {
-                return false;
+        if (obj instanceof MessageAnnotations other) {
+            if (value == null) {
+                return other.value == null;
             }
-        } else if (!value.equals(other.value)) {
-            return false;
+
+            return value.equals(other.value);
         }
 
-        return true;
+        return false;
     }
 }
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/types/transport/AMQPHeader.java
 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/transport/AMQPHeader.java
index 620c1def..dab4d66f 100644
--- 
a/protonj2/src/main/java/org/apache/qpid/protonj2/types/transport/AMQPHeader.java
+++ 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/transport/AMQPHeader.java
@@ -136,23 +136,16 @@ public final class AMQPHeader {
         if (this == obj) {
             return true;
         }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
 
-        AMQPHeader other = (AMQPHeader) obj;
-        if (buffer == null) {
-            if (other.buffer != null) {
-                return false;
+        if (obj instanceof AMQPHeader other) {
+            if (buffer == null) {
+                return other.buffer == null;
             }
-        } else if (!buffer.equals(other.buffer)) {
-            return false;
+
+            return buffer.equals(other.buffer);
         }
 
-        return true;
+        return false;
     }
 
     @Override
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/types/transport/ErrorCondition.java
 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/transport/ErrorCondition.java
index f477d179..a1eea2f3 100644
--- 
a/protonj2/src/main/java/org/apache/qpid/protonj2/types/transport/ErrorCondition.java
+++ 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/transport/ErrorCondition.java
@@ -108,23 +108,22 @@ public final class ErrorCondition {
         if (this == o) {
             return true;
         }
-        if (o == null || getClass() != o.getClass()) {
-            return false;
-        }
 
-        ErrorCondition that = (ErrorCondition) o;
+        if (o instanceof ErrorCondition other) {
+            if (condition != null ? !condition.equals(other.condition) : 
other.condition != null) {
+                return false;
+            }
+            if (description != null ? !description.equals(other.description) : 
other.description != null) {
+                return false;
+            }
+            if (info != null ? !info.equals(other.info) : other.info != null) {
+                return false;
+            }
 
-        if (condition != null ? !condition.equals(that.condition) : 
that.condition != null) {
-            return false;
-        }
-        if (description != null ? !description.equals(that.description) : 
that.description != null) {
-            return false;
-        }
-        if (info != null ? !info.equals(that.info) : that.info != null) {
-            return false;
+            return true;
         }
 
-        return true;
+        return false;
     }
 
     @Override
diff --git 
a/protonj2/src/test/java/org/apache/qpid/protonj2/engine/impl/ProtonReceiverTest.java
 
b/protonj2/src/test/java/org/apache/qpid/protonj2/engine/impl/ProtonReceiverTest.java
index 8b2880ee..4c930c5b 100644
--- 
a/protonj2/src/test/java/org/apache/qpid/protonj2/engine/impl/ProtonReceiverTest.java
+++ 
b/protonj2/src/test/java/org/apache/qpid/protonj2/engine/impl/ProtonReceiverTest.java
@@ -4789,6 +4789,7 @@ public class ProtonReceiverTest extends 
ProtonEngineTestSupport {
         assertNull(failure);
     }
 
+    @Test
     public void testFailureOnViolationOfPerDeliveryTransferLimit() throws 
Exception {
         Engine engine = EngineFactory.PROTON.createNonSaslEngine();
         engine.errorHandler(result -> failure = result.failureCause());


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to