package lodi;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.StringJoiner;
import java.util.regex.Pattern;

public class ManualReplacements {

    public static class Builder {
        public Builder() {
            this.patterns = new LinkedList<>();
            this.replacements = new LinkedList<>();
        }

        public Builder add(String pattern, String replacement) {
            this.patterns.add(pattern);
            this.replacements.add(replacement);

            return this;
        }

        public ManualReplacements build() {
            return new ManualReplacements(patterns, replacements);
        }

        private final LinkedList<String> patterns;
        private final LinkedList<String> replacements;
    }

    public ManualReplacements(LinkedList<String> patterns, LinkedList<String> replacements) {
        if (patterns.size() != replacements.size())
            throw new IllegalArgumentException("`patterns` and `size` should have the same length");

        this.replacements = new HashMap<>();

        while (!patterns.isEmpty()) {
            String p = patterns.removeFirst();
            String r = replacements.removeFirst();
            this.replacements.put(Pattern.compile(Pattern.quote(p)), r);
        }
    }

    public String apply(String in) {
        StringBuilder b1 = new StringBuilder();
        StringBuilder b2 = new StringBuilder();
        StringBuilder temp;


    }

    private final HashMap<Pattern, String> replacements;
}

@@ -24,22 +24,52 @@
 ava.
-util.ArrayList
+io.BufferedReader;%0Aimport java.io.FileReader
 ;%0Aim
@@ -142,18 +142,41 @@
 til.
-StringJoin
+Map;%0Aimport java.util.regex.Match
 er;%0A
@@ -832,32 +832,644 @@
 cements;%0A    %7D%0A%0A
+    public static ManualReplacements loadFromFile(String filename) %0A        throws java.io.IOException%0A    %7B%0A        Builder b = new Builder();%0A        BufferedReader in = new BufferedReader(new FileReader(filename));%0A%0A        String line;%0A        while ((line = in.readLine()) != null) %7B%0A            line = line.trim();%0A%0A            // skip comments and empty lines%0A            if (line.startsWith(%22#%22) %7C%7C line.isEmpty())%0A                continue;%0A%0A            String%5B%5D lineSplit = line.split(%22%7C%22);%0A            b.add(lineSplit%5B0%5D, lineSplit%5B1%5D);%0A        %7D%0A%0A        in.close();%0A%0A        return b.build();%0A    %7D%0A%0A
     public Manua
@@ -2021,93 +2021,123 @@
     
-StringBuilder b1 = new StringBuilder();%0A        StringBuilder b2 = new StringBuild
+for (Map.Entry%3CPattern, String%3E entry: replacements.entrySet()) %7B%0A            Matcher m = entry.getKey().match
 er(
+in
 );%0A 
@@ -2147,29 +2147,82 @@
     
-StringBuilder temp;%0A%0A
+    in = m.replaceAll(entry.getValue());%0A        %7D%0A%0A        return in;    
 %0A   

implement manual replacementsmanual replacements