From f20b088ff9efdee3033bdf6e2edddabe0e79f6c9 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 9 Dec 2024 17:54:29 +0100 Subject: [PATCH] use sorted map in annotation processor (cherry picked from commit 37f51949fda2f04cd64eab76a1cc91343695f52e) --- .../processor/XmlElementProcessor.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/libs/annotation-processor/src/main/java/im/conversations/android/annotation/processor/XmlElementProcessor.java b/libs/annotation-processor/src/main/java/im/conversations/android/annotation/processor/XmlElementProcessor.java index c42cc53405..b93849d57d 100644 --- a/libs/annotation-processor/src/main/java/im/conversations/android/annotation/processor/XmlElementProcessor.java +++ b/libs/annotation-processor/src/main/java/im/conversations/android/annotation/processor/XmlElementProcessor.java @@ -4,17 +4,17 @@ import com.google.auto.service.AutoService; import com.google.common.base.CaseFormat; import com.google.common.base.Objects; import com.google.common.base.Strings; +import com.google.common.collect.ComparisonChain; import com.google.common.collect.ImmutableMap; - +import com.google.common.collect.ImmutableSortedMap; import im.conversations.android.annotation.XmlElement; import im.conversations.android.annotation.XmlPackage; - import java.io.IOException; import java.io.PrintWriter; import java.util.List; import java.util.Map; import java.util.Set; - +import javax.annotation.Nonnull; import javax.annotation.processing.AbstractProcessor; import javax.annotation.processing.Processor; import javax.annotation.processing.RoundEnvironment; @@ -38,7 +38,7 @@ public class XmlElementProcessor extends AbstractProcessor { public boolean process(Set set, RoundEnvironment roundEnvironment) { final Set elements = roundEnvironment.getElementsAnnotatedWith(XmlElement.class); - final ImmutableMap.Builder builder = ImmutableMap.builder(); + final ImmutableSortedMap.Builder builder = ImmutableSortedMap.naturalOrder(); for (final Element element : elements) { if (element instanceof final TypeElement typeElement) { final Id id = of(typeElement); @@ -160,7 +160,7 @@ public class XmlElementProcessor extends AbstractProcessor { return false; } - public static class Id { + public static class Id implements Comparable { public final String name; public final String namespace; @@ -181,5 +181,13 @@ public class XmlElementProcessor extends AbstractProcessor { public int hashCode() { return Objects.hashCode(name, namespace); } + + @Override + public int compareTo(@Nonnull Id id) { + return ComparisonChain.start() + .compare(namespace, id.namespace) + .compare(name, id.name) + .result(); + } } }