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

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new c49f9cc0e486 Add hashCode to EipAttribute and make equals and 
compareTo total (#29383)
c49f9cc0e486 is described below

commit c49f9cc0e48699713646ca6dd06ebfae04115ab3
Author: dhairya05 <[email protected]>
AuthorDate: Sun Nov 8 13:31:16 2026 +0530

    Add hashCode to EipAttribute and make equals and compareTo total (#29383)
    
    * Fix missing log argument in LuceneIndexAndQueryProducerIT
    * Add hashCode to EipAttribute and make equals and compareTo total
---
 .../camel/maven/htmlxlsx/model/EipAttribute.java   | 11 ++++-
 .../maven/htmlxlsx/model/EipAttributeTest.java     | 50 ++++++++++++++++++++++
 2 files changed, 59 insertions(+), 2 deletions(-)

diff --git 
a/catalog/camel-report-maven-plugin/src/main/java/org/apache/camel/maven/htmlxlsx/model/EipAttribute.java
 
b/catalog/camel-report-maven-plugin/src/main/java/org/apache/camel/maven/htmlxlsx/model/EipAttribute.java
index 77ab7af303e1..34f4a8825e45 100644
--- 
a/catalog/camel-report-maven-plugin/src/main/java/org/apache/camel/maven/htmlxlsx/model/EipAttribute.java
+++ 
b/catalog/camel-report-maven-plugin/src/main/java/org/apache/camel/maven/htmlxlsx/model/EipAttribute.java
@@ -20,6 +20,7 @@ import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Properties;
 
 import com.fasterxml.jackson.annotation.JsonAnyGetter;
@@ -155,7 +156,7 @@ public class EipAttribute implements 
Comparable<EipAttribute> {
         if (o == null) {
             return 1;
         }
-        return index - o.index;
+        return Integer.compare(index, o.index);
     }
 
     @Override
@@ -169,7 +170,13 @@ public class EipAttribute implements 
Comparable<EipAttribute> {
             return false;
         }
 
-        return id.equals(((EipAttribute) o).id);
+        return Objects.equals(id, ((EipAttribute) o).id);
+    }
+
+    @Override
+    public int hashCode() {
+
+        return Objects.hashCode(id);
     }
 
     @Override
diff --git 
a/catalog/camel-report-maven-plugin/src/test/java/org/apache/camel/maven/htmlxlsx/model/EipAttributeTest.java
 
b/catalog/camel-report-maven-plugin/src/test/java/org/apache/camel/maven/htmlxlsx/model/EipAttributeTest.java
index 46bdb9011d84..b16a0170e310 100644
--- 
a/catalog/camel-report-maven-plugin/src/test/java/org/apache/camel/maven/htmlxlsx/model/EipAttributeTest.java
+++ 
b/catalog/camel-report-maven-plugin/src/test/java/org/apache/camel/maven/htmlxlsx/model/EipAttributeTest.java
@@ -17,6 +17,8 @@
 package org.apache.camel.maven.htmlxlsx.model;
 
 import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
 
 import org.apache.camel.maven.htmlxlsx.TestUtil;
 import org.junit.jupiter.api.Test;
@@ -100,4 +102,52 @@ public class EipAttributeTest extends 
GetterAndSetterTest<EipAttribute> {
         result = attribute1.equals(attribute2);
         assertFalse(result);
     }
+
+    @Test
+    public void testEqualsWithoutId() {
+
+        // The id is only set when the deserialized key happens to be "id",
+        // so an attribute carrying any other key has a null id.
+        EipAttribute noId = new EipAttribute();
+        EipAttribute otherNoId = new EipAttribute();
+
+        assertEquals(noId, otherNoId);
+        assertNotEquals(noId, getInstance());
+        assertNotEquals(getInstance(), noId);
+    }
+
+    @Test
+    public void testHashCode() {
+
+        EipAttribute attribute1 = getInstance();
+        EipAttribute attribute2 = getInstance();
+
+        // Equal attributes must agree on their hash code, so that they
+        // collapse to one entry in a hash based collection.
+        assertEquals(attribute1, attribute2);
+        assertEquals(attribute1.hashCode(), attribute2.hashCode());
+
+        attribute2.setIndex(attribute1.getIndex() + 1);
+        assertEquals(attribute1.hashCode(), attribute2.hashCode());
+
+        Set<EipAttribute> set = new HashSet<>();
+        set.add(attribute1);
+        set.add(attribute2);
+        assertEquals(1, set.size());
+
+        assertEquals(new EipAttribute().hashCode(), new 
EipAttribute().hashCode());
+    }
+
+    @Test
+    public void testCompareToDoesNotOverflow() {
+
+        EipAttribute high = getInstance();
+        high.setIndex(Integer.MAX_VALUE);
+
+        EipAttribute low = getInstance();
+        low.setIndex(-1);
+
+        assertTrue(high.compareTo(low) > 0);
+        assertTrue(low.compareTo(high) < 0);
+    }
 }

Reply via email to