Skip to content

Commit

Permalink
Merge pull request #333 from Ladicek/annotation-equivalence-hash-code
Browse files Browse the repository at this point in the history
Add AnnotationInstance.equivalenceHashCode()
  • Loading branch information
Ladicek authored Sep 25, 2023
2 parents 3fa7a6c + 597e8e0 commit 310da1e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions core/src/main/java/org/jboss/jandex/AnnotationInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -515,4 +515,16 @@ public boolean equivalentTo(AnnotationInstance other) {

return name.equals(other.name) && Arrays.equals(values, other.values);
}

/**
* Returns an equivalence hash code. This is consistent with {@link #equivalentTo(AnnotationInstance)},
* therefore no attention is paid to the annotation target.
*
* @return hash code consistent with annotation equivalence
*/
public int equivalenceHashCode() {
int result = name.hashCode();
result = 31 * result + Arrays.hashCode(values);
return result;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jboss.jandex.test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand Down Expand Up @@ -48,5 +49,7 @@ private void testEqualityEquivalence(Index index) {
assertTrue(foo.equivalentTo(foo2));
assertFalse(foo.equivalentTo(bar));
assertFalse(foo2.equivalentTo(bar));

assertEquals(foo.equivalenceHashCode(), foo2.equivalenceHashCode());
}
}

0 comments on commit 310da1e

Please sign in to comment.