Skip to content

Commit 4b93892

Browse files
committed
add comparator to NamespacedIdentifiers
1 parent e486b00 commit 4b93892

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

libraries/core/src/main/java/net/ornithemc/osl/core/api/util/NamespacedIdentifiers.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package net.ornithemc.osl.core.api.util;
22

3+
import java.util.Comparator;
4+
35
import net.ornithemc.osl.core.impl.util.NamespacedIdentifierException;
46
import net.ornithemc.osl.core.impl.util.NamespacedIdentifierParseException;
57
import net.ornithemc.osl.core.impl.util.NamespacedIdentifierImpl;
@@ -28,6 +30,18 @@ public final class NamespacedIdentifiers {
2830
*/
2931
public static final int MAX_LENGTH_IDENTIFIER = Integer.MAX_VALUE;
3032

33+
/**
34+
* A comparator for {@code NamespacedIdentifier}s, comparing first by identifier, then by namespace.
35+
*/
36+
public static final Comparator<NamespacedIdentifier> COMPARATOR = (a, b) -> {
37+
int c = a.identifier().compareTo(b.identifier());
38+
if (c == 0) {
39+
c = a.namespace().compareTo(b.namespace());
40+
}
41+
42+
return c;
43+
};
44+
3145
/**
3246
* Construct and validate a {@code NamespacedIdentifier} with the default namespace and the given identifier.
3347
*

0 commit comments

Comments
 (0)