|
15 | 15 | import java.util.LinkedList; |
16 | 16 | import java.util.List; |
17 | 17 | import java.util.Map; |
| 18 | +import java.util.Objects; |
18 | 19 | import java.util.regex.Pattern; |
19 | 20 |
|
20 | 21 | public final class Utils { |
@@ -73,9 +74,8 @@ public static long mixedNumberWordToLong(final String numberWord) |
73 | 74 | multiplier = Parser.matchGroup("[\\d]+([\\.,][\\d]+)?([KMBkmb])+", numberWord, 2); |
74 | 75 | } catch (final ParsingException ignored) { |
75 | 76 | } |
76 | | - |
77 | | - final double count = Double.parseDouble(Parser.matchGroup1("([\\d]+([\\.,][\\d]+)?)", |
78 | | - numberWord).replace(",", ".")); |
| 77 | + final double count = Double.parseDouble( |
| 78 | + Parser.matchGroup1("([\\d]+([\\.,][\\d]+)?)", numberWord).replace(",", ".")); |
79 | 79 | switch (multiplier.toUpperCase()) { |
80 | 80 | case "K": |
81 | 81 | return (long) (count * 1e3); |
@@ -391,19 +391,12 @@ public static String getStringResultFromRegexArray(@Nonnull final String input, |
391 | 391 | @Nonnull final String[] regexes, |
392 | 392 | final int group) |
393 | 393 | throws Parser.RegexException { |
394 | | - for (final String regex : regexes) { |
395 | | - try { |
396 | | - final String result = Parser.matchGroup(regex, input, group); |
397 | | - if (result != null) { |
398 | | - return result; |
399 | | - } |
400 | | - |
401 | | - // Continue if the result is null |
402 | | - } catch (final Parser.RegexException ignored) { |
403 | | - } |
404 | | - } |
405 | | - |
406 | | - throw new Parser.RegexException("No regex matched the input on group " + group); |
| 394 | + return getStringResultFromRegexArray(input, |
| 395 | + Arrays.stream(regexes) |
| 396 | + .filter(Objects::nonNull) |
| 397 | + .map(Pattern::compile) |
| 398 | + .toArray(Pattern[]::new), |
| 399 | + group); |
407 | 400 | } |
408 | 401 |
|
409 | 402 | /** |
|
0 commit comments