Comparable Arns
- Vorherrschende Sprache
- Java
- Sterne
- 2.6k
- Forks
- 1k
- Ø Merge
- 2 T. 9 Std.
- Gemergte PRs (30 T.)
- 51
Beschreibung
### Describe the feature
It'd be nice if [Arn](https://github.com/aws/aws-sdk-java-v2/blob/master/core/arns/src/main/java/software/amazon/awssdk/arns/Arn.java) implemented `Comparable`.
This would make Arns usable in sorted collection types, etc.
### Is your Feature Request related to a problem?
Not really.
- We can use `HashMap` instead of `TreeMap`, etc.
- We can sort Arns by converting to strings, sorting, then converting back to Arns.
So this would just make Arns more flexible.
### Proposed Solution
Here is a straightforward implementation:
public static final Comparator COMPARATOR =
Comparator.comparing(Arn::toString);
@Override
public int compareTo(Arn rhs) {
return COMPARATOR.compare(this, rhs);
}
Here is a more elaborate one, which may be more efficient by avoiding the String construction:
public static final Comparator COMPARATOR =
Comparator.comparing(Arn::partition)
.thenComparing(Arn::service)
.thenComparing(x -> x.region, Comparator.nullsLast(Comparator.naturalOrder()))
.thenComparing(x -> x.accountId, Comparator.nullsLast(Comparator.naturalOrder()))
.thenComparing(Arn::resourceAsString);
@Override
public int compareTo(Arn rhs) {
return COMPARATOR.compare(this, rhs);
}
### Describe alternatives you've considered
_No response_
### Acknowledge
- [X] I may be able to implement this feature request
### AWS Java SDK version used
aws-sdk-java-v2 c0eb030fceaa9ccb64ad8acd74445f4e5ee3a547
### JDK version used
openjdk version "1.8.0_312"
### Operating System and version
MacOS Big Sur Version 11.6.2 (20G314)
Beitragsleitfaden
Rechercherichtung
Beginne mit Arn.java, dem im Issue genannten Einstiegspunkt, und prüfe, wie ARN-Komponenten und String-Repräsentationen verfügbar gemacht werden. Implementiere das angeforderte vergleichbare Verhalten mit einem der vorgeschlagenen Sortieransätze und überprüfe anschließend, dass Arn-Instanzen in sortierten Sammlungen verwendet werden können und dass die Sortierreihenfolge konsistent ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- java
- Bereich
- backend
- Issue-Typ
- Feature
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 38/100