Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.68 KB | None | 0 0
  1.  public static String format(String input, PrematchMatch prematchMatch,
  2.                                 Map<String, String> specifiers) {
  3.         Matcher matcher = SPECIFIER_PATTERN.matcher(input);
  4.         List<String> partsToReplace = new ArrayList<>();
  5.         while (matcher.find()) {
  6.             partsToReplace.add(matcher.group());
  7.         }
  8.         if (partsToReplace.size() > 0) {
  9.             for (String partToReplace : partsToReplace) {
  10.                 if (partToReplace != null && partToReplace.length() > 0) {
  11.                     switch (partToReplace) {
  12.                         case TEAM_1_SPECIFIER:
  13.                             input = input.replace(partToReplace, prematchMatch.getTeam1Name());
  14.                             break;
  15.                         case TEAM_2_SPECIFIER:
  16.                             input = input.replace(partToReplace, prematchMatch.getTeam2Name());
  17.                             break;
  18.                         default:
  19.                             String specifierKey = partToReplace.replaceAll("[^a-zA-Z0-9]", "");
  20.                             String prefix = getPrefixForPart(partToReplace);
  21.                             String sufix = getSufixForPart(partToReplace);
  22.                             if (!specifierKey.isEmpty() && specifiers.containsKey(specifierKey)) {
  23.                                 String specifierValue = calculateSpecifierValueWithPrefix(specifiers.get(specifierKey), prefix);
  24.                                 input = input.replace(partToReplace, (specifierValue + sufix));
  25.                             }
  26.                             break;
  27.                     }
  28.                 }
  29.             }
  30.         }
  31.         return input;
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement