Skip to content

Commit

Permalink
Paying off technical debt: almost all utility classes have a private …
Browse files Browse the repository at this point in the history
…constructor now. (#2649)

* Start paying technical debt.

* Continue adding private constructors.

* Add more private constructors.

* Continue adding private constructors.

* Continue adding private constructors.

* Remove unused private method.
  • Loading branch information
TRvanRossum authored and stefan-kolb committed Mar 20, 2017
1 parent a4d6a28 commit 4ff55d0
Show file tree
Hide file tree
Showing 89 changed files with 307 additions and 19 deletions.
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public class Globals {
private static GlobalFocusListener focusListener;
private static FileUpdateMonitor fileUpdateMonitor;

private Globals() {
}

// Key binding preferences
public static KeyBindingPreferences getKeyPrefs() {
if (keyPrefs == null) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/cli/CrossrefFetcherEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
*/
public class CrossrefFetcherEvaluator {

private CrossrefFetcherEvaluator() {
}

public static void main(String[] args) throws IOException, InterruptedException {
Globals.prefs = JabRefPreferences.getInstance();
try (FileReader reader = new FileReader(args[0])) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/cli/GenerateCharacterTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

public class GenerateCharacterTable {

private GenerateCharacterTable() {
}

public static void main(String[] args) {
Map<Integer, String> characterMap = new TreeMap<>(HTMLUnicodeConversionMaps.NUMERICAL_LATEX_CONVERSION_MAP);
System.out.println("\\documentclass[10pt, a4paper]{article}");
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/cli/XMPUtilMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@

public class XMPUtilMain {

private XMPUtilMain() {
}

/**
* Command-line tool for working with XMP-data.
*
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/gui/EntryMarker.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class EntryMarker {

private static final Pattern MARK_NUMBER_PATTERN = Pattern.compile(JabRefPreferences.getInstance().MARKING_WITH_NUMBER_PATTERN);

private EntryMarker() {
}

/**
* @param increment whether the given increment should be added to the current one. Currently never used in JabRef. Could be used to increase marking color ("Mark in specific color").
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/gui/GUIGlobals.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public class GUIGlobals {

public static final int MAX_BACK_HISTORY_SIZE = 10; // The maximum number of "Back" operations stored.

private GUIGlobals() {
}

public static JLabel getTableIcon(String fieldType) {
JLabel label = GUIGlobals.TABLE_ICONS.get(fieldType);
if (label == null) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/gui/actions/Actions.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,7 @@ public class Actions {
public static final String UNMARK_ENTRIES = "unmarkEntries";
public static final String WRITE_XMP = "writeXMP";
public static final String PRINT_PREVIEW = "printPreview";

private Actions() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
*/
public class BackupUIManager {

private BackupUIManager() {
}

public static void showRestoreBackupDialog(JFrame frame, Path originalPath) {
int answer = JOptionPane.showConfirmDialog(frame,
new StringBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

public class CustomEntryTypesManager {

private CustomEntryTypesManager() {
}

/**
* Iterate through all entry types, and store those that are
* custom defined to preferences. This method is called from
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/gui/desktop/JabRefDesktop.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public class JabRefDesktop {
private static final NativeDesktop NATIVE_DESKTOP = getNativeDesktop();
private static final Pattern REMOTE_LINK_PATTERN = Pattern.compile("[a-z]+://.*");

private JabRefDesktop() {
}

/**
* Open a http/pdf/ps viewer for the given link string.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private void registerHyperlinkListener() {
this.addHyperlinkListener(e -> {
try {
if ((e.getURL() != null) && (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)) {
new JabRefDesktop().openBrowser(e.getURL().toString());
JabRefDesktop.openBrowser(e.getURL().toString());
}
} catch (IOException e1) {
LOGGER.error(e1.getMessage(), e1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@

public class FieldExtraComponents {


private FieldExtraComponents() {
}

private static final Log LOGGER = LogFactory.getLog(FieldExtraComponents.class);

private static final String ABBREVIATION_TOOLTIP_TEXT = "<HTML>"
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/gui/exporter/ExportAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class ExportAction {

private static final Log LOGGER = LogFactory.getLog(ExportAction.class);

private ExportAction() {
}


/**
* Create an AbstractAction for performing an export operation.
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/gui/externalfiles/AutoSetLinks.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@

public class AutoSetLinks {

private AutoSetLinks() {
}

/**
* Shortcut method if links are set without using the GUI
*
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/gui/groups/GroupDescriptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

public class GroupDescriptions {

private GroupDescriptions() {
}

public static String getDescriptionForPreview(String field, String expr, boolean caseSensitive, boolean regExp) {
String header = regExp ? Localization.lang(
"This group contains entries whose <b>%0</b> field contains the regular expression <b>%1</b>",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@

public class UndoableChangeEntriesOfGroup {

public static AbstractUndoableEdit getUndoableEdit(GroupTreeNodeViewModel node, List<FieldChange> changes) {
boolean hasEntryChanges = false;
NamedCompound entryChangeCompound = new NamedCompound(Localization.lang("change entries of group"));
for (FieldChange fieldChange : changes) {
hasEntryChanges = true;
entryChangeCompound.addEdit(new UndoableFieldChange(fieldChange));
}
if (hasEntryChanges) {
entryChangeCompound.end();
return entryChangeCompound;
}
private UndoableChangeEntriesOfGroup() {
}

return null;
public static AbstractUndoableEdit getUndoableEdit(GroupTreeNodeViewModel node, List<FieldChange> changes) {
boolean hasEntryChanges = false;
NamedCompound entryChangeCompound = new NamedCompound(Localization.lang("change entries of group"));
for(FieldChange fieldChange : changes) {
hasEntryChanges = true;
entryChangeCompound.addEdit(new UndoableFieldChange(fieldChange));
}
if (hasEntryChanges) {
entryChangeCompound.end();
return entryChangeCompound;
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

public class WarnAssignmentSideEffects {

private WarnAssignmentSideEffects() {
}

/**
* Warns the user of undesired side effects of an explicit assignment/removal of entries to/from this group.
* Currently there are four types of groups: AllEntriesGroup, SearchGroup - do not support explicit assignment.
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/gui/importer/ImportFileFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

class ImportFileFilter {

private ImportFileFilter() {
}

public static FileChooser.ExtensionFilter convert(Importer format) {
return new FileChooser.ExtensionFilter(format.getExtensions().getDescription(),
format.getExtensions().getExtensions());
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/gui/importer/ImportFormats.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
public class ImportFormats {
private static final Log LOGGER = LogFactory.getLog(ImportFormats.class);

private ImportFormats() {
}

/**
* Create an AbstractAction for performing an Import operation.
* @param frame The JabRefFrame of this JabRef instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
*/
public class ParserResultWarningDialog {

private ParserResultWarningDialog() {
}

/**
* Shows a dialog with the warnings from an import or open of a file
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

public class JournalAbbreviationsUtil {

private JournalAbbreviationsUtil() {
}

public static TableModel getTableModel(Collection<Abbreviation> abbreviations) {
Object[][] cells = new Object[abbreviations.size()][2];
int row = 0;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/gui/keyboard/EmacsKeyBindings.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ public class EmacsKeyBindings {
new JEditorPane(),
};

private EmacsKeyBindings() {
}

/**
* Loads the emacs keybindings for all common <code>JTextComponent</code>s.
*
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/gui/keyboard/KeyBinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

public class KeyBinder {

private KeyBinder() {
}

/**
* Binds ESC-Key to cancel button
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

public class MainTableNameFormatter {

private MainTableNameFormatter(){}

/**
* Format a name field for the table, according to user preferences.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
*/
public class JTextFieldChangeListenerUtil {

private JTextFieldChangeListenerUtil() {
}

/**
* Installs a listener to receive notification when the text of any
* {@code JTextComponent} is changed. Internally, it installs a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

public class SpecialFieldDropDown {

private SpecialFieldDropDown() {
}

public static JButton generateSpecialFieldButtonWithDropDown(SpecialField field, JabRefFrame frame) {
Dimension buttonDim = new Dimension(23, 23);
SpecialFieldViewModel viewModel = new SpecialFieldViewModel(field);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/jabref/gui/util/BindingsHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
* Some methods are taken from https://bugs.openjdk.java.net/browse/JDK-8134679
*/
public class BindingsHelper {

private BindingsHelper() {
}

public static <T> BooleanBinding any(ObservableList<T> source, Predicate<T> predicate) {
return Bindings.createBooleanBinding(() -> source.stream().anyMatch(predicate), source);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public class BibtexKeyPatternUtil {

private static final int CHARS_OF_FIRST = 5;

private BibtexKeyPatternUtil() {
}

private static String normalize(String content) {
List<String> tokens = new ArrayList<>();
int b = 0;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/logic/bst/BibtexNameFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
*/
public class BibtexNameFormatter {

private BibtexNameFormatter() {
}

public static String formatName(String authorsNameList, int whichName, String formatString, Warn warn) {
AuthorList al = AuthorList.parse(authorsNameList);

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/logic/bst/BibtexPurify.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
*/
public class BibtexPurify {

private BibtexPurify() {
}

/**
*
* @param toPurify
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/logic/bst/BibtexTextPrefix.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/
public class BibtexTextPrefix {

private BibtexTextPrefix() {
}

/**
*
* @param numOfChars
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/jabref/logic/bst/BibtexWidth.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class BibtexWidth {

private static int[] widths;


static {
if (BibtexWidth.widths == null) {
BibtexWidth.widths = new int[128];
Expand Down Expand Up @@ -135,6 +134,9 @@ public class BibtexWidth {
}
}

private BibtexWidth() {
}

private static int getSpecialCharWidth(char[] c, int pos) {
if ((pos + 1) < c.length) {
if ((c[pos] == 'o') && (c[pos + 1] == 'e')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public class CitationStyleGenerator {
private static final Log LOGGER = LogFactory.getLog(CitationStyleGenerator.class);
private static final BibTeXConverter BIBTEX_CONVERTER = new BibTeXConverter();

private CitationStyleGenerator() {
}

/**
* WARNING: the citation is generated using JavaScript which may take some time, better call it from outside the main Thread
* Generates a Citation based on the given entry and style
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/logic/cleanup/Cleanups.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public class Cleanups {
RECOMMEND_BIBLATEX_ACTIONS = new FieldFormatterCleanups(false, recommendedBiblatexFormatters);
}

private Cleanups() {
}

public static List<Formatter> getAvailableFormatters() {
return Collections.unmodifiableList(availableFormatters);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/logic/exporter/ExportFormats.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class ExportFormats {
// Global variable that is used for counting output entries when exporting:
public static int entryNumber;

private ExportFormats() {
}

public static void initAllExports(Map<String, ExportFormat> customFormats,
LayoutFormatterPreferences layoutPreferences, SavePreferences savePreferences) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

public class MetaDataSerializer {

private MetaDataSerializer() {
}

/**
* Writes all data in the format <key, serialized data>.
*/
Expand Down Expand Up @@ -90,7 +93,7 @@ private static Map<String, List<String>> serializeCiteKeyPattern(MetaData metaDa
stringyPattern.put(metaDataKey, data);
}
}
if (citeKeyPattern.getDefaultValue() != null && !citeKeyPattern.getDefaultValue().isEmpty()) {
if ((citeKeyPattern.getDefaultValue() != null) && !citeKeyPattern.getDefaultValue().isEmpty()) {
List<String> data = new ArrayList<>();
data.add(citeKeyPattern.getDefaultValue().get(0));
stringyPattern.put(MetaData.KEYPATTERNDEFAULT, data);
Expand Down
Loading

0 comments on commit 4ff55d0

Please sign in to comment.