package org.jabref.logic.formatter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

import org.jabref.logic.formatter.bibtexfields.AddBracesFormatter;
import org.jabref.logic.formatter.bibtexfields.ClearFormatter;
import org.jabref.logic.formatter.bibtexfields.EscapeUnderscoresFormatter;
import org.jabref.logic.formatter.bibtexfields.HtmlToLatexFormatter;
import org.jabref.logic.formatter.bibtexfields.HtmlToUnicodeFormatter;
import org.jabref.logic.formatter.bibtexfields.LatexCleanupFormatter;
import org.jabref.logic.formatter.bibtexfields.NormalizeDateFormatter;
import org.jabref.logic.formatter.bibtexfields.NormalizeEnDashesFormatter;
import org.jabref.logic.formatter.bibtexfields.NormalizeMonthFormatter;
import org.jabref.logic.formatter.bibtexfields.NormalizeNamesFormatter;
import org.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter;
import org.jabref.logic.formatter.bibtexfields.OrdinalsToSuperscriptFormatter;
import org.jabref.logic.formatter.bibtexfields.RegexFormatter;
import org.jabref.logic.formatter.bibtexfields.RemoveBracesFormatter;
import org.jabref.logic.formatter.bibtexfields.UnicodeToLatexFormatter;
import org.jabref.logic.formatter.bibtexfields.UnitsToLatexFormatter;
import org.jabref.logic.formatter.casechanger.CapitalizeFormatter;
import org.jabref.logic.formatter.casechanger.LowerCaseFormatter;
import org.jabref.logic.formatter.casechanger.SentenceCaseFormatter;
import org.jabref.logic.formatter.casechanger.TitleCaseFormatter;
import org.jabref.logic.formatter.casechanger.UpperCaseFormatter;
import org.jabref.logic.formatter.minifier.MinifyNameListFormatter;
import org.jabref.logic.layout.format.LatexToUnicodeFormatter;
import org.jabref.model.cleanup.Formatter;

public class Formatters {

    private static final List<Formatter> CONVERTERS = Arrays.asList(
            new HtmlToLatexFormatter(),
            new HtmlToUnicodeFormatter(),
            new LatexToUnicodeFormatter(),
            new UnicodeToLatexFormatter()
    );

    private static final List<Formatter> CASE_CHANGERS = Arrays.asList(
            new CapitalizeFormatter(),
            new LowerCaseFormatter(),
            new SentenceCaseFormatter(),
            new TitleCaseFormatter(),
            new UpperCaseFormatter()
    );

    private static final List<Formatter> OTHERS = Arrays.asList(
            new AddBracesFormatter(),
            new ClearFormatter(),
            new LatexCleanupFormatter(),
            new MinifyNameListFormatter(),
            new NormalizeDateFormatter(),
            new NormalizeEnDashesFormatter(),
            new NormalizeMonthFormatter(),
            new NormalizeNamesFormatter(),
            new NormalizePagesFormatter(),
            new OrdinalsToSuperscriptFormatter(),
            new RegexFormatter(""),
            new RemoveBracesFormatter(),
            new UnitsToLatexFormatter(),
            new EscapeUnderscoresFormatter()
    );

    private static final String REGEX = "regex";

    private static final int LENGTH_OF_REGEX_PREFIX = REGEX.length();

    private Formatters() {
    }

    public static List<Formatter> getConverters() {
        return Arrays.asList(
                new HtmlToLatexFormatter(),
                new HtmlToUnicodeFormatter(),
                new LatexToUnicodeFormatter(),
                new UnicodeToLatexFormatter()
        );
    }

    public static List<Formatter> getCaseChangers() {
        return Arrays.asList(
                new CapitalizeFormatter(),
                new LowerCaseFormatter(),
                new SentenceCaseFormatter(),
                new TitleCaseFormatter(),
                new UpperCaseFormatter()
        );
    }

    public static List<Formatter> getOthers() {
        return Arrays.asList(
                new ClearFormatter(),
                new LatexCleanupFormatter(),
                new MinifyNameListFormatter(),
                new NormalizeDateFormatter(),
                new NormalizeMonthFormatter(),
                new NormalizeNamesFormatter(),
                new NormalizePagesFormatter(),
                new OrdinalsToSuperscriptFormatter(),
                new RemoveBracesFormatter(),
                new UnitsToLatexFormatter(),
                new EscapeUnderscoresFormatter()
        );
    }

    public static List<Formatter> getAll() {
        List<Formatter> all = new ArrayList<>();
        all.addAll(getConverters());
        all.addAll(getCaseChangers());
        all.addAll(getOthers());
        return all;
    }

    public static Optional<Formatter> getFormatterForModifier(String modifier) {
        Objects.requireNonNull(modifier);

        switch (modifier) {
            case "lower":
                return Optional.of(new LowerCaseFormatter());
            case "upper":
                return Optional.of(new UpperCaseFormatter());
        }

        if (modifier.startsWith(RegexFormatter.KEY)) {
            String regex = modifier.substring(RegexFormatter.KEY.length());
            return Optional.of(new RegexFormatter(regex));
        } else {
            return getAll().stream().filter(f -> f.getKey().equals(modifier)).findAny();
        }
    }

}

@@ -164,75 +164,8 @@
 l;%0A%0A
-import org.jabref.logic.formatter.bibtexfields.AddBracesFormatter;%0A
 impo
@@ -215,32 +215,32 @@
 ClearFormatter;%0A
+
 import org.jabre
@@ -583,83 +583,8 @@
 er;%0A
-import org.jabref.logic.formatter.bibtexfields.NormalizeEnDashesFormatter;%0A
 impo
@@ -1658,16 +1658,16 @@
 atter;%0A%0A
+
 public c
@@ -1689,1305 +1689,8 @@
  %7B%0A%0A
-    private static final List%3CFormatter%3E CONVERTERS = Arrays.asList(%0A            new HtmlToLatexFormatter(),%0A            new HtmlToUnicodeFormatter(),%0A            new LatexToUnicodeFormatter(),%0A            new UnicodeToLatexFormatter()%0A    );%0A%0A    private static final List%3CFormatter%3E CASE_CHANGERS = Arrays.asList(%0A            new CapitalizeFormatter(),%0A            new LowerCaseFormatter(),%0A            new SentenceCaseFormatter(),%0A            new TitleCaseFormatter(),%0A            new UpperCaseFormatter()%0A    );%0A%0A    private static final List%3CFormatter%3E OTHERS = Arrays.asList(%0A            new AddBracesFormatter(),%0A            new ClearFormatter(),%0A            new LatexCleanupFormatter(),%0A            new MinifyNameListFormatter(),%0A            new NormalizeDateFormatter(),%0A            new NormalizeEnDashesFormatter(),%0A            new NormalizeMonthFormatter(),%0A            new NormalizeNamesFormatter(),%0A            new NormalizePagesFormatter(),%0A            new OrdinalsToSuperscriptFormatter(),%0A            new RegexFormatter(%22%22),%0A            new RemoveBracesFormatter(),%0A            new UnitsToLatexFormatter(),%0A            new EscapeUnderscoresFormatter()%0A    );%0A%0A    private static final String REGEX = %22regex%22;%0A%0A    private static final int LENGTH_OF_REGEX_PREFIX = REGEX.length();%0A%0A
     

Remove unused code