Skip to content

Commit

Permalink
Merge pull request #124 from Trard/v4
Browse files Browse the repository at this point in the history
Preserve annotation order
  • Loading branch information
Revxrsal authored Jan 15, 2025
2 parents e538c61 + 509b05c commit 2ebf1ad
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ public AnnotationListFromMap(Map<Class<? extends Annotation>, Annotation> annota
}

public static @NotNull Map<Class<? extends Annotation>, Annotation> toMap(@NotNull Iterable<Annotation> annotations) {
Map<Class<? extends Annotation>, Annotation> map = new HashMap<>();
Map<Class<? extends Annotation>, Annotation> map = new LinkedHashMap<>();
for (Annotation annotation : annotations) {
map.put(annotation.annotationType(), annotation);
}
return map;
}

public static @NotNull Map<Class<? extends Annotation>, Annotation> toMap(@NotNull Annotation[] annotations) {
Map<Class<? extends Annotation>, Annotation> map = new HashMap<>();
Map<Class<? extends Annotation>, Annotation> map = new LinkedHashMap<>();
for (Annotation annotation : annotations) {
map.put(annotation.annotationType(), annotation);
}
Expand Down Expand Up @@ -146,7 +146,7 @@ public <T extends Annotation> boolean contains(@NotNull Class<T> type) {
@NotNull AnnotatedElement element,
@NotNull Map<Class<? extends Annotation>, Set<AnnotationReplacer<?>>> replacers
) {
Map<Class<? extends Annotation>, Annotation> annotations = new HashMap<>(this.annotations);
Map<Class<? extends Annotation>, Annotation> annotations = new LinkedHashMap<>(this.annotations);
for (Annotation annotation : this.annotations.values()) {
for (AnnotationReplacer replacer : replacers.getOrDefault(annotation.annotationType(), emptySet())) {
Collection<Annotation> newAnnotations = replacer.replaceAnnotation(element, annotation);
Expand All @@ -163,7 +163,7 @@ public <T extends Annotation> boolean contains(@NotNull Class<T> type) {

@Override
public @NotNull Map<Class<?>, Annotation> toMutableMap() {
return new HashMap<>(annotations);
return new LinkedHashMap<>(annotations);
}

@Override
Expand All @@ -187,7 +187,7 @@ public boolean any(@NotNull Predicate<Annotation> predicate) {

@Override
public @NotNull AnnotationList withAnnotations(boolean overrideExisting, @NotNull Annotation... annotations) {
HashMap<Class<? extends Annotation>, Annotation> map = new HashMap<>(this.annotations);
LinkedHashMap<Class<? extends Annotation>, Annotation> map = new LinkedHashMap<>(this.annotations);
for (@NotNull Annotation annotation : annotations) {
if (overrideExisting)
map.put(annotation.annotationType(), annotation);
Expand Down

0 comments on commit 2ebf1ad

Please sign in to comment.