Skip to content

Commit

Permalink
pre-compile regex in PriorityDirectoryConverter (NationalSecurityAgen…
Browse files Browse the repository at this point in the history
  • Loading branch information
DonResnik authored and Ryan Garvey rpgarve committed Jan 7, 2025
1 parent b60c70e commit 638b0f4
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 638b0f4

Please sign in to comment.