Skip to content

Commit

Permalink
Merge pull request #4044 from JabRef/feature/abstract-formatter
Browse files Browse the repository at this point in the history
Streamline formatter implementation
  • Loading branch information
koppor authored May 24, 2018
2 parents 7671b80 + 8aab893 commit 5f21d47
Show file tree
Hide file tree
Showing 29 changed files with 60 additions and 94 deletions.
13 changes: 1 addition & 12 deletions src/main/java/org/jabref/logic/formatter/IdentityFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* It may seem useless, but is needed as a fallback option
*/
public class IdentityFormatter implements Formatter {
public class IdentityFormatter extends Formatter {

@Override
public String getName() {
Expand All @@ -35,15 +35,4 @@ public String getDescription() {
public String getExampleInput() {
return "JabRef";
}

@Override
public int hashCode() {
return defaultHashCode();
}

@Override
public boolean equals(Object obj) {
return defaultEquals(obj);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.jabref.logic.l10n.Localization;
import org.jabref.model.cleanup.Formatter;

public class AddBracesFormatter implements Formatter {
public class AddBracesFormatter extends Formatter {

@Override
public String getName() {
Expand Down Expand Up @@ -38,5 +38,4 @@ public String getDescription() {
public String getExampleInput() {
return "In CDMA";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.jabref.logic.l10n.Localization;
import org.jabref.model.cleanup.Formatter;

public class ClearFormatter implements Formatter {
public class ClearFormatter extends Formatter {

@Override
public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.jabref.logic.l10n.Localization;
import org.jabref.model.cleanup.Formatter;

public class EscapeUnderscoresFormatter implements Formatter {
public class EscapeUnderscoresFormatter extends Formatter {

private static final Pattern UNDERSCORES = Pattern.compile("_");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class HtmlToLatexFormatter implements LayoutFormatter, Formatter {
public class HtmlToLatexFormatter extends Formatter implements LayoutFormatter {

private static final Logger LOGGER = LoggerFactory.getLogger(HtmlToLatexFormatter.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.apache.commons.lang3.StringEscapeUtils;

@ApacheCommonsLang3Allowed("There is no equivalent in Google's Guava")
public class HtmlToUnicodeFormatter implements LayoutFormatter, Formatter {
public class HtmlToUnicodeFormatter extends Formatter implements LayoutFormatter {

@Override
public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.jabref.logic.l10n.Localization;
import org.jabref.model.cleanup.Formatter;

public class LatexCleanupFormatter implements Formatter {
public class LatexCleanupFormatter extends Formatter {

private static final Pattern REMOVE_REDUNDANT = Pattern
.compile("(?<!\\\\[\\p{Alpha}]{0,100}\\{[^\\}]{0,100})\\}([-/ ]?)\\{");
Expand Down Expand Up @@ -62,5 +62,4 @@ public String getDescription() {
public String getExampleInput() {
return "{VLSI} {DSP}";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* This class transforms date to the format yyyy-mm-dd or yyyy-mm..
*/
public class NormalizeDateFormatter implements Formatter {
public class NormalizeDateFormatter extends Formatter {
@Override
public String getName() {
return Localization.lang("Normalize date");
Expand Down Expand Up @@ -43,14 +43,4 @@ public String getDescription() {
public String getExampleInput() {
return "29.11.2003";
}

@Override
public int hashCode() {
return defaultHashCode();
}

@Override
public boolean equals(Object obj) {
return defaultEquals(obj);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.jabref.model.cleanup.Formatter;
import org.jabref.model.entry.Month;

public class NormalizeMonthFormatter implements Formatter {
public class NormalizeMonthFormatter extends Formatter {

@Override
public String getName() {
Expand Down Expand Up @@ -35,5 +35,4 @@ public String getDescription() {
public String getExampleInput() {
return "December";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* Formatter normalizing a list of person names to the BibTeX format.
*/
public class NormalizeNamesFormatter implements Formatter {
public class NormalizeNamesFormatter extends Formatter {

@Override
public String getName() {
Expand Down Expand Up @@ -37,5 +37,4 @@ public String getDescription() {
public String getExampleInput() {
return "Albert Einstein and Alan Turing";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* To make it easier to maintain Scribe-compatible databases, the standard styles convert
* a single dash (as in 7-33) to the double dash used in TEX to denote number ranges (as in 7--33).
*/
public class NormalizePagesFormatter implements Formatter {
public class NormalizePagesFormatter extends Formatter {

// "startpage" and "endpage" are named groups. See http://stackoverflow.com/a/415635/873282 for a documentation
private static final Pattern PAGES_DETECT_PATTERN = Pattern.compile("\\A(?<startpage>(\\d+:)?\\d+)(?:-{1,2}(?<endpage>(\\d+:)?\\d+))?\\Z");
Expand Down Expand Up @@ -61,7 +61,7 @@ public String format(String value) {
}

// Remove pages prefix
String cleanValue = value.replace("pp.", "").replace("p.","");
String cleanValue = value.replace("pp.", "").replace("p.", "");
// remove unwanted literals incl. whitespace
cleanValue = cleanValue.replaceAll("\u2013|\u2014", "-").replaceAll(REJECT_LITERALS, "");
// try to find pages pattern
Expand All @@ -87,14 +87,4 @@ public String getDescription() {
public String getExampleInput() {
return "1 - 2";
}

@Override
public int hashCode() {
return defaultHashCode();
}

@Override
public boolean equals(Object obj) {
return defaultEquals(obj);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* This class transforms ordinal numbers into LaTex superscripts.
*/
public class OrdinalsToSuperscriptFormatter implements Formatter {
public class OrdinalsToSuperscriptFormatter extends Formatter {

// find possible superscripts on word boundaries
private static final Pattern SUPERSCRIPT_DETECT_PATTERN = Pattern.compile("\\b(\\d+)(st|nd|rd|th)\\b",
Expand Down Expand Up @@ -61,5 +61,4 @@ public String getDescription() {
public String getExampleInput() {
return "11th";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.jabref.logic.l10n.Localization;
import org.jabref.model.cleanup.Formatter;

public class RegexFormatter implements Formatter {
public class RegexFormatter extends Formatter {

private static final Pattern PATTERN_ESCAPED_OPENING_CURLY_BRACE = Pattern.compile("\\\\\\{");

Expand Down Expand Up @@ -101,5 +101,4 @@ public static void setRegex(String rex) {
String[] parts = rexToSet.split("\",\"");
regex = parts;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.jabref.logic.l10n.Localization;
import org.jabref.model.cleanup.Formatter;

public class RemoveBracesFormatter implements Formatter {
public class RemoveBracesFormatter extends Formatter {

@Override
public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* Removes all hyphenated line breaks in the string.
*/
public class RemoveHyphenatedNewlinesFormatter implements Formatter {
public class RemoveHyphenatedNewlinesFormatter extends Formatter {
private static final Pattern HYPHENATED_WORDS = Pattern.compile("(-\r\n|-\n|-\r)");

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* Removes all line breaks in the string.
*/
public class RemoveNewlinesFormatter implements Formatter {
public class RemoveNewlinesFormatter extends Formatter {
private static final Pattern LINEBREAKS = Pattern.compile("(\r?\n|\r)");

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class UnicodeToLatexFormatter implements LayoutFormatter, Formatter {
public class UnicodeToLatexFormatter extends Formatter implements LayoutFormatter {

private static final Logger LOGGER = LoggerFactory.getLogger(UnicodeToLatexFormatter.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.jabref.logic.util.strings.StringLengthComparator;
import org.jabref.model.cleanup.Formatter;

public class UnitsToLatexFormatter implements Formatter {
public class UnitsToLatexFormatter extends Formatter {

private static final List<String> UNIT_LIST = Arrays.asList(
"A", // Ampere
Expand Down Expand Up @@ -81,7 +81,6 @@ public class UnitsToLatexFormatter implements Formatter {

private final List<String> prefixUnitCombinations;


public UnitsToLatexFormatter() {
prefixUnitCombinations = new ArrayList<>(
UnitsToLatexFormatter.UNIT_LIST.size() * UnitsToLatexFormatter.UNIT_PREFIX_LIST.size());
Expand Down Expand Up @@ -112,7 +111,6 @@ public String format(String text) {
result = result.replaceAll("([0-9])(" + listOfWord + ")", "$1\\{$2\\}"); // Only add brackets to keep case
result = result.replaceAll("([0-9])-(" + listOfWord + ")", "$1\\\\mbox\\{-\\}\\{$2\\}"); // Replace hyphen with non-break hyphen
result = result.replaceAll("([0-9]) (" + listOfWord + ")", "$1~\\{$2\\}"); // Replace space with a hard space

}

return result;
Expand All @@ -137,5 +135,4 @@ public String getName() {
public String getKey() {
return "units_to_latex";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.jabref.logic.l10n.Localization;
import org.jabref.model.cleanup.Formatter;

public class CapitalizeFormatter implements Formatter {
public class CapitalizeFormatter extends Formatter {

@Override
public String getName() {
Expand Down Expand Up @@ -37,5 +37,4 @@ public String getDescription() {
public String getExampleInput() {
return "I have {a} DREAM";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.jabref.logic.l10n.Localization;
import org.jabref.model.cleanup.Formatter;

public class LowerCaseFormatter implements Formatter {
public class LowerCaseFormatter extends Formatter {

@Override
public String getName() {
Expand All @@ -27,16 +27,6 @@ public String format(String input) {
return title.toString();
}

@Override
public int hashCode() {
return defaultHashCode();
}

@Override
public boolean equals(Object obj) {
return defaultEquals(obj);
}

@Override
public String getDescription() {
return Localization.lang("Changes all letters to lower case.");
Expand All @@ -46,5 +36,4 @@ public String getDescription() {
public String getExampleInput() {
return "KDE {Amarok}";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.jabref.logic.util.strings.StringLengthComparator;
import org.jabref.model.cleanup.Formatter;

public class ProtectTermsFormatter implements Formatter {
public class ProtectTermsFormatter extends Formatter {

private final ProtectedTermsLoader protectedTermsLoader;

Expand Down Expand Up @@ -56,5 +56,4 @@ public String getName() {
public String getKey() {
return "protect_terms";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.jabref.logic.l10n.Localization;
import org.jabref.model.cleanup.Formatter;

public class SentenceCaseFormatter implements Formatter {
public class SentenceCaseFormatter extends Formatter {

@Override
public String getName() {
Expand Down Expand Up @@ -37,5 +37,4 @@ public String getDescription() {
public String getExampleInput() {
return "i have {Aa} DREAM";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.jabref.logic.l10n.Localization;
import org.jabref.model.cleanup.Formatter;

public class TitleCaseFormatter implements Formatter {
public class TitleCaseFormatter extends Formatter {

@Override
public String getName() {
Expand Down Expand Up @@ -49,5 +49,4 @@ public String getDescription() {
public String getExampleInput() {
return "{BPMN} conformance In open source Engines";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.jabref.logic.l10n.Localization;
import org.jabref.model.cleanup.Formatter;

public class UpperCaseFormatter implements Formatter {
public class UpperCaseFormatter extends Formatter {

@Override
public String getName() {
Expand Down Expand Up @@ -37,5 +37,4 @@ public String getDescription() {
public String getExampleInput() {
return "Kde {Amarok}";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Replaces three or more authors with and others
*/
public class MinifyNameListFormatter implements Formatter {
public class MinifyNameListFormatter extends Formatter {
@Override
public String getName() {
return Localization.lang("Minify list of person names");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* This formatter converts LaTeX character sequences their equivalent unicode characters,
* and removes other LaTeX commands without handling them.
*/
public class LatexToUnicodeFormatter implements LayoutFormatter, Formatter {
public class LatexToUnicodeFormatter extends Formatter implements LayoutFormatter {

@Override
public String getName() {
Expand Down
Loading

0 comments on commit 5f21d47

Please sign in to comment.