Skip to content

Commit

Permalink
Sort manipulators based on underlines present on it, assuming it will…
Browse files Browse the repository at this point in the history
… be more complex as well
  • Loading branch information
EverNife committed Jun 11, 2024
1 parent c362af1 commit 01302b5
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ public RegexReplacer<O> addManipulator(String manipulableString, BiFunction<O, M
)
);
//Sort manipulators based on the prefix lengh, it might help performance, bigger prefixes first
Collections.sort(this.manipulators, Comparator.comparing(manipulatorParser -> manipulatorParser.getManipulator().getPrefix().length()));
Collections.sort(this.manipulators, Comparator.comparing(manipulatorParser -> {
int prefixSize = manipulatorParser.getManipulator().getPrefix().length();
long underlines = manipulatorParser.getId().chars().filter(c -> c == '_').count(); //More complex manipulators first
return (prefixSize * 1000) + underlines;
}));
Collections.reverse(this.manipulators);
return this;
}
Expand Down

0 comments on commit 01302b5

Please sign in to comment.