|
7 | 7 | import javax.annotation.Nonnull; |
8 | 8 | import java.util.Collections; |
9 | 9 | import java.util.List; |
10 | | -import java.util.function.BiFunction; |
| 10 | +import java.util.function.BiPredicate; |
11 | 11 | import java.util.regex.Matcher; |
12 | 12 | import java.util.regex.Pattern; |
13 | 13 |
|
@@ -67,35 +67,35 @@ public void execute(@Nonnull final String argString) throws CommandException { |
67 | 67 | throw new CommandException(AnsiFormattedText.from("Incorrect usage.\nusage: ") |
68 | 68 | .bold().append(COMMAND_NAME).boldOff().append(" ").append(getUsage())); |
69 | 69 | } |
70 | | - if (!validParameterAssignment(argString)) { |
| 70 | + if (!assignIfValidParameter(argString)) { |
71 | 71 | throw new CommandException(AnsiFormattedText.from("Incorrect number of arguments.\nusage: ") |
72 | 72 | .bold().append(COMMAND_NAME).boldOff().append(" ").append(getUsage())); |
73 | 73 | } |
74 | 74 | } |
75 | 75 |
|
76 | | - private boolean validParameterAssignment(@Nonnull String argString) throws CommandException { |
77 | | - return setParameterIfItMatchesPattern(argString, lambdaPattern, validParameterAssignment()) |
78 | | - || setParameterIfItMatchesPattern(argString, argPattern, validParameterAssignment()) |
| 76 | + private boolean assignIfValidParameter(@Nonnull String argString) throws CommandException { |
| 77 | + return setParameterIfItMatchesPattern(argString, lambdaPattern, assignIfValidParameter()) |
| 78 | + || setParameterIfItMatchesPattern(argString, argPattern, assignIfValidParameter()) |
79 | 79 | || setParameterIfItMatchesPattern(argString, backtickLambdaPattern, backTickMatchPattern()) |
80 | 80 | || setParameterIfItMatchesPattern(argString, backtickPattern, backTickMatchPattern()); |
81 | 81 | } |
82 | 82 |
|
83 | 83 | private boolean setParameterIfItMatchesPattern(@Nonnull String argString, Pattern pattern, |
84 | | - BiFunction<String, Matcher, Boolean> matchingFunction) throws CommandException { |
| 84 | + BiPredicate<String, Matcher> matchingFunction) throws CommandException { |
85 | 85 | Matcher matcher = pattern.matcher(argString); |
86 | | - if (matchingFunction.apply(argString, matcher)) { |
| 86 | + if (matchingFunction.test(argString, matcher)) { |
87 | 87 | variableHolder.set(matcher.group("key"), matcher.group("value")); |
88 | 88 | return true; |
89 | 89 | } else { |
90 | 90 | return false; |
91 | 91 | } |
92 | 92 | } |
93 | 93 |
|
94 | | - private BiFunction<String, Matcher, Boolean> validParameterAssignment() { |
| 94 | + private BiPredicate<String, Matcher> assignIfValidParameter() { |
95 | 95 | return (argString, matcher) -> matcher.matches(); |
96 | 96 | } |
97 | 97 |
|
98 | | - private BiFunction<String, Matcher, Boolean> backTickMatchPattern() { |
| 98 | + private BiPredicate<String, Matcher> backTickMatchPattern() { |
99 | 99 | return (argString, backtickLambdaMatcher) -> { |
100 | 100 | return argString.trim().startsWith("`") |
101 | 101 | && backtickLambdaMatcher.matches() |
|
0 commit comments