Skip to content

Commit

Permalink
pre-compile regex in PriorityDirectoryConverter (#1023)
Browse files Browse the repository at this point in the history
  • Loading branch information
DonResnik authored Dec 12, 2024
1 parent bc96ff7 commit 379db5e
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,24 @@
import org.apache.commons.lang3.StringUtils;
import picocli.CommandLine.ITypeConverter;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PriorityDirectoryConverter implements ITypeConverter<PriorityDirectory> {

public PriorityDirectoryConverter() {
super();
}

public static final String PRIORITY_DIR_REGEX = ".*:\\d+$";
private static final Pattern priorityDirRegex = Pattern.compile(PRIORITY_DIR_REGEX);

@Override
public PriorityDirectory convert(String value) {
final String dirName;
final int priority;
if (value.matches(PRIORITY_DIR_REGEX)) {
Matcher matcher = priorityDirRegex.matcher(value);
if (matcher.matches()) {
dirName = StringUtils.substringBeforeLast(value, ":");
priority = Integer.parseInt(StringUtils.substringAfterLast(value, ":"));
} else {
Expand Down

0 comments on commit 379db5e

Please sign in to comment.