Skip to content

Commit

Permalink
Replaced Map.get() with containsKey() where appropriate (#1146)
Browse files Browse the repository at this point in the history
  • Loading branch information
oscargus committed Apr 10, 2016
1 parent 1e80606 commit 26af87b
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 26 deletions.
12 changes: 6 additions & 6 deletions src/main/java/net/sf/jabref/external/RegExpFileSearch.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2003-2011 JabRef contributors.
/* Copyright (C) 2003-2016 JabRef contributors.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
Expand Down Expand Up @@ -54,10 +54,10 @@ public class RegExpFileSearch {
* @param regExp The expression deciding which names are acceptable.
* @return A map linking each given entry to a list of files matching the given criteria.
*/
public static Map<BibEntry, java.util.List<File>> findFilesForSet(Collection<BibEntry> entries,
public static Map<BibEntry, List<File>> findFilesForSet(Collection<BibEntry> entries,
Collection<String> extensions, List<File> directories, String regExp) {

Map<BibEntry, java.util.List<File>> res = new HashMap<>();
Map<BibEntry, List<File>> res = new HashMap<>();
for (BibEntry entry : entries) {
res.put(entry, RegExpFileSearch.findFiles(entry, extensions, directories, regExp));
}
Expand All @@ -83,7 +83,7 @@ private static List<File> findFiles(BibEntry entry, Collection<String> extension

/**
* Searches the given directory and filename pattern for a file for the
* bibtex entry.
* BibTeX entry.
*
* Used to fix:
*
Expand All @@ -99,7 +99,7 @@ private static List<File> findFiles(BibEntry entry, Collection<String> extension
* <ul>
* <li>* Any subDir</li>
* <li>** Any subDir (recursive)</li>
* <li>[key] Key from bibtex file and database</li>
* <li>[key] Key from BibTeX file and database</li>
* <li>.* Anything else is taken to be a Regular expression.</li>
* </ul>
*
Expand All @@ -121,7 +121,7 @@ private static List<File> findFiles(BibEntry entry, Collection<String> extension
*/
private static List<File> findFile(BibEntry entry, Collection<File> dirs, String file,
String extensionRegExp) {
ArrayList<File> res = new ArrayList<>();
List<File> res = new ArrayList<>();
for (File directory : dirs) {
res.addAll(RegExpFileSearch.findFile(entry, directory.getPath(), file, extensionRegExp));
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/sf/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2003-2015 JabRef contributors.
/* Copyright (C) 2003-2016 JabRef contributors.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
Expand Down Expand Up @@ -1026,7 +1026,7 @@ public void update() {
* @param _command The name of the command to run.
*/
public void runCommand(final String _command) {
if (actions.get(_command) == null) {
if (!actions.containsKey(_command)) {
LOGGER.info("No action defined for '" + _command + '\'');
return;
}
Expand Down Expand Up @@ -1448,7 +1448,7 @@ public void setupMainPanel() {
splitPane.setDividerSize(GUIGlobals.SPLIT_PANE_DIVIDER_SIZE);

// check whether a mainTable already existed and a floatSearch was active
boolean floatSearchActive = (mainTable != null) && this.tableModel.getSearchState() == MainTableDataModel.DisplayOption.FLOAT;
boolean floatSearchActive = (mainTable != null) && (this.tableModel.getSearchState() == MainTableDataModel.DisplayOption.FLOAT);

createMainTable();

Expand Down Expand Up @@ -2346,7 +2346,7 @@ public Optional<String> searchAndOpen() {
} else {
result = FileUtil.findAssociatedFiles(entries, extensions, dirs);
}
if (result.get(entry) != null) {
if (result.containsKey(entry)) {
final List<File> res = result.get(entry);
if (!res.isEmpty()) {
final String filepath = res.get(0).getPath();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/gui/SidePaneManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public SidePane getPanel() {
}

public synchronized boolean hasComponent(String name) {
return components.get(name) != null;
return components.containsKey(name);
}

public synchronized boolean isComponentVisible(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,14 @@ public int size() {
}

public boolean isKnownName(String journalName) {
String nameKey = Objects.requireNonNull(journalName).trim().toLowerCase();
return (fullNameLowerCase2Abbreviation.get(nameKey) != null)
|| (isoLowerCase2Abbreviation.get(nameKey) != null)
|| (medlineLowerCase2Abbreviation.get(nameKey) != null);
String nameKey = Objects.requireNonNull(journalName).trim().toLowerCase(Locale.ENGLISH);
return (fullNameLowerCase2Abbreviation.containsKey(nameKey)) || (isoLowerCase2Abbreviation.containsKey(nameKey))
|| (medlineLowerCase2Abbreviation.containsKey(nameKey));
}

public boolean isAbbreviatedName(String journalName) {
String nameKey = Objects.requireNonNull(journalName).trim().toLowerCase();
return (isoLowerCase2Abbreviation.get(nameKey) != null)
|| (medlineLowerCase2Abbreviation.get(nameKey) != null);
String nameKey = Objects.requireNonNull(journalName).trim().toLowerCase(Locale.ENGLISH);
return (isoLowerCase2Abbreviation.containsKey(nameKey)) || (medlineLowerCase2Abbreviation.containsKey(nameKey));
}

/**
Expand All @@ -57,7 +55,7 @@ public boolean isAbbreviatedName(String journalName) {
* @return The abbreviated name
*/
public Optional<Abbreviation> getAbbreviation(String journalName) {
String nameKey = Objects.requireNonNull(journalName).toLowerCase().trim();
String nameKey = Objects.requireNonNull(journalName).toLowerCase(Locale.ENGLISH).trim();

if (fullNameLowerCase2Abbreviation.containsKey(nameKey)) {
return Optional.of(fullNameLowerCase2Abbreviation.get(nameKey));
Expand All @@ -82,9 +80,10 @@ public void addEntry(Abbreviation abbreviation) {

abbreviations.add(abbreviation);

fullNameLowerCase2Abbreviation.put(abbreviation.getName().toLowerCase(), abbreviation);
isoLowerCase2Abbreviation.put(abbreviation.getIsoAbbreviation().toLowerCase(), abbreviation);
medlineLowerCase2Abbreviation.put(abbreviation.getMedlineAbbreviation().toLowerCase(), abbreviation);
fullNameLowerCase2Abbreviation.put(abbreviation.getName().toLowerCase(Locale.ENGLISH), abbreviation);
isoLowerCase2Abbreviation.put(abbreviation.getIsoAbbreviation().toLowerCase(Locale.ENGLISH), abbreviation);
medlineLowerCase2Abbreviation.put(abbreviation.getMedlineAbbreviation().toLowerCase(Locale.ENGLISH),
abbreviation);
}

public void addEntries(List<Abbreviation> abbreviationsToAdd) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/sf/jabref/logic/openoffice/OOBibStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,11 @@ public Layout getReferenceFormat(String type) {
*/
public String getNumCitationMarker(List<Integer> number, int minGroupingCount, boolean inList) {
String bracketBefore = getStringCitProperty(BRACKET_BEFORE);
if (inList && (citProperties.get(BRACKET_BEFORE_IN_LIST) != null)) {
if (inList && (citProperties.containsKey(BRACKET_BEFORE_IN_LIST))) {
bracketBefore = getStringCitProperty(BRACKET_BEFORE_IN_LIST);
}
String bracketAfter = getStringCitProperty(BRACKET_AFTER);
if (inList && (citProperties.get(BRACKET_AFTER_IN_LIST) != null)) {
if (inList && (citProperties.containsKey(BRACKET_AFTER_IN_LIST))) {
bracketAfter = getStringCitProperty(BRACKET_AFTER_IN_LIST);
}
// Sort the numbers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static void upgradeFaultyEncodingStrings() {
encodingMap.put("Big5_HKSCS", "Big5-HKSCS");
encodingMap.put("EUC_JP", "EUC-JP");

if (encodingMap.get(defaultEncoding) != null) {
if (encodingMap.containsKey(defaultEncoding)) {
prefs.put(JabRefPreferences.DEFAULT_ENCODING, encodingMap.get(defaultEncoding));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/model/EntryTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void removeType(String name) {
if (!ALL_TYPES.get(toLowerCase).equals(STANDARD_TYPES.get(toLowerCase))) {
ALL_TYPES.remove(toLowerCase);

if (STANDARD_TYPES.get(toLowerCase) != null) {
if (STANDARD_TYPES.containsKey(toLowerCase)) {
// In this case the user has removed a customized version
// of a standard type. We reinstate the standard type.
addOrModifyEntryType(STANDARD_TYPES.get(toLowerCase));
Expand Down

0 comments on commit 26af87b

Please sign in to comment.