This would make Arns usable in sorted collection types, etc.
Is your Feature Request related to a problem?
Not really.
We can use HashMap<Arn, ...> instead of TreeMap<Arn, ...>, 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<Arn> 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<Arn> 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
Describe the feature
It'd be nice if Arn implemented
Comparable<Arn>
.This would make Arns usable in sorted collection types, etc.
Is your Feature Request related to a problem?
Not really.
HashMap<Arn, ...>
instead ofTreeMap<Arn, ...>
, etc.So this would just make Arns more flexible.
Proposed Solution
Here is a straightforward implementation:
Here is a more elaborate one, which may be more efficient by avoiding the String construction:
Describe alternatives you've considered
No response
Acknowledge
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)