-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #341 from Ladicek/annotation-instance-equivalence-…
…proxy add an equivalence proxy for AnnotationInstance
- Loading branch information
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
core/src/main/java/org/jboss/jandex/AnnotationInstanceEquivalenceProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.jboss.jandex; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Holds an {@link AnnotationInstance} and implements equality and hash code as equivalence. | ||
* <p> | ||
* When using equivalence proxies, it is usually a mistake to obtain | ||
* the {@linkplain AnnotationInstance#target() target} of the delegate annotation instance. | ||
* <p> | ||
* <b>Thread-Safety</b> | ||
* </p> | ||
* This class is immutable and can be shared between threads without safe | ||
* publication. | ||
* | ||
* @see AnnotationInstance#equivalentTo(AnnotationInstance) | ||
* @see AnnotationInstance#equivalenceHashCode() | ||
*/ | ||
public final class AnnotationInstanceEquivalenceProxy { | ||
private final AnnotationInstance annotation; | ||
|
||
AnnotationInstanceEquivalenceProxy(AnnotationInstance annotation) { | ||
this.annotation = Objects.requireNonNull(annotation); | ||
} | ||
|
||
public AnnotationInstance get() { | ||
return annotation; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
if (o == null || getClass() != o.getClass()) | ||
return false; | ||
return annotation.equivalentTo(((AnnotationInstanceEquivalenceProxy) o).annotation); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return annotation.equivalenceHashCode(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters