Skip to content

Commit

Permalink
add compareTo in PathString
Browse files Browse the repository at this point in the history
  • Loading branch information
HSGamer committed Mar 6, 2024
1 parent 1556798 commit 1621884
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package me.hsgamer.hscore.config;

import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;
Expand All @@ -8,7 +10,7 @@
/**
* The path string to use in {@link Config}
*/
public class PathString {
public class PathString implements Comparable<PathString> {
/**
* The root path
*/
Expand Down Expand Up @@ -205,4 +207,16 @@ public boolean equals(Object o) {
public int hashCode() {
return Arrays.hashCode(path);
}

@Override
public int compareTo(@NotNull PathString o) {
int length = Math.min(path.length, o.path.length);
for (int i = 0; i < length; i++) {
int compare = path[i].compareTo(o.path[i]);
if (compare != 0) {
return compare;
}
}
return Integer.compare(path.length, o.path.length);
}
}

0 comments on commit 1621884

Please sign in to comment.