From c7de8dea7c44fc3a45188d6bc03c2d9586a1574e Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Sat, 9 Dec 2017 13:55:16 +0100 Subject: [PATCH 1/6] Refactor BibTeX key generator --- .../org/jabref/cli/ArgumentProcessor.java | 19 +- src/main/java/org/jabref/gui/BasePanel.java | 27 +- .../java/org/jabref/gui/EntryTypeDialog.java | 4 +- .../org/jabref/gui/GenFieldsCustomizer.java | 4 +- .../SearchFixDuplicateLabels.java | 13 +- .../gui/customentrytypes/EntryTypeList.java | 4 +- .../customentrytypes/FieldSetComponent.java | 4 +- .../jabref/gui/entryeditor/EntryEditor.java | 24 +- .../gui/importer/ImportInspectionDialog.java | 14 +- .../gui/openoffice/OpenOfficePanel.java | 13 +- .../jabref/gui/undo/UndoableKeyChange.java | 4 + ...tternUtil.java => BibtexKeyGenerator.java} | 165 ++++--- .../importer/fileformat/EndnoteImporter.java | 4 +- .../importer/fileformat/FreeCiteImporter.java | 9 +- .../integrity/BibtexkeyDeviationChecker.java | 4 +- .../java/org/jabref/model/entry/BibEntry.java | 4 +- .../org/jabref/pdfimport/PdfImporter.java | 8 +- .../jabref/preferences/JabRefPreferences.java | 2 +- ...lTest.java => BibtexKeyGeneratorTest.java} | 442 +++++++++--------- .../MakeLabelWithDatabaseTest.java | 117 ++--- .../MakeLabelWithoutDatabaseTest.java | 4 +- 21 files changed, 427 insertions(+), 462 deletions(-) rename src/main/java/org/jabref/logic/bibtexkeypattern/{BibtexKeyPatternUtil.java => BibtexKeyGenerator.java} (70%) rename src/test/java/org/jabref/logic/bibtexkeypattern/{BibtexKeyPatternUtilTest.java => BibtexKeyGeneratorTest.java} (59%) diff --git a/src/main/java/org/jabref/cli/ArgumentProcessor.java b/src/main/java/org/jabref/cli/ArgumentProcessor.java index b5079bbcb1c..da5369d3daa 100644 --- a/src/main/java/org/jabref/cli/ArgumentProcessor.java +++ b/src/main/java/org/jabref/cli/ArgumentProcessor.java @@ -18,7 +18,7 @@ import org.jabref.gui.externalfiles.AutoSetLinks; import org.jabref.gui.importer.fetcher.EntryFetcher; import org.jabref.gui.importer.fetcher.EntryFetchers; -import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; +import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator; import org.jabref.logic.exporter.BibDatabaseWriter; import org.jabref.logic.exporter.BibtexDatabaseWriter; import org.jabref.logic.exporter.ExportFormat; @@ -46,7 +46,6 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntry; -import org.jabref.model.metadata.MetaData; import org.jabref.model.strings.StringUtil; import org.jabref.preferences.SearchPreferences; import org.jabref.shared.prefs.SharedDatabasePreferences; @@ -509,17 +508,11 @@ private void regenerateBibtexKeys(List loaded) { for (ParserResult parserResult : loaded) { BibDatabase database = parserResult.getDatabase(); - MetaData metaData = parserResult.getMetaData(); - if (metaData != null) { - LOGGER.info(Localization.lang("Regenerating BibTeX keys according to metadata")); - for (BibEntry entry : database.getEntries()) { - // try to make a new label - BibtexKeyPatternUtil.makeAndSetLabel( - metaData.getCiteKeyPattern(Globals.prefs.getBibtexKeyPatternPreferences().getKeyPattern()), - database, entry, Globals.prefs.getBibtexKeyPatternPreferences()); - } - } else { - LOGGER.info(Localization.lang("No meta data present in BIB file. Cannot regenerate BibTeX keys")); + LOGGER.info(Localization.lang("Regenerating BibTeX keys according to metadata")); + + BibtexKeyGenerator keyGenerator = new BibtexKeyGenerator(parserResult.getDatabaseContext(), Globals.prefs.getBibtexKeyPatternPreferences()); + for (BibEntry entry : database.getEntries()) { + keyGenerator.generateAndSetKey(entry); } } } diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 7020faa005c..2c39ca12cec 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -99,7 +99,7 @@ import org.jabref.gui.worker.CitationStyleToClipboardWorker; import org.jabref.gui.worker.MarkEntriesAction; import org.jabref.gui.worker.SendAsEMailAction; -import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; +import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator; import org.jabref.logic.citationstyle.CitationStyleCache; import org.jabref.logic.citationstyle.CitationStyleOutputFormat; import org.jabref.logic.exporter.BibtexDatabaseWriter; @@ -119,7 +119,6 @@ import org.jabref.logic.util.io.FileFinders; import org.jabref.logic.util.io.FileUtil; import org.jabref.model.FieldChange; -import org.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern; import org.jabref.model.database.BibDatabase; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.DatabaseLocation; @@ -136,6 +135,7 @@ import org.jabref.model.entry.event.EntryEventSource; import org.jabref.model.entry.specialfields.SpecialField; import org.jabref.model.entry.specialfields.SpecialFieldValue; +import org.jabref.model.strings.StringUtil; import org.jabref.preferences.JabRefPreferences; import org.jabref.preferences.PreviewPreferences; import org.jabref.shared.DBMSSynchronizer; @@ -448,16 +448,10 @@ public void run() { // generate the new cite keys for each entry final NamedCompound ce = new NamedCompound(Localization.lang("Autogenerate BibTeX keys")); - AbstractBibtexKeyPattern citeKeyPattern = bibDatabaseContext.getMetaData() - .getCiteKeyPattern(Globals.prefs.getBibtexKeyPatternPreferences().getKeyPattern()); + BibtexKeyGenerator keyGenerator = new BibtexKeyGenerator(bibDatabaseContext, Globals.prefs.getBibtexKeyPatternPreferences()); for (BibEntry entry : entries) { - String oldCiteKey = entry.getCiteKeyOptional().orElse(""); - BibtexKeyPatternUtil.makeAndSetLabel(citeKeyPattern, bibDatabaseContext.getDatabase(), - entry, Globals.prefs.getBibtexKeyPatternPreferences()); - String newCiteKey = entry.getCiteKeyOptional().orElse(""); - if (!oldCiteKey.equals(newCiteKey)) { - ce.addEdit(new UndoableKeyChange(entry, oldCiteKey, newCiteKey)); - } + Optional change = keyGenerator.generateAndSetKey(entry); + change.ifPresent(fieldChange -> ce.addEdit(new UndoableKeyChange(fieldChange))); } ce.end(); @@ -1735,15 +1729,12 @@ public void autoGenerateKeysBeforeSaving() { if (Globals.prefs.getBoolean(JabRefPreferences.GENERATE_KEYS_BEFORE_SAVING)) { NamedCompound ce = new NamedCompound(Localization.lang("Autogenerate BibTeX keys")); + BibtexKeyGenerator keyGenerator = new BibtexKeyGenerator(bibDatabaseContext, Globals.prefs.getBibtexKeyPatternPreferences()); for (BibEntry bes : bibDatabaseContext.getDatabase().getEntries()) { Optional oldKey = bes.getCiteKeyOptional(); - if (!(oldKey.isPresent()) || oldKey.get().isEmpty()) { - BibtexKeyPatternUtil.makeAndSetLabel(bibDatabaseContext.getMetaData() - .getCiteKeyPattern(Globals.prefs.getBibtexKeyPatternPreferences().getKeyPattern()), - bibDatabaseContext.getDatabase(), - bes, Globals.prefs.getBibtexKeyPatternPreferences()); - bes.getCiteKeyOptional().ifPresent( - newKey -> ce.addEdit(new UndoableKeyChange(bes, oldKey.orElse(""), newKey))); + if (StringUtil.isBlank(oldKey)) { + Optional change = keyGenerator.generateAndSetKey(bes); + change.ifPresent(fieldChange -> ce.addEdit(new UndoableKeyChange(fieldChange))); } } diff --git a/src/main/java/org/jabref/gui/EntryTypeDialog.java b/src/main/java/org/jabref/gui/EntryTypeDialog.java index 84a736773c4..83d655539f9 100644 --- a/src/main/java/org/jabref/gui/EntryTypeDialog.java +++ b/src/main/java/org/jabref/gui/EntryTypeDialog.java @@ -30,7 +30,7 @@ import org.jabref.gui.importer.ImportInspectionDialog; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.logic.bibtex.DuplicateCheck; -import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; +import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator; import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.IdBasedFetcher; import org.jabref.logic.importer.WebFetchers; @@ -319,7 +319,7 @@ protected void done() { diag.toFront(); } else { // Regenerate CiteKey of imported BibEntry - BibtexKeyPatternUtil.makeAndSetLabel(Globals.prefs.getBibtexKeyPatternPreferences().getKeyPattern(), frame.getCurrentBasePanel().getDatabase(), bibEntry, Globals.prefs.getBibtexKeyPatternPreferences()); + new BibtexKeyGenerator(frame.getCurrentBasePanel().getBibDatabaseContext(), Globals.prefs.getBibtexKeyPatternPreferences()).generateAndSetKey(bibEntry); // Update Timestamps if (Globals.prefs.getTimestampPreferences().includeCreatedTimestamp()) { bibEntry.setField(Globals.prefs.getTimestampPreferences().getTimestampField(), Globals.prefs.getTimestampPreferences().now()); diff --git a/src/main/java/org/jabref/gui/GenFieldsCustomizer.java b/src/main/java/org/jabref/gui/GenFieldsCustomizer.java index d7b93d7b349..b8b3a800b76 100644 --- a/src/main/java/org/jabref/gui/GenFieldsCustomizer.java +++ b/src/main/java/org/jabref/gui/GenFieldsCustomizer.java @@ -24,7 +24,7 @@ import org.jabref.gui.entryeditor.EntryEditorTabList; import org.jabref.gui.help.HelpAction; import org.jabref.gui.keyboard.KeyBinding; -import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; +import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator; import org.jabref.logic.help.HelpFile; import org.jabref.logic.l10n.Localization; import org.jabref.preferences.JabRefPreferences; @@ -119,7 +119,7 @@ private void okActionPerformed() { Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); return; } - String testString = BibtexKeyPatternUtil.checkLegalKey(parts[1], + String testString = BibtexKeyGenerator.cleanKey(parts[1], Globals.prefs.getBoolean(JabRefPreferences.ENFORCE_LEGAL_BIBTEX_KEY)); if (!testString.equals(parts[1]) || (parts[1].indexOf('&') >= 0)) { // Report error and exit. diff --git a/src/main/java/org/jabref/gui/bibtexkeypattern/SearchFixDuplicateLabels.java b/src/main/java/org/jabref/gui/bibtexkeypattern/SearchFixDuplicateLabels.java index 558dd6406de..3ea61a83dc6 100644 --- a/src/main/java/org/jabref/gui/bibtexkeypattern/SearchFixDuplicateLabels.java +++ b/src/main/java/org/jabref/gui/bibtexkeypattern/SearchFixDuplicateLabels.java @@ -4,6 +4,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import javax.swing.JCheckBox; @@ -12,8 +13,9 @@ import org.jabref.gui.undo.NamedCompound; import org.jabref.gui.undo.UndoableKeyChange; import org.jabref.gui.worker.AbstractWorker; -import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; +import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator; import org.jabref.logic.l10n.Localization; +import org.jabref.model.FieldChange; import org.jabref.model.database.BibDatabase; import org.jabref.model.entry.BibEntry; @@ -91,13 +93,10 @@ public void update() { // Do the actual generation: if (!toGenerateFor.isEmpty()) { NamedCompound ce = new NamedCompound(Localization.lang("Resolve duplicate BibTeX keys")); + BibtexKeyGenerator keyGenerator = new BibtexKeyGenerator(panel.getBibDatabaseContext(), Globals.prefs.getBibtexKeyPatternPreferences()); for (BibEntry entry : toGenerateFor) { - String oldKey = entry.getCiteKeyOptional().orElse(null); - BibtexKeyPatternUtil.makeAndSetLabel(panel.getBibDatabaseContext().getMetaData() - .getCiteKeyPattern(Globals.prefs.getBibtexKeyPatternPreferences().getKeyPattern()), - panel.getDatabase(), entry, - Globals.prefs.getBibtexKeyPatternPreferences()); - ce.addEdit(new UndoableKeyChange(entry, oldKey, entry.getCiteKeyOptional().get())); + Optional change = keyGenerator.generateAndSetKey(entry); + change.ifPresent(fieldChange -> ce.addEdit(new UndoableKeyChange(fieldChange))); } ce.end(); panel.getUndoManager().addEdit(ce); diff --git a/src/main/java/org/jabref/gui/customentrytypes/EntryTypeList.java b/src/main/java/org/jabref/gui/customentrytypes/EntryTypeList.java index b456654cfff..5f27c6a14e8 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/EntryTypeList.java +++ b/src/main/java/org/jabref/gui/customentrytypes/EntryTypeList.java @@ -12,7 +12,7 @@ import javax.swing.event.ListSelectionListener; import org.jabref.Globals; -import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; +import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator; import org.jabref.logic.l10n.Localization; import org.jabref.model.EntryTypes; import org.jabref.model.database.BibDatabaseMode; @@ -57,7 +57,7 @@ protected void addField(String str) { return; } - String testString = BibtexKeyPatternUtil.checkLegalKey(s, + String testString = BibtexKeyGenerator.cleanKey(s, Globals.prefs.getBoolean(JabRefPreferences.ENFORCE_LEGAL_BIBTEX_KEY)); if (!testString.equals(s) || (s.indexOf('&') >= 0)) { // Report error and exit. diff --git a/src/main/java/org/jabref/gui/customentrytypes/FieldSetComponent.java b/src/main/java/org/jabref/gui/customentrytypes/FieldSetComponent.java index f7d17f4a95b..6dbfcae9830 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/FieldSetComponent.java +++ b/src/main/java/org/jabref/gui/customentrytypes/FieldSetComponent.java @@ -34,7 +34,7 @@ import org.jabref.Globals; import org.jabref.gui.IconTheme; -import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; +import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator; import org.jabref.logic.l10n.Localization; import org.jabref.preferences.JabRefPreferences; @@ -242,7 +242,7 @@ protected void addField(String str) { return; } - String testString = BibtexKeyPatternUtil.checkLegalKey(s, + String testString = BibtexKeyGenerator.cleanKey(s, Globals.prefs.getBoolean(JabRefPreferences.ENFORCE_LEGAL_BIBTEX_KEY)); if (!testString.equals(s) || (s.indexOf('&') >= 0)) { // Report error and exit. diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index 29fb6d18cf2..46ad8bc803e 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -70,7 +70,7 @@ import org.jabref.logic.TypedBibEntry; import org.jabref.logic.bibtex.InvalidFieldValueException; import org.jabref.logic.bibtex.LatexFieldFormatter; -import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; +import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator; import org.jabref.logic.help.HelpFile; import org.jabref.logic.importer.EntryBasedFetcher; import org.jabref.logic.importer.WebFetchers; @@ -80,6 +80,7 @@ import org.jabref.logic.util.OS; import org.jabref.logic.util.UpdateField; import org.jabref.model.EntryTypes; +import org.jabref.model.FieldChange; import org.jabref.model.database.BibDatabase; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.EntryType; @@ -655,7 +656,7 @@ public void actionPerformed(ActionEvent event) { } // Make sure the key is legal: - String cleaned = BibtexKeyPatternUtil.checkLegalKey(newValue, + String cleaned = BibtexKeyGenerator.cleanKey(newValue, Globals.prefs.getBoolean(JabRefPreferences.ENFORCE_LEGAL_BIBTEX_KEY)); if ((cleaned == null) || cleaned.equals(newValue)) { textField.setValidBackgroundColor(); @@ -852,22 +853,9 @@ public void actionPerformed(ActionEvent e) { } } - BibtexKeyPatternUtil.makeAndSetLabel(panel.getBibDatabaseContext().getMetaData() - .getCiteKeyPattern(Globals.prefs.getBibtexKeyPatternPreferences().getKeyPattern()), - panel.getDatabase(), entry, - Globals.prefs.getBibtexKeyPatternPreferences()); - - if (entry.hasCiteKey()) { - // Store undo information: - panel.getUndoManager().addEdit( - new UndoableKeyChange(entry, oldValue.orElse(null), - entry.getCiteKeyOptional().get())); // Cite key always set here - - // here we update the field - String bibtexKeyData = entry.getCiteKeyOptional().get(); - entry.setField(BibEntry.KEY_FIELD, bibtexKeyData); - panel.markBaseChanged(); - } + Optional change = new BibtexKeyGenerator(panel.getBibDatabaseContext(), Globals.prefs.getBibtexKeyPatternPreferences()) + .generateAndSetKey(entry); + change.ifPresent(fieldChange -> panel.getUndoManager().addEdit(new UndoableKeyChange(fieldChange))); } } diff --git a/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java b/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java index cdf00d5d921..32b46822ec5 100644 --- a/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java +++ b/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java @@ -78,7 +78,7 @@ import org.jabref.gui.util.component.CheckBoxMessage; import org.jabref.logic.bibtex.DuplicateCheck; import org.jabref.logic.bibtex.comparator.FieldComparator; -import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; +import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator; import org.jabref.logic.help.HelpFile; import org.jabref.logic.importer.ImportInspector; import org.jabref.logic.importer.OutputPrinter; @@ -453,10 +453,8 @@ private void generateKeyForEntry(BibEntry entry) { database.insertEntry(entry); // Generate a unique key: - BibtexKeyPatternUtil.makeAndSetLabel( - localMetaData.getCiteKeyPattern(Globals.prefs.getBibtexKeyPatternPreferences().getKeyPattern()), - database, entry, - Globals.prefs.getBibtexKeyPatternPreferences()); + new BibtexKeyGenerator(localMetaData.getCiteKeyPattern(Globals.prefs.getBibtexKeyPatternPreferences().getKeyPattern()), + database, Globals.prefs.getBibtexKeyPatternPreferences()).generateAndSetKey(entry); // Remove the entry from the database again, since we only added it in // order to // make sure the key was unique: @@ -497,10 +495,8 @@ private void generateKeys() { entry.setId(IdGenerator.next()); database.insertEntry(entry); - BibtexKeyPatternUtil.makeAndSetLabel( - localMetaData.getCiteKeyPattern(Globals.prefs.getBibtexKeyPatternPreferences().getKeyPattern()), - database, entry, - Globals.prefs.getBibtexKeyPatternPreferences()); + new BibtexKeyGenerator(localMetaData.getCiteKeyPattern(Globals.prefs.getBibtexKeyPatternPreferences().getKeyPattern()), + database, Globals.prefs.getBibtexKeyPatternPreferences()).generateAndSetKey(entry); // Add the generated key to our list: -- TODO: Why?? keys.add(entry.getCiteKeyOptional()); } diff --git a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java index 81e76f6f6f4..649c3716ed6 100644 --- a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java +++ b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java @@ -50,8 +50,8 @@ import org.jabref.gui.util.DirectoryDialogConfiguration; import org.jabref.gui.util.FileDialogConfiguration; import org.jabref.gui.worker.AbstractWorker; +import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator; import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences; -import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; import org.jabref.logic.help.HelpFile; import org.jabref.logic.l10n.Localization; import org.jabref.logic.openoffice.OOBibStyle; @@ -660,14 +660,9 @@ private boolean checkThatEntriesHaveKeys(List entries) { for (BibEntry entry : entries) { if (!entry.getCiteKeyOptional().isPresent()) { // Generate key - BibtexKeyPatternUtil - .makeAndSetLabel( - panel.getBibDatabaseContext().getMetaData().getCiteKeyPattern(prefs.getKeyPattern()), - panel.getDatabase(), entry, - prefs); - // Add undo change - undoCompound.addEdit( - new UndoableKeyChange(entry, null, entry.getCiteKeyOptional().get())); + new BibtexKeyGenerator(panel.getBibDatabaseContext(), prefs) + .generateAndSetKey(entry) + .ifPresent(change -> undoCompound.addEdit(new UndoableKeyChange(change))); } } undoCompound.end(); diff --git a/src/main/java/org/jabref/gui/undo/UndoableKeyChange.java b/src/main/java/org/jabref/gui/undo/UndoableKeyChange.java index 531c167d8e2..804e06efee8 100644 --- a/src/main/java/org/jabref/gui/undo/UndoableKeyChange.java +++ b/src/main/java/org/jabref/gui/undo/UndoableKeyChange.java @@ -1,6 +1,7 @@ package org.jabref.gui.undo; import org.jabref.logic.l10n.Localization; +import org.jabref.model.FieldChange; import org.jabref.model.entry.BibEntry; import org.jabref.model.strings.StringUtil; @@ -15,6 +16,9 @@ public class UndoableKeyChange extends AbstractUndoableJabRefEdit { private final String oldValue; private final String newValue; + public UndoableKeyChange(FieldChange change) { + this(change.getEntry(), change.getOldValue(), change.getNewValue()); + } public UndoableKeyChange(BibEntry entry, String oldValue, String newValue) { this.entry = entry; diff --git a/src/main/java/org/jabref/logic/bibtexkeypattern/BibtexKeyPatternUtil.java b/src/main/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGenerator.java similarity index 70% rename from src/main/java/org/jabref/logic/bibtexkeypattern/BibtexKeyPatternUtil.java rename to src/main/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGenerator.java index 72e404352fd..8bf54c59e34 100644 --- a/src/main/java/org/jabref/logic/bibtexkeypattern/BibtexKeyPatternUtil.java +++ b/src/main/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGenerator.java @@ -3,8 +3,10 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; +import java.util.Optional; import org.jabref.logic.util.BracketedPattern; +import org.jabref.model.FieldChange; import org.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern; import org.jabref.model.database.BibDatabase; import org.jabref.model.database.BibDatabaseContext; @@ -18,33 +20,88 @@ /** * This is the utility class of the LabelPattern package. */ -public class BibtexKeyPatternUtil extends BracketedPattern { - private static final Log LOGGER = LogFactory.getLog(BibtexKeyPatternUtil.class); +public class BibtexKeyGenerator extends BracketedPattern { + private static final Log LOGGER = LogFactory.getLog(BibtexKeyGenerator.class); - // All single characters that we can use for extending a key to make it unique: - private static final String CHARS = "abcdefghijklmnopqrstuvwxyz"; + /* + * All single characters that we can use for extending a key to make it unique. + */ + private static final String APPENDIX_CHARACTERS = "abcdefghijklmnopqrstuvwxyz"; + private final AbstractBibtexKeyPattern citeKeyPattern; + private final BibDatabase database; + private final BibtexKeyPatternPreferences bibtexKeyPatternPreferences; + + public BibtexKeyGenerator(BibDatabaseContext bibDatabaseContext, BibtexKeyPatternPreferences bibtexKeyPatternPreferences) { + this(bibDatabaseContext.getMetaData().getCiteKeyPattern(bibtexKeyPatternPreferences.getKeyPattern()), + bibDatabaseContext.getDatabase(), + bibtexKeyPatternPreferences); + } + + public BibtexKeyGenerator(AbstractBibtexKeyPattern citeKeyPattern, BibDatabase database, BibtexKeyPatternPreferences bibtexKeyPatternPreferences) { + this.citeKeyPattern = citeKeyPattern; + this.database = database; + this.bibtexKeyPatternPreferences = bibtexKeyPatternPreferences; + } - private BibtexKeyPatternUtil() { + static String generateKey(BibEntry entry, String value, Character keywordDelimiter, BibDatabase database) { + return expandBrackets("[" + value + "]", keywordDelimiter, entry, database); } /** - * Generates a BibTeX label according to the pattern for a given entry type, and saves the unique label in the - * Bibtexentry. + * Computes an appendix to a BibTeX key that could make it unique. We use + * a-z for numbers 0-25, and then aa-az, ba-bz, etc. * - * The given database is used to avoid duplicate keys. + * @param number + * The appendix number. + * @return The String to append. + */ + private static String getAppendix(int number) { + if (number >= APPENDIX_CHARACTERS.length()) { + int lastChar = number % APPENDIX_CHARACTERS.length(); + return getAppendix((number / APPENDIX_CHARACTERS.length()) - 1) + APPENDIX_CHARACTERS.substring(lastChar, lastChar + 1); + } else { + return APPENDIX_CHARACTERS.substring(number, number + 1); + } + } + + /** + * This method returns a String similar to the one passed in, except that it is molded into a form that is + * acceptable for bibtex. + *

+ * Watch-out that the returned string might be of length 0 afterwards. * - * @param citeKeyPattern - * @param database a BibDatabase - * @param entry a BibEntry - * @return modified BibEntry + * @param key the key to clean + * @param enforceLegalKey make sure that the key is legal in all respects */ - public static void makeAndSetLabel(AbstractBibtexKeyPattern citeKeyPattern, BibDatabase database, BibEntry entry, - BibtexKeyPatternPreferences bibtexKeyPatternPreferences) { - String newKey = makeLabel(citeKeyPattern, database, entry, bibtexKeyPatternPreferences); - entry.setCiteKey(newKey); + public static String cleanKey(String key, boolean enforceLegalKey) { + if (!enforceLegalKey) { + // User doesn't want us to enforce legal characters. We must still look + // for whitespace and some characters such as commas, since these would + // interfere with parsing: + StringBuilder newKey = new StringBuilder(); + for (int i = 0; i < key.length(); i++) { + char c = key.charAt(i); + if (!Character.isWhitespace(c) && ("{}(),\\\"".indexOf(c) == -1)) { + newKey.append(c); + } + } + return newKey.toString(); + } + + StringBuilder newKey = new StringBuilder(); + for (int i = 0; i < key.length(); i++) { + char c = key.charAt(i); + if (!Character.isWhitespace(c) && ("{}(),\\\"#~^'".indexOf(c) == -1)) { + newKey.append(c); + } + } + + // Replace non-English characters like umlauts etc. with a sensible + // letter or letter combination that bibtex can accept. + return StringUtil.replaceSpecialCharacters(newKey.toString()); } - private static String makeLabel(AbstractBibtexKeyPattern citeKeyPattern, BibDatabase database, BibEntry entry, BibtexKeyPatternPreferences bibtexKeyPatternPreferences) { + public String generateKey(BibEntry entry) { String key; StringBuilder stringBuilder = new StringBuilder(); try { @@ -84,7 +141,7 @@ private static String makeLabel(AbstractBibtexKeyPattern citeKeyPattern, BibData } // Remove all illegal characters from the key. - key = checkLegalKey(stringBuilder.toString(), bibtexKeyPatternPreferences.isEnforceLegalKey()); + key = cleanKey(stringBuilder.toString(), bibtexKeyPatternPreferences.isEnforceLegalKey()); // Remove Regular Expressions while generating Keys String regex = bibtexKeyPatternPreferences.getKeyPatternRegex(); @@ -112,7 +169,7 @@ private static String makeLabel(AbstractBibtexKeyPattern citeKeyPattern, BibData String moddedKey; do { - moddedKey = key + getAddition(number); + moddedKey = key + getAppendix(number); number++; occurrences = database.getDuplicationChecker().getNumberOfKeyOccurrences(moddedKey); @@ -127,72 +184,14 @@ private static String makeLabel(AbstractBibtexKeyPattern citeKeyPattern, BibData return newKey; } - public static String makeLabel(BibEntry entry, String value, Character keywordDelimiter, BibDatabase database) { - return expandBrackets("[" + value + "]", keywordDelimiter, entry, database); - } - - /** - * Computes an appendix to a BibTeX key that could make it unique. We use - * a-z for numbers 0-25, and then aa-az, ba-bz, etc. - * - * @param number - * The appendix number. - * @return The String to append. - */ - private static String getAddition(int number) { - if (number >= CHARS.length()) { - int lastChar = number % CHARS.length(); - return getAddition((number / CHARS.length()) - 1) + CHARS.substring(lastChar, lastChar + 1); - } else { - return CHARS.substring(number, number + 1); - } - } - /** - * This method returns a String similar to the one passed in, except that it is molded into a form that is - * acceptable for bibtex. - *

- * Watch-out that the returned string might be of length 0 afterwards. + * Generates a BibTeX key for the given entry, and sets the key. * - * @param key mayBeNull - * @param enforceLegalKey make sure that the key is legal in all respects + * @param entry the entry to generate the key for + * @return the change to the key (or an empty optional if the key was not changed) */ - public static String checkLegalKey(String key, boolean enforceLegalKey) { - if (key == null) { - return null; - } - if (!enforceLegalKey) { - // User doesn't want us to enforce legal characters. We must still look - // for whitespace and some characters such as commas, since these would - // interfere with parsing: - StringBuilder newKey = new StringBuilder(); - for (int i = 0; i < key.length(); i++) { - char c = key.charAt(i); - if (!Character.isWhitespace(c) && ("{}(),\\\"".indexOf(c) == -1)) { - newKey.append(c); - } - } - return newKey.toString(); - } - - StringBuilder newKey = new StringBuilder(); - for (int i = 0; i < key.length(); i++) { - char c = key.charAt(i); - if (!Character.isWhitespace(c) && ("{}(),\\\"#~^'".indexOf(c) == -1)) { - newKey.append(c); - } - } - - // Replace non-English characters like umlauts etc. with a sensible - // letter or letter combination that bibtex can accept. - - return StringUtil.replaceSpecialCharacters(newKey.toString()); - } - - public static String makeLabel(BibDatabaseContext bibDatabaseContext, - BibEntry entry, - BibtexKeyPatternPreferences bibtexKeyPatternPreferences) { - AbstractBibtexKeyPattern citeKeyPattern = bibDatabaseContext.getMetaData().getCiteKeyPattern(bibtexKeyPatternPreferences.getKeyPattern()); - return makeLabel(citeKeyPattern, bibDatabaseContext.getDatabase(), entry, bibtexKeyPatternPreferences); + public Optional generateAndSetKey(BibEntry entry) { + String newKey = generateKey(entry); + return entry.setCiteKey(newKey); } } diff --git a/src/main/java/org/jabref/logic/importer/fileformat/EndnoteImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/EndnoteImporter.java index 5e30924d3d4..640ce5fe616 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/EndnoteImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/EndnoteImporter.java @@ -8,7 +8,7 @@ import java.util.Map; import java.util.regex.Pattern; -import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; +import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.Importer; import org.jabref.logic.importer.ParserResult; @@ -229,7 +229,7 @@ else if ("P".equals(prefix)) { type = "mastersthesis"; } } else if ("F".equals(prefix)) { - hm.put(BibEntry.KEY_FIELD, BibtexKeyPatternUtil.checkLegalKey(val, + hm.put(BibEntry.KEY_FIELD, BibtexKeyGenerator.cleanKey(val, preferences.getBibtexKeyPatternPreferences().isEnforceLegalKey())); } } diff --git a/src/main/java/org/jabref/logic/importer/fileformat/FreeCiteImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/FreeCiteImporter.java index 63967d5903b..371db1f9be8 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/FreeCiteImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/FreeCiteImporter.java @@ -20,7 +20,7 @@ import javax.xml.stream.XMLStreamReader; import org.jabref.JabRefGUI; -import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; +import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.Importer; import org.jabref.logic.importer.ParserResult; @@ -205,11 +205,8 @@ public ParserResult importEntries(String text) { // autogenerate label (BibTeX key) if (JabRefGUI.getMainFrame() != null) { // only possible in GUI mode - BibtexKeyPatternUtil.makeAndSetLabel( - JabRefGUI.getMainFrame().getCurrentBasePanel().getBibDatabaseContext().getMetaData() - .getCiteKeyPattern(importFormatPreferences.getBibtexKeyPatternPreferences().getKeyPattern()), - JabRefGUI.getMainFrame().getCurrentBasePanel().getDatabase(), e, - importFormatPreferences.getBibtexKeyPatternPreferences()); + new BibtexKeyGenerator(JabRefGUI.getMainFrame().getCurrentBasePanel().getBibDatabaseContext(), importFormatPreferences.getBibtexKeyPatternPreferences()) + .generateAndSetKey(e); } res.add(e); diff --git a/src/main/java/org/jabref/logic/integrity/BibtexkeyDeviationChecker.java b/src/main/java/org/jabref/logic/integrity/BibtexkeyDeviationChecker.java index 773c343b135..b90a70410ef 100644 --- a/src/main/java/org/jabref/logic/integrity/BibtexkeyDeviationChecker.java +++ b/src/main/java/org/jabref/logic/integrity/BibtexkeyDeviationChecker.java @@ -5,8 +5,8 @@ import java.util.Objects; import java.util.Optional; +import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator; import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences; -import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; import org.jabref.logic.integrity.IntegrityCheck.Checker; import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseContext; @@ -32,7 +32,7 @@ public List check(BibEntry entry) { String key = valuekey.get(); // generate new key - String generatedKey = BibtexKeyPatternUtil.makeLabel(bibDatabaseContext, entry, bibtexKeyPatternPreferences); + String generatedKey = new BibtexKeyGenerator(bibDatabaseContext, bibtexKeyPatternPreferences).generateKey(entry); if (!Objects.equals(key, generatedKey)) { return Collections.singletonList(new IntegrityMessage( diff --git a/src/main/java/org/jabref/model/entry/BibEntry.java b/src/main/java/org/jabref/model/entry/BibEntry.java index 54e8e0000ab..bab785ff029 100644 --- a/src/main/java/org/jabref/model/entry/BibEntry.java +++ b/src/main/java/org/jabref/model/entry/BibEntry.java @@ -184,8 +184,8 @@ public String getCiteKey() { * * @param newCiteKey The cite key to set. Must not be null; use {@link #clearCiteKey()} to remove the cite key. */ - public void setCiteKey(String newCiteKey) { - setField(KEY_FIELD, newCiteKey); + public Optional setCiteKey(String newCiteKey) { + return setField(KEY_FIELD, newCiteKey); } public Optional getCiteKeyOptional() { diff --git a/src/main/java/org/jabref/pdfimport/PdfImporter.java b/src/main/java/org/jabref/pdfimport/PdfImporter.java index 8995ea13b07..d34cbe7cb6e 100644 --- a/src/main/java/org/jabref/pdfimport/PdfImporter.java +++ b/src/main/java/org/jabref/pdfimport/PdfImporter.java @@ -23,7 +23,7 @@ import org.jabref.gui.filelist.FileListTableModel; import org.jabref.gui.maintable.MainTable; import org.jabref.gui.undo.UndoableInsertEntry; -import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; +import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator; import org.jabref.logic.importer.ParserResult; import org.jabref.logic.importer.fileformat.PdfContentImporter; import org.jabref.logic.importer.fileformat.PdfXmpImporter; @@ -214,10 +214,8 @@ private void doContentImport(String fileName, List res) { // insert entry to database and link file panel.getDatabase().insertEntry(entry); panel.markBaseChanged(); - BibtexKeyPatternUtil.makeAndSetLabel(panel.getBibDatabaseContext().getMetaData() - .getCiteKeyPattern(Globals.prefs.getBibtexKeyPatternPreferences().getKeyPattern()), panel.getDatabase(), - entry, - Globals.prefs.getBibtexKeyPatternPreferences()); + new BibtexKeyGenerator(panel.getBibDatabaseContext(), Globals.prefs.getBibtexKeyPatternPreferences()) + .generateAndSetKey(entry); DroppedFileHandler dfh = new DroppedFileHandler(frame, panel); dfh.linkPdfToEntry(fileName, entry); diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 6bbd42f0710..1e30b85a240 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -1208,7 +1208,7 @@ public void putKeyPattern(GlobalBibtexKeyPattern pattern) { if (!pattern.isDefaultValue(key)) { // no default value // the first entry in the array is the full pattern - // see org.jabref.logic.labelPattern.BibtexKeyPatternUtil.split(String) + // see org.jabref.logic.labelPattern.BibtexKeyGenerator.split(String) pre.put(key, pattern.getValue(key).get(0)); } } diff --git a/src/test/java/org/jabref/logic/bibtexkeypattern/BibtexKeyPatternUtilTest.java b/src/test/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGeneratorTest.java similarity index 59% rename from src/test/java/org/jabref/logic/bibtexkeypattern/BibtexKeyPatternUtilTest.java rename to src/test/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGeneratorTest.java index 551134c45c1..1a6804772bf 100644 --- a/src/test/java/org/jabref/logic/bibtexkeypattern/BibtexKeyPatternUtilTest.java +++ b/src/test/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGeneratorTest.java @@ -17,7 +17,7 @@ import static org.junit.Assert.assertNull; import static org.mockito.Mockito.mock; -public class BibtexKeyPatternUtilTest { +public class BibtexKeyGeneratorTest { private static final String AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_1 = "Isaac Newton"; private static final String AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_2 = "Isaac Newton and James Maxwell"; @@ -53,7 +53,7 @@ public void testAndInAuthorName() throws ParseException { Optional entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Simon Holland}}", importFormatPreferences); assertEquals("Holland", - BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0.get(), "auth", + BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth", ',', new BibDatabase()), true)); } @@ -69,7 +69,7 @@ public void testCrossrefAndInAuthorNames() throws Exception { database.insertEntry(entry2); assertEquals("Holland", - BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry1, "auth", + BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry1, "auth", ',', database), true)); } @@ -78,7 +78,7 @@ public void testAndAuthorNames() throws ParseException { String bibtexString = "@ARTICLE{whatevery, author={Mari D. Herland and Mona-Iren Hauge and Ingeborg M. Helgeland}}"; Optional entry = BibtexParser.singleFromString(bibtexString, importFormatPreferences); assertEquals("HerlandHaugeHelgeland", - BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry.get(), "authors3", + BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry.get(), "authors3", ',', new BibDatabase()), true)); } @@ -94,7 +94,7 @@ public void testCrossrefAndAuthorNames() throws Exception { database.insertEntry(entry2); assertEquals("HerlandHaugeHelgeland", - BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry1, "authors3", + BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry1, "authors3", ',', database), true)); } @@ -103,7 +103,7 @@ public void testSpecialLatexCharacterInAuthorName() throws ParseException { Optional entry = BibtexParser.singleFromString( "@ARTICLE{kohn, author={Simon Popovi\\v{c}ov\\'{a}}}", importFormatPreferences); assertEquals("Popovicova", - BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry.get(), "auth", + BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry.get(), "auth", ',', new BibDatabase()), true)); } @@ -117,73 +117,73 @@ public void testMakeLabelAndCheckLegalKeys() throws ParseException { Optional entry0 = BibtexParser.singleFromString( "@ARTICLE{kohn, author={Andreas Köning}, year={2000}}", importFormatPreferences); assertEquals("Koen", - BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0.get(), "auth3", + BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", ',', new BibDatabase()), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Áöning}, year={2000}}", importFormatPreferences); assertEquals("Aoen", - BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0.get(), "auth3", + BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", ',', new BibDatabase()), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Éöning}, year={2000}}", importFormatPreferences); assertEquals("Eoen", - BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0.get(), "auth3", + BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", ',', new BibDatabase()), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Íöning}, year={2000}}", importFormatPreferences); assertEquals("Ioen", - BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0.get(), "auth3", + BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", ',', new BibDatabase()), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Ĺöning}, year={2000}}", importFormatPreferences); assertEquals("Loen", - BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0.get(), "auth3", + BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", ',', new BibDatabase()), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Ńöning}, year={2000}}", importFormatPreferences); assertEquals("Noen", - BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0.get(), "auth3", + BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", ',', new BibDatabase()), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Óöning}, year={2000}}", importFormatPreferences); assertEquals("Ooen", - BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0.get(), "auth3", + BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", ',', new BibDatabase()), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Ŕöning}, year={2000}}", importFormatPreferences); assertEquals("Roen", - BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0.get(), "auth3", + BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", ',', new BibDatabase()), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Śöning}, year={2000}}", importFormatPreferences); assertEquals("Soen", - BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0.get(), "auth3", + BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", ',', new BibDatabase()), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Úöning}, year={2000}}", importFormatPreferences); assertEquals("Uoen", - BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0.get(), "auth3", + BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", ',', new BibDatabase()), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Ýöning}, year={2000}}", importFormatPreferences); assertEquals("Yoen", - BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0.get(), "auth3", + BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", ',', new BibDatabase()), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Źöning}, year={2000}}", importFormatPreferences); assertEquals("Zoen", - BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0.get(), "auth3", + BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", ',', new BibDatabase()), true)); } @@ -195,31 +195,31 @@ public void testMakeLabelAndCheckLegalKeysAccentGrave() throws ParseException { Optional entry0 = BibtexParser.singleFromString( "@ARTICLE{kohn, author={Andreas Àöning}, year={2000}}", importFormatPreferences); assertEquals("Aoen", - BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0.get(), "auth3", + BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", ',', new BibDatabase()), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Èöning}, year={2000}}", importFormatPreferences); assertEquals("Eoen", - BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0.get(), "auth3", + BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", ',', new BibDatabase()), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Ìöning}, year={2000}}", importFormatPreferences); assertEquals("Ioen", - BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0.get(), "auth3", + BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", ',', new BibDatabase()), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Òöning}, year={2000}}", importFormatPreferences); assertEquals("Ooen", - BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0.get(), "auth3", + BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", ',', new BibDatabase()), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Ùöning}, year={2000}}", importFormatPreferences); assertEquals("Uoen", - BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0.get(), "auth3", + BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", ',', new BibDatabase()), true)); } @@ -227,7 +227,7 @@ public void testMakeLabelAndCheckLegalKeysAccentGrave() throws ParseException { * Tests if checkLegalKey replaces Non-ASCII chars. * There are quite a few chars that should be replaced. Perhaps there is a better method than the current. * - * @see BibtexKeyPatternUtil#checkLegalKey(String) + * @see BibtexKeyGenerator#checkLegalKey(String) */ @Test public void testCheckLegalKey() { @@ -238,43 +238,43 @@ public void testCheckLegalKey() { //"Ł ł Ő ő Ű ű Ŀ ŀ Ħ ħ Ð ð Þ þ Œ œ Æ æ Ø ø Å å Ə ə String accents = "ÀàÈèÌìÒòÙù  â Ĉ ĉ Ê ê Ĝ ĝ Ĥ ĥ Î î Ĵ ĵ Ô ô Ŝ ŝ Û û Ŵ ŵ Ŷ ŷ"; String expectedResult = "AaEeIiOoUuAaCcEeGgHhIiJjOoSsUuWwYy"; - assertEquals(expectedResult, BibtexKeyPatternUtil.checkLegalKey(accents, true)); + assertEquals(expectedResult, BibtexKeyGenerator.cleanKey(accents, true)); accents = "ÄäËëÏïÖöÜüŸÿ"; expectedResult = "AeaeEeIiOeoeUeueYy"; - assertEquals(expectedResult, BibtexKeyPatternUtil.checkLegalKey(accents, true)); + assertEquals(expectedResult, BibtexKeyGenerator.cleanKey(accents, true)); accents = "Ç ç Ģ ģ Ķ ķ Ļ ļ Ņ ņ Ŗ ŗ Ş ş Ţ ţ"; expectedResult = "CcGgKkLlNnRrSsTt"; - assertEquals(expectedResult, BibtexKeyPatternUtil.checkLegalKey(accents, true)); + assertEquals(expectedResult, BibtexKeyGenerator.cleanKey(accents, true)); accents = "Ă ă Ĕ ĕ Ğ ğ Ĭ ĭ Ŏ ŏ Ŭ ŭ"; expectedResult = "AaEeGgIiOoUu"; - assertEquals(expectedResult, BibtexKeyPatternUtil.checkLegalKey(accents, true)); + assertEquals(expectedResult, BibtexKeyGenerator.cleanKey(accents, true)); accents = "Ċ ċ Ė ė Ġ ġ İ ı Ż ż"; expectedResult = "CcEeGgIiZz"; - assertEquals(expectedResult, BibtexKeyPatternUtil.checkLegalKey(accents, true)); + assertEquals(expectedResult, BibtexKeyGenerator.cleanKey(accents, true)); accents = "Ą ą Ę ę Į į Ǫ ǫ Ų ų"; expectedResult = "AaEeIiOoUu"; // O or Q? o or q? - assertEquals(expectedResult, BibtexKeyPatternUtil.checkLegalKey(accents, true)); + assertEquals(expectedResult, BibtexKeyGenerator.cleanKey(accents, true)); accents = "Ā ā Ē ē Ī ī Ō ō Ū ū Ȳ ȳ"; expectedResult = "AaEeIiOoUuYy"; - assertEquals(expectedResult, BibtexKeyPatternUtil.checkLegalKey(accents, true)); + assertEquals(expectedResult, BibtexKeyGenerator.cleanKey(accents, true)); accents = "Ǎ ǎ Č č Ď ď Ě ě Ǐ ǐ Ľ ľ Ň ň Ǒ ǒ Ř ř Š š Ť ť Ǔ ǔ Ž ž"; expectedResult = "AaCcDdEeIiLlNnOoRrSsTtUuZz"; - assertEquals(expectedResult, BibtexKeyPatternUtil.checkLegalKey(accents, true)); + assertEquals(expectedResult, BibtexKeyGenerator.cleanKey(accents, true)); expectedResult = "AaEeIiNnOoUuYy"; accents = "ÃãẼẽĨĩÑñÕõŨũỸỹ"; - assertEquals(expectedResult, BibtexKeyPatternUtil.checkLegalKey(accents, true)); + assertEquals(expectedResult, BibtexKeyGenerator.cleanKey(accents, true)); accents = "Ḍ ḍ Ḥ ḥ Ḷ ḷ Ḹ ḹ Ṃ ṃ Ṇ ṇ Ṛ ṛ Ṝ ṝ Ṣ ṣ Ṭ ṭ"; expectedResult = "DdHhLlLlMmNnRrRrSsTt"; - assertEquals(expectedResult, BibtexKeyPatternUtil.checkLegalKey(accents, true)); + assertEquals(expectedResult, BibtexKeyGenerator.cleanKey(accents, true)); String totest = "À à È è Ì ì Ò ò Ù ù  â Ĉ ĉ Ê ê Ĝ ĝ Ĥ ĥ Î î Ĵ ĵ Ô ô Ŝ ŝ Û û Ŵ ŵ Ŷ ŷ Ä ä Ë ë Ï ï Ö ö Ü ü Ÿ ÿ " + "à ã Ẽ ẽ Ĩ ĩ Ñ ñ Õ õ Ũ ũ Ỹ ỹ Ç ç Ģ ģ Ķ ķ Ļ ļ Ņ ņ Ŗ ŗ Ş ş Ţ ţ" @@ -284,23 +284,23 @@ public void testCheckLegalKey() { String expectedResults = "AaEeIiOoUuAaCcEeGgHhIiJjOoSsUuWwYyAeaeEeIiOeoeUeueYy" + "AaEeIiNnOoUuYyCcGgKkLlNnRrSsTt" + "AaCcDdEeIiLlNnOoRrSsTtUuZz" + "AaEeIiOoUuYy" + "AaEeGgIiOoUu" + "CcEeGgIiZzAaEeIiOoUu" + "DdHhLlLlMmNnRrRrSsTt"; - assertEquals(expectedResults, BibtexKeyPatternUtil.checkLegalKey(totest, true)); + assertEquals(expectedResults, BibtexKeyGenerator.cleanKey(totest, true)); } @Test public void testFirstAuthor() { - assertEquals("Newton", BibtexKeyPatternUtil.firstAuthor(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_5)); - assertEquals("Newton", BibtexKeyPatternUtil.firstAuthor(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1)); + assertEquals("Newton", BibtexKeyGenerator.firstAuthor(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_5)); + assertEquals("Newton", BibtexKeyGenerator.firstAuthor(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1)); // https://sourceforge.net/forum/message.php?msg_id=4498555 - assertEquals("K{\\\"o}ning", BibtexKeyPatternUtil.firstAuthor("K{\\\"o}ning")); + assertEquals("K{\\\"o}ning", BibtexKeyGenerator.firstAuthor("K{\\\"o}ning")); - assertEquals("", BibtexKeyPatternUtil.firstAuthor("")); + assertEquals("", BibtexKeyGenerator.firstAuthor("")); } @Test(expected = NullPointerException.class) public void testFirstAuthorNull() { - BibtexKeyPatternUtil.firstAuthor(null); + BibtexKeyGenerator.firstAuthor(null); } @Test @@ -308,7 +308,7 @@ public void testUniversity() throws ParseException { Optional entry = BibtexParser.singleFromString( "@ARTICLE{kohn, author={{Link{\\\"{o}}ping University}}}", importFormatPreferences); assertEquals("UniLinkoeping", - BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry.get(), "auth", + BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry.get(), "auth", ',', new BibDatabase()), true)); } @@ -324,7 +324,7 @@ public void testcrossrefUniversity() throws Exception { database.insertEntry(entry2); assertEquals("UniLinkoeping", - BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry1, "auth", + BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry1, "auth", ',', database), true)); } @@ -334,7 +334,7 @@ public void testDepartment() throws ParseException { "@ARTICLE{kohn, author={{Link{\\\"{o}}ping University, Department of Electrical Engineering}}}", importFormatPreferences); assertEquals("UniLinkoepingEE", - BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry.get(), "auth", + BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry.get(), "auth", ',', new BibDatabase()), true)); } @@ -350,7 +350,7 @@ public void testcrossrefDepartment() throws Exception { database.insertEntry(entry2); assertEquals("UniLinkoepingEE", - BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry1, "auth", + BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry1, "auth", ',', database), true)); } @@ -360,7 +360,7 @@ public void testSchool() throws ParseException { "@ARTICLE{kohn, author={{Link{\\\"{o}}ping University, School of Computer Engineering}}}", importFormatPreferences); assertEquals("UniLinkoepingCE", - BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry.get(), "auth", + BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry.get(), "auth", ',', new BibDatabase()), true)); } @@ -376,7 +376,7 @@ public void testcrossrefSchool() throws Exception { database.insertEntry(entry2); assertEquals("UniLinkoepingCE", - BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry1, "auth", + BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry1, "auth", ',', database), true)); } @@ -385,7 +385,7 @@ public void testInstituteOfTechnology() throws ParseException { Optional entry = BibtexParser.singleFromString( "@ARTICLE{kohn, author={{Massachusetts Institute of Technology}}}", importFormatPreferences); assertEquals("MIT", - BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry.get(), "auth", + BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry.get(), "auth", ',', new BibDatabase()), true)); } @@ -401,35 +401,35 @@ public void testcrossrefInstituteOfTechnology() throws Exception { database.insertEntry(entry2); assertEquals("MIT", - BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry1, "auth", + BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry1, "auth", ',', database), true)); } @Test public void testAuthIniN() { - assertEquals("NMEB", BibtexKeyPatternUtil.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_5, 4)); - assertEquals("NMEB", BibtexKeyPatternUtil.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4, 4)); - assertEquals("NeME", BibtexKeyPatternUtil.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3, 4)); - assertEquals("NeMa", BibtexKeyPatternUtil.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2, 4)); - assertEquals("Newt", BibtexKeyPatternUtil.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 4)); + assertEquals("NMEB", BibtexKeyGenerator.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_5, 4)); + assertEquals("NMEB", BibtexKeyGenerator.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4, 4)); + assertEquals("NeME", BibtexKeyGenerator.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3, 4)); + assertEquals("NeMa", BibtexKeyGenerator.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2, 4)); + assertEquals("Newt", BibtexKeyGenerator.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 4)); assertEquals("", ""); - assertEquals("N", BibtexKeyPatternUtil.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 1)); - assertEquals("", BibtexKeyPatternUtil.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 0)); - assertEquals("", BibtexKeyPatternUtil.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, -1)); + assertEquals("N", BibtexKeyGenerator.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 1)); + assertEquals("", BibtexKeyGenerator.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 0)); + assertEquals("", BibtexKeyGenerator.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, -1)); - assertEquals("Newton", BibtexKeyPatternUtil.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 6)); - assertEquals("Newton", BibtexKeyPatternUtil.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 7)); + assertEquals("Newton", BibtexKeyGenerator.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 6)); + assertEquals("Newton", BibtexKeyGenerator.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 7)); } @Test(expected = NullPointerException.class) public void testAuthIniNNull() { - BibtexKeyPatternUtil.authIniN(null, 3); + BibtexKeyGenerator.authIniN(null, 3); } @Test public void testAuthIniNEmptyReturnsEmpty() { - assertEquals("", BibtexKeyPatternUtil.authIniN("", 1)); + assertEquals("", BibtexKeyGenerator.authIniN("", 1)); } /** @@ -437,16 +437,16 @@ public void testAuthIniNEmptyReturnsEmpty() { */ @Test public void authAuthEa() { - assertEquals("Newton", BibtexKeyPatternUtil.authAuthEa(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_1)); + assertEquals("Newton", BibtexKeyGenerator.authAuthEa(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_1)); assertEquals("Newton.Maxwell", - BibtexKeyPatternUtil.authAuthEa(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_2)); + BibtexKeyGenerator.authAuthEa(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_2)); assertEquals("Newton.Maxwell.ea", - BibtexKeyPatternUtil.authAuthEa(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_3)); + BibtexKeyGenerator.authAuthEa(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_3)); } @Test public void testAuthEaEmptyReturnsEmpty() { - assertEquals("", BibtexKeyPatternUtil.authAuthEa("")); + assertEquals("", BibtexKeyGenerator.authAuthEa("")); } /** @@ -460,17 +460,17 @@ public void testAuthEtAl() { String delim = "."; String append = ".etal"; assertEquals("Newton.etal", - BibtexKeyPatternUtil.authEtal(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_3, delim, append)); + BibtexKeyGenerator.authEtal(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_3, delim, append)); assertEquals("Newton.Maxwell", - BibtexKeyPatternUtil.authEtal(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_2, delim, append)); + BibtexKeyGenerator.authEtal(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_2, delim, append)); // [authEtAl] delim = ""; append = "EtAl"; assertEquals("NewtonEtAl", - BibtexKeyPatternUtil.authEtal(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_3, delim, append)); + BibtexKeyGenerator.authEtal(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_3, delim, append)); assertEquals("NewtonMaxwell", - BibtexKeyPatternUtil.authEtal(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_2, delim, append)); + BibtexKeyGenerator.authEtal(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_2, delim, append)); } /** @@ -479,15 +479,15 @@ public void testAuthEtAl() { @Test public void testAuthShort() { // tests taken from the comments - assertEquals("NME+", BibtexKeyPatternUtil.authshort(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4)); - assertEquals("NME", BibtexKeyPatternUtil.authshort(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3)); - assertEquals("NM", BibtexKeyPatternUtil.authshort(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2)); - assertEquals("Newton", BibtexKeyPatternUtil.authshort(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1)); + assertEquals("NME+", BibtexKeyGenerator.authshort(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4)); + assertEquals("NME", BibtexKeyGenerator.authshort(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3)); + assertEquals("NM", BibtexKeyGenerator.authshort(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2)); + assertEquals("Newton", BibtexKeyGenerator.authshort(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1)); } @Test public void testAuthShortEmptyReturnsEmpty() { - assertEquals("", BibtexKeyPatternUtil.authshort("")); + assertEquals("", BibtexKeyGenerator.authshort("")); } /** @@ -495,27 +495,27 @@ public void testAuthShortEmptyReturnsEmpty() { */ @Test public void authNM() { - assertEquals("N", BibtexKeyPatternUtil.authNofMth(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 1, 1)); + assertEquals("N", BibtexKeyGenerator.authNofMth(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 1, 1)); assertEquals("Max", - BibtexKeyPatternUtil.authNofMth(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2, 3, 2)); + BibtexKeyGenerator.authNofMth(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2, 3, 2)); assertEquals("New", - BibtexKeyPatternUtil.authNofMth(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3, 3, 1)); + BibtexKeyGenerator.authNofMth(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3, 3, 1)); assertEquals("Bo", - BibtexKeyPatternUtil.authNofMth(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4, 2, 4)); + BibtexKeyGenerator.authNofMth(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4, 2, 4)); assertEquals("Bohr", - BibtexKeyPatternUtil.authNofMth(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_5, 6, 4)); + BibtexKeyGenerator.authNofMth(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_5, 6, 4)); assertEquals("Aal", - BibtexKeyPatternUtil.authNofMth(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_1, 3, 1)); + BibtexKeyGenerator.authNofMth(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_1, 3, 1)); assertEquals("Less", - BibtexKeyPatternUtil.authNofMth(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_2, 4, 2)); + BibtexKeyGenerator.authNofMth(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_2, 4, 2)); - assertEquals("", BibtexKeyPatternUtil.authNofMth("", 2, 4)); + assertEquals("", BibtexKeyGenerator.authNofMth("", 2, 4)); } @Test(expected = NullPointerException.class) public void authNMThrowsNPE() { - BibtexKeyPatternUtil.authNofMth(null, 2, 4); + BibtexKeyGenerator.authNofMth(null, 2, 4); } /** @@ -523,14 +523,14 @@ public void authNMThrowsNPE() { */ @Test public void firstAuthorForenameInitials() { - assertEquals("I", BibtexKeyPatternUtil + assertEquals("I", BibtexKeyGenerator .firstAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1)); - assertEquals("I", BibtexKeyPatternUtil + assertEquals("I", BibtexKeyGenerator .firstAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2)); assertEquals("I", - BibtexKeyPatternUtil.firstAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_1)); + BibtexKeyGenerator.firstAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_1)); assertEquals("I", - BibtexKeyPatternUtil.firstAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_2)); + BibtexKeyGenerator.firstAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_2)); } /** @@ -538,18 +538,18 @@ public void firstAuthorForenameInitials() { */ @Test public void firstAuthorVonAndLast() { - assertEquals("vanderAalst", BibtexKeyPatternUtil + assertEquals("vanderAalst", BibtexKeyGenerator .firstAuthorVonAndLast(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_1)); - assertEquals("vanderAalst", BibtexKeyPatternUtil + assertEquals("vanderAalst", BibtexKeyGenerator .firstAuthorVonAndLast(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_2)); } @Test public void firstAuthorVonAndLastNoVonInName() { assertEquals("Newton", - BibtexKeyPatternUtil.firstAuthorVonAndLast(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_1)); + BibtexKeyGenerator.firstAuthorVonAndLast(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_1)); assertEquals("Newton", - BibtexKeyPatternUtil.firstAuthorVonAndLast(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_2)); + BibtexKeyGenerator.firstAuthorVonAndLast(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_2)); } /** @@ -557,11 +557,11 @@ public void firstAuthorVonAndLastNoVonInName() { */ @Test public void testAllAuthors() { - assertEquals("Newton", BibtexKeyPatternUtil.allAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1)); + assertEquals("Newton", BibtexKeyGenerator.allAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1)); assertEquals("NewtonMaxwell", - BibtexKeyPatternUtil.allAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2)); + BibtexKeyGenerator.allAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2)); assertEquals("NewtonMaxwellEinstein", - BibtexKeyPatternUtil.allAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3)); + BibtexKeyGenerator.allAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3)); } /** @@ -569,16 +569,16 @@ public void testAllAuthors() { */ @Test public void authorsAlpha() { - assertEquals("New", BibtexKeyPatternUtil.authorsAlpha(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1)); - assertEquals("NM", BibtexKeyPatternUtil.authorsAlpha(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2)); - assertEquals("NME", BibtexKeyPatternUtil.authorsAlpha(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3)); - assertEquals("NMEB", BibtexKeyPatternUtil.authorsAlpha(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4)); - assertEquals("NME+", BibtexKeyPatternUtil.authorsAlpha(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_5)); + assertEquals("New", BibtexKeyGenerator.authorsAlpha(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1)); + assertEquals("NM", BibtexKeyGenerator.authorsAlpha(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2)); + assertEquals("NME", BibtexKeyGenerator.authorsAlpha(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3)); + assertEquals("NMEB", BibtexKeyGenerator.authorsAlpha(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4)); + assertEquals("NME+", BibtexKeyGenerator.authorsAlpha(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_5)); assertEquals("vdAal", - BibtexKeyPatternUtil.authorsAlpha(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_1)); + BibtexKeyGenerator.authorsAlpha(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_1)); assertEquals("vdAvL", - BibtexKeyPatternUtil.authorsAlpha(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_2)); + BibtexKeyGenerator.authorsAlpha(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_2)); } /** @@ -586,17 +586,17 @@ public void authorsAlpha() { */ @Test public void lastAuthor() { - assertEquals("Newton", BibtexKeyPatternUtil.lastAuthor(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1)); - assertEquals("Maxwell", BibtexKeyPatternUtil.lastAuthor(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2)); + assertEquals("Newton", BibtexKeyGenerator.lastAuthor(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1)); + assertEquals("Maxwell", BibtexKeyGenerator.lastAuthor(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2)); assertEquals("Einstein", - BibtexKeyPatternUtil.lastAuthor(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3)); - assertEquals("Bohr", BibtexKeyPatternUtil.lastAuthor(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4)); - assertEquals("Unknown", BibtexKeyPatternUtil.lastAuthor(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_5)); + BibtexKeyGenerator.lastAuthor(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3)); + assertEquals("Bohr", BibtexKeyGenerator.lastAuthor(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4)); + assertEquals("Unknown", BibtexKeyGenerator.lastAuthor(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_5)); assertEquals("Aalst", - BibtexKeyPatternUtil.lastAuthor(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_1)); + BibtexKeyGenerator.lastAuthor(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_1)); assertEquals("Lessen", - BibtexKeyPatternUtil.lastAuthor(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_2)); + BibtexKeyGenerator.lastAuthor(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_2)); } /** @@ -605,19 +605,19 @@ public void lastAuthor() { @Test public void lastAuthorForenameInitials() { assertEquals("I", - BibtexKeyPatternUtil.lastAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1)); + BibtexKeyGenerator.lastAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1)); assertEquals("J", - BibtexKeyPatternUtil.lastAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2)); + BibtexKeyGenerator.lastAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2)); assertEquals("A", - BibtexKeyPatternUtil.lastAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3)); + BibtexKeyGenerator.lastAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3)); assertEquals("N", - BibtexKeyPatternUtil.lastAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4)); + BibtexKeyGenerator.lastAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4)); assertEquals("H", - BibtexKeyPatternUtil.lastAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_5)); + BibtexKeyGenerator.lastAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_5)); - assertEquals("W", BibtexKeyPatternUtil + assertEquals("W", BibtexKeyGenerator .lastAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_1)); - assertEquals("T", BibtexKeyPatternUtil + assertEquals("T", BibtexKeyGenerator .lastAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_2)); } @@ -627,20 +627,20 @@ public void lastAuthorForenameInitials() { @Test public void oneAuthorPlusIni() { assertEquals("Newto", - BibtexKeyPatternUtil.oneAuthorPlusIni(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1)); + BibtexKeyGenerator.oneAuthorPlusIni(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1)); assertEquals("NewtoM", - BibtexKeyPatternUtil.oneAuthorPlusIni(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2)); + BibtexKeyGenerator.oneAuthorPlusIni(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2)); assertEquals("NewtoME", - BibtexKeyPatternUtil.oneAuthorPlusIni(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3)); + BibtexKeyGenerator.oneAuthorPlusIni(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3)); assertEquals("NewtoMEB", - BibtexKeyPatternUtil.oneAuthorPlusIni(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4)); + BibtexKeyGenerator.oneAuthorPlusIni(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4)); assertEquals("NewtoMEBU", - BibtexKeyPatternUtil.oneAuthorPlusIni(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_5)); + BibtexKeyGenerator.oneAuthorPlusIni(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_5)); assertEquals("Aalst", - BibtexKeyPatternUtil.oneAuthorPlusIni(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_1)); + BibtexKeyGenerator.oneAuthorPlusIni(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_1)); assertEquals("AalstL", - BibtexKeyPatternUtil.oneAuthorPlusIni(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_2)); + BibtexKeyGenerator.oneAuthorPlusIni(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_2)); } /** @@ -648,18 +648,18 @@ public void oneAuthorPlusIni() { */ @Test public void testNAuthors1() { - assertEquals("Newton", BibtexKeyPatternUtil.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 1)); + assertEquals("Newton", BibtexKeyGenerator.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 1)); assertEquals("NewtonEtAl", - BibtexKeyPatternUtil.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2, 1)); + BibtexKeyGenerator.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2, 1)); assertEquals("NewtonEtAl", - BibtexKeyPatternUtil.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3, 1)); + BibtexKeyGenerator.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3, 1)); assertEquals("NewtonEtAl", - BibtexKeyPatternUtil.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4, 1)); + BibtexKeyGenerator.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4, 1)); } @Test public void testNAuthors1EmptyReturnEmpty() { - assertEquals("", BibtexKeyPatternUtil.nAuthors("", 1)); + assertEquals("", BibtexKeyGenerator.nAuthors("", 1)); } /** @@ -667,69 +667,69 @@ public void testNAuthors1EmptyReturnEmpty() { */ @Test public void testNAuthors3() { - assertEquals("Newton", BibtexKeyPatternUtil.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 3)); + assertEquals("Newton", BibtexKeyGenerator.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 3)); assertEquals("NewtonMaxwell", - BibtexKeyPatternUtil.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2, 3)); + BibtexKeyGenerator.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2, 3)); assertEquals("NewtonMaxwellEinstein", - BibtexKeyPatternUtil.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3, 3)); + BibtexKeyGenerator.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3, 3)); assertEquals("NewtonMaxwellEinsteinEtAl", - BibtexKeyPatternUtil.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4, 3)); + BibtexKeyGenerator.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4, 3)); } @Test public void testFirstPage() { - assertEquals("7", BibtexKeyPatternUtil.firstPage("7--27")); - assertEquals("27", BibtexKeyPatternUtil.firstPage("--27")); - assertEquals("", BibtexKeyPatternUtil.firstPage("")); - assertEquals("42", BibtexKeyPatternUtil.firstPage("42--111")); - assertEquals("7", BibtexKeyPatternUtil.firstPage("7,41,73--97")); - assertEquals("7", BibtexKeyPatternUtil.firstPage("41,7,73--97")); - assertEquals("43", BibtexKeyPatternUtil.firstPage("43+")); + assertEquals("7", BibtexKeyGenerator.firstPage("7--27")); + assertEquals("27", BibtexKeyGenerator.firstPage("--27")); + assertEquals("", BibtexKeyGenerator.firstPage("")); + assertEquals("42", BibtexKeyGenerator.firstPage("42--111")); + assertEquals("7", BibtexKeyGenerator.firstPage("7,41,73--97")); + assertEquals("7", BibtexKeyGenerator.firstPage("41,7,73--97")); + assertEquals("43", BibtexKeyGenerator.firstPage("43+")); } @Test(expected = NullPointerException.class) public void testFirstPageNull() { - BibtexKeyPatternUtil.firstPage(null); + BibtexKeyGenerator.firstPage(null); } @Test public void testPagePrefix() { - assertEquals("L", BibtexKeyPatternUtil.pagePrefix("L7--27")); - assertEquals("L--", BibtexKeyPatternUtil.pagePrefix("L--27")); - assertEquals("L", BibtexKeyPatternUtil.pagePrefix("L")); - assertEquals("L", BibtexKeyPatternUtil.pagePrefix("L42--111")); - assertEquals("L", BibtexKeyPatternUtil.pagePrefix("L7,L41,L73--97")); - assertEquals("L", BibtexKeyPatternUtil.pagePrefix("L41,L7,L73--97")); - assertEquals("L", BibtexKeyPatternUtil.pagePrefix("L43+")); - assertEquals("", BibtexKeyPatternUtil.pagePrefix("7--27")); - assertEquals("--", BibtexKeyPatternUtil.pagePrefix("--27")); - assertEquals("", BibtexKeyPatternUtil.pagePrefix("")); - assertEquals("", BibtexKeyPatternUtil.pagePrefix("42--111")); - assertEquals("", BibtexKeyPatternUtil.pagePrefix("7,41,73--97")); - assertEquals("", BibtexKeyPatternUtil.pagePrefix("41,7,73--97")); - assertEquals("", BibtexKeyPatternUtil.pagePrefix("43+")); + assertEquals("L", BibtexKeyGenerator.pagePrefix("L7--27")); + assertEquals("L--", BibtexKeyGenerator.pagePrefix("L--27")); + assertEquals("L", BibtexKeyGenerator.pagePrefix("L")); + assertEquals("L", BibtexKeyGenerator.pagePrefix("L42--111")); + assertEquals("L", BibtexKeyGenerator.pagePrefix("L7,L41,L73--97")); + assertEquals("L", BibtexKeyGenerator.pagePrefix("L41,L7,L73--97")); + assertEquals("L", BibtexKeyGenerator.pagePrefix("L43+")); + assertEquals("", BibtexKeyGenerator.pagePrefix("7--27")); + assertEquals("--", BibtexKeyGenerator.pagePrefix("--27")); + assertEquals("", BibtexKeyGenerator.pagePrefix("")); + assertEquals("", BibtexKeyGenerator.pagePrefix("42--111")); + assertEquals("", BibtexKeyGenerator.pagePrefix("7,41,73--97")); + assertEquals("", BibtexKeyGenerator.pagePrefix("41,7,73--97")); + assertEquals("", BibtexKeyGenerator.pagePrefix("43+")); } @Test(expected = NullPointerException.class) public void testPagePrefixNull() { - BibtexKeyPatternUtil.pagePrefix(null); + BibtexKeyGenerator.pagePrefix(null); } @Test public void testLastPage() { - assertEquals("27", BibtexKeyPatternUtil.lastPage("7--27")); - assertEquals("27", BibtexKeyPatternUtil.lastPage("--27")); - assertEquals("", BibtexKeyPatternUtil.lastPage("")); - assertEquals("111", BibtexKeyPatternUtil.lastPage("42--111")); - assertEquals("97", BibtexKeyPatternUtil.lastPage("7,41,73--97")); - assertEquals("97", BibtexKeyPatternUtil.lastPage("7,41,97--73")); - assertEquals("43", BibtexKeyPatternUtil.lastPage("43+")); + assertEquals("27", BibtexKeyGenerator.lastPage("7--27")); + assertEquals("27", BibtexKeyGenerator.lastPage("--27")); + assertEquals("", BibtexKeyGenerator.lastPage("")); + assertEquals("111", BibtexKeyGenerator.lastPage("42--111")); + assertEquals("97", BibtexKeyGenerator.lastPage("7,41,73--97")); + assertEquals("97", BibtexKeyGenerator.lastPage("7,41,97--73")); + assertEquals("43", BibtexKeyGenerator.lastPage("43+")); } @Test(expected = NullPointerException.class) public void testLastPageNull() { - BibtexKeyPatternUtil.lastPage(null); + BibtexKeyGenerator.lastPage(null); } /** @@ -740,28 +740,28 @@ public void veryShortTitle() { // veryShortTitle is getTitleWords with "1" as count int count = 1; assertEquals("application", - BibtexKeyPatternUtil.getTitleWords(count, - BibtexKeyPatternUtil.removeSmallWords(TITLE_STRING_ALL_LOWER_FOUR_SMALL_WORDS_ONE_EN_DASH))); - assertEquals("BPEL", BibtexKeyPatternUtil.getTitleWords(count, - BibtexKeyPatternUtil.removeSmallWords( + BibtexKeyGenerator.getTitleWords(count, + BibtexKeyGenerator.removeSmallWords(TITLE_STRING_ALL_LOWER_FOUR_SMALL_WORDS_ONE_EN_DASH))); + assertEquals("BPEL", BibtexKeyGenerator.getTitleWords(count, + BibtexKeyGenerator.removeSmallWords( TITLE_STRING_ALL_LOWER_FIRST_WORD_IN_BRACKETS_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON))); - assertEquals("Process", BibtexKeyPatternUtil.getTitleWords(count, - BibtexKeyPatternUtil.removeSmallWords(TITLE_STRING_CASED))); + assertEquals("Process", BibtexKeyGenerator.getTitleWords(count, + BibtexKeyGenerator.removeSmallWords(TITLE_STRING_CASED))); assertEquals("BPMN", - BibtexKeyPatternUtil.getTitleWords(count, - BibtexKeyPatternUtil.removeSmallWords(TITLE_STRING_CASED_ONE_UPPER_WORD_ONE_SMALL_WORD))); - assertEquals("Difference", BibtexKeyPatternUtil.getTitleWords(count, - BibtexKeyPatternUtil.removeSmallWords(TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AT_THE_BEGINNING))); + BibtexKeyGenerator.getTitleWords(count, + BibtexKeyGenerator.removeSmallWords(TITLE_STRING_CASED_ONE_UPPER_WORD_ONE_SMALL_WORD))); + assertEquals("Difference", BibtexKeyGenerator.getTitleWords(count, + BibtexKeyGenerator.removeSmallWords(TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AT_THE_BEGINNING))); assertEquals("Cloud", - BibtexKeyPatternUtil.getTitleWords(count, - BibtexKeyPatternUtil + BibtexKeyGenerator.getTitleWords(count, + BibtexKeyGenerator .removeSmallWords(TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON))); assertEquals("Towards", - BibtexKeyPatternUtil.getTitleWords(count, - BibtexKeyPatternUtil.removeSmallWords(TITLE_STRING_CASED_TWO_SMALL_WORDS_ONE_CONNECTED_WORD))); + BibtexKeyGenerator.getTitleWords(count, + BibtexKeyGenerator.removeSmallWords(TITLE_STRING_CASED_TWO_SMALL_WORDS_ONE_CONNECTED_WORD))); assertEquals("Measurement", - BibtexKeyPatternUtil.getTitleWords(count, - BibtexKeyPatternUtil + BibtexKeyGenerator.getTitleWords(count, + BibtexKeyGenerator .removeSmallWords(TITLE_STRING_CASED_FOUR_SMALL_WORDS_TWO_CONNECTED_WORDS))); } @@ -773,20 +773,20 @@ public void shortTitle() { // shortTitle is getTitleWords with "3" as count int count = 3; assertEquals("application migration effort", - BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_ALL_LOWER_FOUR_SMALL_WORDS_ONE_EN_DASH)); - assertEquals("BPEL conformance in", BibtexKeyPatternUtil.getTitleWords(count, + BibtexKeyGenerator.getTitleWords(count, TITLE_STRING_ALL_LOWER_FOUR_SMALL_WORDS_ONE_EN_DASH)); + assertEquals("BPEL conformance in", BibtexKeyGenerator.getTitleWords(count, TITLE_STRING_ALL_LOWER_FIRST_WORD_IN_BRACKETS_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON)); - assertEquals("Process Viewing Patterns", BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_CASED)); + assertEquals("Process Viewing Patterns", BibtexKeyGenerator.getTitleWords(count, TITLE_STRING_CASED)); assertEquals("BPMN Conformance in", - BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_CASED_ONE_UPPER_WORD_ONE_SMALL_WORD)); - assertEquals("The Difference Between", BibtexKeyPatternUtil.getTitleWords(count, + BibtexKeyGenerator.getTitleWords(count, TITLE_STRING_CASED_ONE_UPPER_WORD_ONE_SMALL_WORD)); + assertEquals("The Difference Between", BibtexKeyGenerator.getTitleWords(count, TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AT_THE_BEGINNING)); assertEquals("Cloud Computing: The", - BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON)); + BibtexKeyGenerator.getTitleWords(count, TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON)); assertEquals("Towards Choreography based", - BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_CASED_TWO_SMALL_WORDS_ONE_CONNECTED_WORD)); + BibtexKeyGenerator.getTitleWords(count, TITLE_STRING_CASED_TWO_SMALL_WORDS_ONE_CONNECTED_WORD)); assertEquals("On the Measurement", - BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_CASED_FOUR_SMALL_WORDS_TWO_CONNECTED_WORDS)); + BibtexKeyGenerator.getTitleWords(count, TITLE_STRING_CASED_FOUR_SMALL_WORDS_TWO_CONNECTED_WORDS)); } /** @@ -796,22 +796,22 @@ public void shortTitle() { public void camel() { // camel capitalises and concatenates all the words of the title assertEquals("ApplicationMigrationEffortInTheCloudTheCaseOfCloudPlatforms", - BibtexKeyPatternUtil.getCamelizedTitle(TITLE_STRING_ALL_LOWER_FOUR_SMALL_WORDS_ONE_EN_DASH)); + BibtexKeyGenerator.getCamelizedTitle(TITLE_STRING_ALL_LOWER_FOUR_SMALL_WORDS_ONE_EN_DASH)); assertEquals("BPELConformanceInOpenSourceEnginesTheCaseOfStaticAnalysis", - BibtexKeyPatternUtil.getCamelizedTitle( + BibtexKeyGenerator.getCamelizedTitle( TITLE_STRING_ALL_LOWER_FIRST_WORD_IN_BRACKETS_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON)); - assertEquals("ProcessViewingPatterns", BibtexKeyPatternUtil.getCamelizedTitle(TITLE_STRING_CASED)); + assertEquals("ProcessViewingPatterns", BibtexKeyGenerator.getCamelizedTitle(TITLE_STRING_CASED)); assertEquals("BPMNConformanceInOpenSourceEngines", - BibtexKeyPatternUtil.getCamelizedTitle(TITLE_STRING_CASED_ONE_UPPER_WORD_ONE_SMALL_WORD)); + BibtexKeyGenerator.getCamelizedTitle(TITLE_STRING_CASED_ONE_UPPER_WORD_ONE_SMALL_WORD)); assertEquals("TheDifferenceBetweenGraphBasedAndBlockStructuredBusinessProcessModellingLanguages", - BibtexKeyPatternUtil.getCamelizedTitle( + BibtexKeyGenerator.getCamelizedTitle( TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AT_THE_BEGINNING)); assertEquals("CloudComputingTheNextRevolutionInIT", - BibtexKeyPatternUtil.getCamelizedTitle(TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON)); + BibtexKeyGenerator.getCamelizedTitle(TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON)); assertEquals("TowardsChoreographyBasedProcessDistributionInTheCloud", - BibtexKeyPatternUtil.getCamelizedTitle(TITLE_STRING_CASED_TWO_SMALL_WORDS_ONE_CONNECTED_WORD)); + BibtexKeyGenerator.getCamelizedTitle(TITLE_STRING_CASED_TWO_SMALL_WORDS_ONE_CONNECTED_WORD)); assertEquals("OnTheMeasurementOfDesignTimeAdaptabilityForProcessBasedSystems", - BibtexKeyPatternUtil.getCamelizedTitle(TITLE_STRING_CASED_FOUR_SMALL_WORDS_TWO_CONNECTED_WORDS)); + BibtexKeyGenerator.getCamelizedTitle(TITLE_STRING_CASED_FOUR_SMALL_WORDS_TWO_CONNECTED_WORDS)); } /** @@ -822,27 +822,27 @@ public void title() { // title capitalises the significant words of the title // for the title case the concatenation happens at formatting, which is tested in MakeLabelWithDatabaseTest.java assertEquals("Application Migration Effort in the Cloud the Case of Cloud Platforms", - BibtexKeyPatternUtil + BibtexKeyGenerator .camelizeSignificantWordsInTitle(TITLE_STRING_ALL_LOWER_FOUR_SMALL_WORDS_ONE_EN_DASH)); assertEquals("BPEL Conformance in Open Source Engines: the Case of Static Analysis", - BibtexKeyPatternUtil.camelizeSignificantWordsInTitle( + BibtexKeyGenerator.camelizeSignificantWordsInTitle( TITLE_STRING_ALL_LOWER_FIRST_WORD_IN_BRACKETS_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON)); assertEquals("Process Viewing Patterns", - BibtexKeyPatternUtil.camelizeSignificantWordsInTitle(TITLE_STRING_CASED)); + BibtexKeyGenerator.camelizeSignificantWordsInTitle(TITLE_STRING_CASED)); assertEquals("BPMN Conformance in Open Source Engines", - BibtexKeyPatternUtil + BibtexKeyGenerator .camelizeSignificantWordsInTitle(TITLE_STRING_CASED_ONE_UPPER_WORD_ONE_SMALL_WORD)); assertEquals("The Difference between Graph Based and Block Structured Business Process Modelling Languages", - BibtexKeyPatternUtil.camelizeSignificantWordsInTitle( + BibtexKeyGenerator.camelizeSignificantWordsInTitle( TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AT_THE_BEGINNING)); assertEquals("Cloud Computing: the Next Revolution in IT", - BibtexKeyPatternUtil.camelizeSignificantWordsInTitle( + BibtexKeyGenerator.camelizeSignificantWordsInTitle( TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON)); assertEquals("Towards Choreography Based Process Distribution in the Cloud", - BibtexKeyPatternUtil + BibtexKeyGenerator .camelizeSignificantWordsInTitle(TITLE_STRING_CASED_TWO_SMALL_WORDS_ONE_CONNECTED_WORD)); assertEquals("On the Measurement of Design Time Adaptability for Process Based Systems", - BibtexKeyPatternUtil.camelizeSignificantWordsInTitle( + BibtexKeyGenerator.camelizeSignificantWordsInTitle( TITLE_STRING_CASED_FOUR_SMALL_WORDS_TWO_CONNECTED_WORDS)); } @@ -851,15 +851,15 @@ public void keywordNKeywordsSeparatedBySpace() { BibEntry entry = new BibEntry(); entry.setField("keywords", "w1, w2a w2b, w3"); - String result = BibtexKeyPatternUtil.makeLabel(entry, "keyword1", ',', new BibDatabase()); + String result = BibtexKeyGenerator.generateKey(entry, "keyword1", ',', new BibDatabase()); assertEquals("w1", result); // check keywords with space - result = BibtexKeyPatternUtil.makeLabel(entry, "keyword2", ',', new BibDatabase()); + result = BibtexKeyGenerator.generateKey(entry, "keyword2", ',', new BibDatabase()); assertEquals("w2a w2b", result); // check out of range - result = BibtexKeyPatternUtil.makeLabel(entry, "keyword4", ',', new BibDatabase()); + result = BibtexKeyGenerator.generateKey(entry, "keyword4", ',', new BibDatabase()); assertEquals("", result); } @@ -874,7 +874,7 @@ public void crossrefkeywordNKeywordsSeparatedBySpace() { database.insertEntry(entry1); entry2.setField("keywords", "w1, w2a w2b, w3"); - String result = BibtexKeyPatternUtil.makeLabel(entry1, "keyword1", ',', database); + String result = BibtexKeyGenerator.generateKey(entry1, "keyword1", ',', database); assertEquals("w1", result); } @@ -885,15 +885,15 @@ public void keywordsNKeywordsSeparatedBySpace() { entry.setField("keywords", "w1, w2a w2b, w3"); // all keywords - String result = BibtexKeyPatternUtil.makeLabel(entry, "keywords", ',', new BibDatabase()); + String result = BibtexKeyGenerator.generateKey(entry, "keywords", ',', new BibDatabase()); assertEquals("w1w2aw2bw3", result); // check keywords with space - result = BibtexKeyPatternUtil.makeLabel(entry, "keywords2", ',', new BibDatabase()); + result = BibtexKeyGenerator.generateKey(entry, "keywords2", ',', new BibDatabase()); assertEquals("w1w2aw2b", result); // check out of range - result = BibtexKeyPatternUtil.makeLabel(entry, "keywords55", ',', new BibDatabase()); + result = BibtexKeyGenerator.generateKey(entry, "keywords55", ',', new BibDatabase()); assertEquals("w1w2aw2bw3", result); } @@ -908,37 +908,37 @@ public void crossrefkeywordsNKeywordsSeparatedBySpace() { database.insertEntry(entry1); entry2.setField("keywords", "w1, w2a w2b, w3"); - String result = BibtexKeyPatternUtil.makeLabel(entry1, "keywords", ',', database); + String result = BibtexKeyGenerator.generateKey(entry1, "keywords", ',', database); assertEquals("w1w2aw2bw3", result); } @Test public void testCheckLegalKeyEnforceLegal() { - assertEquals("AAAA", BibtexKeyPatternUtil.checkLegalKey("AA AA", true)); - assertEquals("SPECIALCHARS", BibtexKeyPatternUtil.checkLegalKey("SPECIAL CHARS#{\\\"}~,^", true)); - assertEquals("", BibtexKeyPatternUtil.checkLegalKey("\n\t\r", true)); + assertEquals("AAAA", BibtexKeyGenerator.cleanKey("AA AA", true)); + assertEquals("SPECIALCHARS", BibtexKeyGenerator.cleanKey("SPECIAL CHARS#{\\\"}~,^", true)); + assertEquals("", BibtexKeyGenerator.cleanKey("\n\t\r", true)); } @Test public void testCheckLegalKeyDoNotEnforceLegal() { - assertEquals("AAAA", BibtexKeyPatternUtil.checkLegalKey("AA AA", false)); - assertEquals("SPECIALCHARS#~^", BibtexKeyPatternUtil.checkLegalKey("SPECIAL CHARS#{\\\"}~,^", false)); - assertEquals("", BibtexKeyPatternUtil.checkLegalKey("\n\t\r", false)); + assertEquals("AAAA", BibtexKeyGenerator.cleanKey("AA AA", false)); + assertEquals("SPECIALCHARS#~^", BibtexKeyGenerator.cleanKey("SPECIAL CHARS#{\\\"}~,^", false)); + assertEquals("", BibtexKeyGenerator.cleanKey("\n\t\r", false)); } @Test public void testCheckLegalNullInNullOut() { - assertNull(BibtexKeyPatternUtil.checkLegalKey(null, true)); - assertNull(BibtexKeyPatternUtil.checkLegalKey(null, false)); + assertNull(BibtexKeyGenerator.cleanKey(null, true)); + assertNull(BibtexKeyGenerator.cleanKey(null, false)); } @Test public void testApplyModifiers() { BibEntry entry = new BibEntry(); entry.setField("title", "Green Scheduling of Whatever"); - assertEquals("GSo", BibtexKeyPatternUtil.makeLabel(entry, "shorttitleINI", ',', new BibDatabase())); - assertEquals("Green Scheduling of", BibtexKeyPatternUtil.makeLabel(entry, "shorttitle", + assertEquals("GSo", BibtexKeyGenerator.generateKey(entry, "shorttitleINI", ',', new BibDatabase())); + assertEquals("Green Scheduling of", BibtexKeyGenerator.generateKey(entry, "shorttitle", ',', new BibDatabase())); } @@ -953,7 +953,7 @@ public void testcrossrefShorttitle() { database.insertEntry(entry1); entry2.setField("title", "Green Scheduling of Whatever"); - assertEquals("Green Scheduling of", BibtexKeyPatternUtil.makeLabel(entry1, "shorttitle", + assertEquals("Green Scheduling of", BibtexKeyGenerator.generateKey(entry1, "shorttitle", ',', database)); } @@ -968,7 +968,7 @@ public void testcrossrefShorttitleInitials() { database.insertEntry(entry1); entry2.setField("title", "Green Scheduling of Whatever"); - assertEquals("GSo", BibtexKeyPatternUtil.makeLabel(entry1, "shorttitleINI", ',', database)); + assertEquals("GSo", BibtexKeyGenerator.generateKey(entry1, "shorttitleINI", ',', database)); } } diff --git a/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithDatabaseTest.java b/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithDatabaseTest.java index 8098382567f..37a9a5105c6 100644 --- a/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithDatabaseTest.java +++ b/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithDatabaseTest.java @@ -36,24 +36,25 @@ public void setUp() { @Test public void generateDefaultKey() { - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("Doe2016"), entry.getCiteKeyOptional()); } @Test public void generateDefaultKeyAlreadyExistsDuplicatesStartAtA() { - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + BibtexKeyGenerator keyGenerator = new BibtexKeyGenerator(bibtexKeyPattern, database, preferences); + keyGenerator.generateAndSetKey(entry); BibEntry entry2 = new BibEntry(); entry2.setField("author", "John Doe"); entry2.setField("year", "2016"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry2, preferences); + keyGenerator.generateAndSetKey(entry2); assertEquals(Optional.of("Doe2016a"), entry2.getCiteKeyOptional()); } @Test public void generateDefaultKeyAlwaysLetter() { preferences = new BibtexKeyPatternPreferences("", "", true, true, true, pattern, ','); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("Doe2016a"), entry.getCiteKeyOptional()); } @@ -61,18 +62,19 @@ public void generateDefaultKeyAlwaysLetter() { public void generateDefaultKeyAlwaysLetterAlreadyExistsDuplicatesStartAtB() { preferences = new BibtexKeyPatternPreferences("", "", true, true, true, pattern, ','); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + BibtexKeyGenerator keyGenerator = new BibtexKeyGenerator(bibtexKeyPattern, database, preferences); + keyGenerator.generateAndSetKey(entry); BibEntry entry2 = new BibEntry(); entry2.setField("author", "John Doe"); entry2.setField("year", "2016"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry2, preferences); + keyGenerator.generateAndSetKey(entry2); assertEquals(Optional.of("Doe2016b"), entry2.getCiteKeyOptional()); } @Test public void generateDefaultKeyStartDuplicatesAtB() { preferences = new BibtexKeyPatternPreferences("", "", false, false, true, pattern, ','); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("Doe2016"), entry.getCiteKeyOptional()); } @@ -80,17 +82,19 @@ public void generateDefaultKeyStartDuplicatesAtB() { public void generateDefaultKeyAlreadyExistsDuplicatesStartAtB() { preferences = new BibtexKeyPatternPreferences("", "", false, false, true, pattern, ','); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + BibtexKeyGenerator keyGenerator = new BibtexKeyGenerator(bibtexKeyPattern, database, preferences); + keyGenerator.generateAndSetKey(entry); BibEntry entry2 = new BibEntry(); entry2.setField("author", "John Doe"); entry2.setField("year", "2016"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry2, preferences); + keyGenerator.generateAndSetKey(entry2); assertEquals(Optional.of("Doe2016b"), entry2.getCiteKeyOptional()); } @Test public void generateDefaultKeyAlreadyExistsManyDuplicates() { - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + BibtexKeyGenerator keyGenerator = new BibtexKeyGenerator(bibtexKeyPattern, database, preferences); + keyGenerator.generateAndSetKey(entry); BibEntry entry2 = new BibEntry(); entry2.setField("author", "John Doe"); entry2.setField("year", "2016"); @@ -101,94 +105,95 @@ public void generateDefaultKeyAlreadyExistsManyDuplicates() { entry3.setField("year", "2016"); entry3.setCiteKey(entry.getCiteKeyOptional().get()); database.insertEntry(entry3); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry3, preferences); + keyGenerator.generateAndSetKey(entry3); assertEquals(Optional.of("Doe2016a"), entry3.getCiteKeyOptional()); } @Test public void generateDefaultKeyFirstTwoAlreadyExists() { - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + BibtexKeyGenerator keyGenerator = new BibtexKeyGenerator(bibtexKeyPattern, database, preferences); + keyGenerator.generateAndSetKey(entry); BibEntry entry2 = new BibEntry(); entry2.setField("author", "John Doe"); entry2.setField("year", "2016"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry2, preferences); + keyGenerator.generateAndSetKey(entry2); database.insertEntry(entry2); BibEntry entry3 = new BibEntry(); entry3.setField("author", "John Doe"); entry3.setField("year", "2016"); entry3.setCiteKey(entry.getCiteKeyOptional().get()); database.insertEntry(entry3); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry3, preferences); + keyGenerator.generateAndSetKey(entry3); assertEquals(Optional.of("Doe2016b"), entry3.getCiteKeyOptional()); } @Test public void generateKeyAuthLowerModified() { bibtexKeyPattern.setDefaultValue("[auth:lower][year]"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("doe2016"), entry.getCiteKeyOptional()); } @Test public void generateKeyAuthUpperModified() { bibtexKeyPattern.setDefaultValue("[auth:upper][year]"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("DOE2016"), entry.getCiteKeyOptional()); } @Test public void generateKeyAuthTitleCaseModified() { bibtexKeyPattern.setDefaultValue("[auth:title_case][year]"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("Doe2016"), entry.getCiteKeyOptional()); } @Test public void generateKeyAuthSentenceCaseModified() { bibtexKeyPattern.setDefaultValue("[auth:sentence_case][year]"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("Doe2016"), entry.getCiteKeyOptional()); } @Test public void generateKeyAuthCapitalizeModified() { bibtexKeyPattern.setDefaultValue("[auth:capitalize][year]"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("Doe2016"), entry.getCiteKeyOptional()); } @Test public void generateDefaultKeyFixedValue() { bibtexKeyPattern.setDefaultValue("[auth]Test[year]"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("DoeTest2016"), entry.getCiteKeyOptional()); } @Test public void generateKeyShortYear() { bibtexKeyPattern.setDefaultValue("[shortyear]"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("16"), entry.getCiteKeyOptional()); } @Test public void generateKeyAuthN() { bibtexKeyPattern.setDefaultValue("[auth2]"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("Do"), entry.getCiteKeyOptional()); } @Test public void generateKeyAuthNShortName() { bibtexKeyPattern.setDefaultValue("[auth10]"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("Doe"), entry.getCiteKeyOptional()); } @Test public void generateKeyEmptyField() { entry = new BibEntry(); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.empty(), entry.getCiteKeyOptional()); } @@ -196,7 +201,7 @@ public void generateKeyEmptyField() { public void generateKeyEmptyFieldDefaultText() { bibtexKeyPattern.setDefaultValue("[author:(No Author Provided)]"); entry.clearField("author"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("NoAuthorProvided"), entry.getCiteKeyOptional()); } @@ -204,28 +209,28 @@ public void generateKeyEmptyFieldDefaultText() { public void generateKeyEmptyFieldColonInDefaultText() { bibtexKeyPattern.setDefaultValue("[author:(Problem:No Author Provided)]"); entry.clearField("author"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("Problem:NoAuthorProvided"), entry.getCiteKeyOptional()); } @Test public void generateKeyTitle() { bibtexKeyPattern.setDefaultValue("[title]"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("AnAwesomePaperonJabRef"), entry.getCiteKeyOptional()); } @Test public void generateKeyTitleAbbr() { bibtexKeyPattern.setDefaultValue("[title:abbr]"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("AAPoJ"), entry.getCiteKeyOptional()); } @Test public void generateKeyShorttitle() { bibtexKeyPattern.setDefaultValue("[shorttitle]"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("Anawesomepaper"), entry.getCiteKeyOptional()); } @@ -233,7 +238,7 @@ public void generateKeyShorttitle() { public void generateKeyShorttitleLowerModified() { bibtexKeyPattern.setDefaultValue("[shorttitle:lower]"); entry.setField("title", "An aweSOme Paper on JabRef"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("anawesomepaper"), entry.getCiteKeyOptional()); } @@ -241,7 +246,7 @@ public void generateKeyShorttitleLowerModified() { public void generateKeyShorttitleUpperModified() { bibtexKeyPattern.setDefaultValue("[shorttitle:upper]"); entry.setField("title", "An aweSOme Paper on JabRef"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("ANAWESOMEPAPER"), entry.getCiteKeyOptional()); } @@ -249,7 +254,7 @@ public void generateKeyShorttitleUpperModified() { public void generateKeyShorttitleTitleCaseModified() { bibtexKeyPattern.setDefaultValue("[shorttitle:title_case]"); entry.setField("title", "An aweSOme Paper on JabRef"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("AnAwesomePaper"), entry.getCiteKeyOptional()); } @@ -257,7 +262,7 @@ public void generateKeyShorttitleTitleCaseModified() { public void generateKeyShorttitleSentenceCaseModified() { bibtexKeyPattern.setDefaultValue("[shorttitle:sentence_case]"); entry.setField("title", "An aweSOme Paper on JabRef"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("Anawesomepaper"), entry.getCiteKeyOptional()); } @@ -265,14 +270,14 @@ public void generateKeyShorttitleSentenceCaseModified() { public void generateKeyShorttitleCapitalizeModified() { bibtexKeyPattern.setDefaultValue("[shorttitle:capitalize]"); entry.setField("title", "An aweSOme Paper on JabRef"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("AnAwesomePaper"), entry.getCiteKeyOptional()); } @Test public void generateKeyVeryshorttitle() { bibtexKeyPattern.setDefaultValue("[veryshorttitle]"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("awesome"), entry.getCiteKeyOptional()); } @@ -280,7 +285,7 @@ public void generateKeyVeryshorttitle() { public void generateKeyVeryshorttitleLowerModified() { bibtexKeyPattern.setDefaultValue("[veryshorttitle:lower]"); entry.setField("title", "An aweSOme Paper on JabRef"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("awesome"), entry.getCiteKeyOptional()); } @@ -288,7 +293,7 @@ public void generateKeyVeryshorttitleLowerModified() { public void generateKeyVeryshorttitleUpperModified() { bibtexKeyPattern.setDefaultValue("[veryshorttitle:upper]"); entry.setField("title", "An aweSOme Paper on JabRef"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("AWESOME"), entry.getCiteKeyOptional()); } @@ -296,7 +301,7 @@ public void generateKeyVeryshorttitleUpperModified() { public void generateKeyVeryshorttitleTitleCaseModified() { bibtexKeyPattern.setDefaultValue("[veryshorttitle:title_case]"); entry.setField("title", "An aweSOme Paper on JabRef"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("Awesome"), entry.getCiteKeyOptional()); } @@ -304,7 +309,7 @@ public void generateKeyVeryshorttitleTitleCaseModified() { public void generateKeyVeryshorttitleSentenceCaseModified() { bibtexKeyPattern.setDefaultValue("[veryshorttitle:sentence_case]"); entry.setField("title", "An aweSOme Paper on JabRef"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("Awesome"), entry.getCiteKeyOptional()); } @@ -312,21 +317,21 @@ public void generateKeyVeryshorttitleSentenceCaseModified() { public void generateKeyVeryshorttitleCapitalizeModified() { bibtexKeyPattern.setDefaultValue("[veryshorttitle:capitalize]"); entry.setField("title", "An aweSOme Paper on JabRef"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("Awesome"), entry.getCiteKeyOptional()); } @Test public void generateKeyShorttitleINI() { bibtexKeyPattern.setDefaultValue("[shorttitleINI]"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("Aap"), entry.getCiteKeyOptional()); } @Test public void generateKeyCamel() { bibtexKeyPattern.setDefaultValue("[camel]"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("AnAwesomePaperOnJabRef"), entry.getCiteKeyOptional()); } @@ -334,7 +339,7 @@ public void generateKeyCamel() { public void generateKeyAuthNM() { bibtexKeyPattern.setDefaultValue("[auth4_3]"); entry.setField("author", "John Doe and Donald Smith and Will Wonder"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("Wond"), entry.getCiteKeyOptional()); } @@ -342,7 +347,7 @@ public void generateKeyAuthNM() { public void generateKeyAuthNMLargeN() { bibtexKeyPattern.setDefaultValue("[auth20_3]"); entry.setField("author", "John Doe and Donald Smith and Will Wonder"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("Wonder"), entry.getCiteKeyOptional()); } @@ -350,7 +355,7 @@ public void generateKeyAuthNMLargeN() { public void generateKeyAuthNMLargeM() { bibtexKeyPattern.setDefaultValue("[auth2_4]"); entry.setField("author", "John Doe and Donald Smith and Will Wonder"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.empty(), entry.getCiteKeyOptional()); } @@ -358,7 +363,7 @@ public void generateKeyAuthNMLargeM() { public void generateKeyAuthNMLargeMReallyReturnsEmptyString() { bibtexKeyPattern.setDefaultValue("[auth2_4][year]"); entry.setField("author", "John Doe and Donald Smith and Will Wonder"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("2016"), entry.getCiteKeyOptional()); } @@ -367,7 +372,7 @@ public void generateKeyRegExReplace() { preferences = new BibtexKeyPatternPreferences("2", "3", false, true, true, pattern, ','); bibtexKeyPattern.setDefaultValue("[auth][year]"); entry.setField("author", "John Doe and Donald Smith and Will Wonder"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("Doe3016"), entry.getCiteKeyOptional()); } @@ -375,7 +380,7 @@ public void generateKeyRegExReplace() { public void generateKeyAuthIni() { bibtexKeyPattern.setDefaultValue("[authIni2]"); entry.setField("author", "John Doe and Donald Smith and Will Wonder"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("DS"), entry.getCiteKeyOptional()); } @@ -383,7 +388,7 @@ public void generateKeyAuthIni() { public void generateKeyAuthIniMany() { bibtexKeyPattern.setDefaultValue("[authIni10]"); entry.setField("author", "John Doe and Donald Smith and Will Wonder"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("DoeSmiWon"), entry.getCiteKeyOptional()); } @@ -391,49 +396,49 @@ public void generateKeyAuthIniMany() { public void generateKeyTitleRegexe() { bibtexKeyPattern.setDefaultValue("[title:regex(\" \",\"-\")]"); entry.setField("title", "Please replace the spaces"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("Please-Replace-the-Spaces"), entry.getCiteKeyOptional()); } @Test public void generateKeyTitleTitleCase() { bibtexKeyPattern.setDefaultValue("[title:title_case]"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("AnAwesomePaperonJabref"), entry.getCiteKeyOptional()); } @Test public void generateKeyTitleCapitalize() { bibtexKeyPattern.setDefaultValue("[title:capitalize]"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("AnAwesomePaperOnJabref"), entry.getCiteKeyOptional()); } @Test public void generateKeyTitleSentenceCase() { bibtexKeyPattern.setDefaultValue("[title:sentence_case]"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("Anawesomepaperonjabref"), entry.getCiteKeyOptional()); } @Test public void generateKeyTitleTitleCaseAbbr() { bibtexKeyPattern.setDefaultValue("[title:title_case:abbr]"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("AAPoJ"), entry.getCiteKeyOptional()); } @Test public void generateKeyTitleCapitalizeAbbr() { bibtexKeyPattern.setDefaultValue("[title:capitalize:abbr]"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("AAPOJ"), entry.getCiteKeyOptional()); } @Test public void generateKeyTitleSentenceCaseAbbr() { bibtexKeyPattern.setDefaultValue("[title:sentence_case:abbr]"); - BibtexKeyPatternUtil.makeAndSetLabel(bibtexKeyPattern, database, entry, preferences); + new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); assertEquals(Optional.of("Aapoj"), entry.getCiteKeyOptional()); } } diff --git a/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithoutDatabaseTest.java b/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithoutDatabaseTest.java index b56e02e4623..fc0bd39f903 100644 --- a/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithoutDatabaseTest.java +++ b/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithoutDatabaseTest.java @@ -22,7 +22,7 @@ public void setUp() { @Test public void makeLabelForFileSearch() { String label = - BibtexKeyPatternUtil.makeLabel(entry, "auth", ',', null); + BibtexKeyGenerator.generateKey(entry, "auth", ',', null); assertEquals("Doe", label); } @@ -34,7 +34,7 @@ public void makeEditorLabelForFileSearch() { localEntry.setField("title", "An awesome paper on JabRef"); String label = - BibtexKeyPatternUtil.makeLabel(localEntry, "auth", ',', null); + BibtexKeyGenerator.generateKey(localEntry, "auth", ',', null); assertEquals("Doe", label); } From 7c9767f0faded801b288b0bc18e8cc015972a0d7 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Sat, 9 Dec 2017 14:34:11 +0100 Subject: [PATCH 2/6] Fix #3359: Automatically remove colon and apostrophe from key pattern --- CHANGELOG.md | 1 + .../bibtexkeypattern/BibtexKeyGenerator.java | 15 ++- .../BibtexKeyGeneratorTest.java | 105 ++++++++++-------- .../MakeLabelWithoutDatabaseTest.java | 4 +- 4 files changed, 74 insertions(+), 51 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a45707b6851..3a1c088a42f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - We fixed an issue where double clicking on an entry in the integrity check dialog resulted in an exception [#3485](https://github.com/JabRef/jabref/issues/3485) - We fixed an issue where the entry type could sometimes not be changed when the entry editor was open [#3435](https://github.com/JabRef/jabref/issues/3435) - We fixed an issue where dropping a pdf on the entry table and renaming it triggered an exception [#3490](https://github.com/JabRef/jabref/issues/3490) + - We improved the key generator to remove certain illegal characters such as colons or apostrophes. [#3359](https://github.com/JabRef/jabref/issues/3359) ### Removed diff --git a/src/main/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGenerator.java b/src/main/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGenerator.java index 8bf54c59e34..022ba25a945 100644 --- a/src/main/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGenerator.java +++ b/src/main/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGenerator.java @@ -1,6 +1,7 @@ package org.jabref.logic.bibtexkeypattern; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -8,6 +9,7 @@ import org.jabref.logic.util.BracketedPattern; import org.jabref.model.FieldChange; import org.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern; +import org.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern; import org.jabref.model.database.BibDatabase; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; @@ -43,8 +45,15 @@ public BibtexKeyGenerator(AbstractBibtexKeyPattern citeKeyPattern, BibDatabase d this.bibtexKeyPatternPreferences = bibtexKeyPatternPreferences; } - static String generateKey(BibEntry entry, String value, Character keywordDelimiter, BibDatabase database) { - return expandBrackets("[" + value + "]", keywordDelimiter, entry, database); + static String generateKey(BibEntry entry, String value) { + return generateKey(entry, value, new BibDatabase()); + } + + static String generateKey(BibEntry entry, String value, BibDatabase database) { + GlobalBibtexKeyPattern keyPattern = new GlobalBibtexKeyPattern(Collections.emptyList()); + keyPattern.setDefaultValue("[" + value + "]"); + return new BibtexKeyGenerator(keyPattern, database, new BibtexKeyPatternPreferences("", "", false, true, true, keyPattern, ',')) + .generateKey(entry); } /** @@ -91,7 +100,7 @@ public static String cleanKey(String key, boolean enforceLegalKey) { StringBuilder newKey = new StringBuilder(); for (int i = 0; i < key.length(); i++) { char c = key.charAt(i); - if (!Character.isWhitespace(c) && ("{}(),\\\"#~^'".indexOf(c) == -1)) { + if (!Character.isWhitespace(c) && ("{}(),\\\"#~^':`".indexOf(c) == -1)) { newKey.append(c); } } diff --git a/src/test/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGeneratorTest.java b/src/test/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGeneratorTest.java index 1a6804772bf..0efa38de786 100644 --- a/src/test/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGeneratorTest.java +++ b/src/test/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGeneratorTest.java @@ -54,7 +54,7 @@ public void testAndInAuthorName() throws ParseException { importFormatPreferences); assertEquals("Holland", BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth", - ',', new BibDatabase()), true)); + new BibDatabase()), true)); } @Test @@ -70,7 +70,7 @@ public void testCrossrefAndInAuthorNames() throws Exception { assertEquals("Holland", BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry1, "auth", - ',', database), true)); + database), true)); } @Test @@ -79,7 +79,7 @@ public void testAndAuthorNames() throws ParseException { Optional entry = BibtexParser.singleFromString(bibtexString, importFormatPreferences); assertEquals("HerlandHaugeHelgeland", BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry.get(), "authors3", - ',', new BibDatabase()), true)); + new BibDatabase()), true)); } @Test @@ -95,7 +95,7 @@ public void testCrossrefAndAuthorNames() throws Exception { assertEquals("HerlandHaugeHelgeland", BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry1, "authors3", - ',', database), true)); + database), true)); } @Test @@ -104,7 +104,7 @@ public void testSpecialLatexCharacterInAuthorName() throws ParseException { "@ARTICLE{kohn, author={Simon Popovi\\v{c}ov\\'{a}}}", importFormatPreferences); assertEquals("Popovicova", BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry.get(), "auth", - ',', new BibDatabase()), true)); + new BibDatabase()), true)); } /** @@ -118,73 +118,73 @@ public void testMakeLabelAndCheckLegalKeys() throws ParseException { "@ARTICLE{kohn, author={Andreas Köning}, year={2000}}", importFormatPreferences); assertEquals("Koen", BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", - ',', new BibDatabase()), true)); + new BibDatabase()), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Áöning}, year={2000}}", importFormatPreferences); assertEquals("Aoen", BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", - ',', new BibDatabase()), true)); + new BibDatabase()), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Éöning}, year={2000}}", importFormatPreferences); assertEquals("Eoen", BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", - ',', new BibDatabase()), true)); + new BibDatabase()), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Íöning}, year={2000}}", importFormatPreferences); assertEquals("Ioen", BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", - ',', new BibDatabase()), true)); + new BibDatabase()), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Ĺöning}, year={2000}}", importFormatPreferences); assertEquals("Loen", BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", - ',', new BibDatabase()), true)); + new BibDatabase()), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Ńöning}, year={2000}}", importFormatPreferences); assertEquals("Noen", BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", - ',', new BibDatabase()), true)); + new BibDatabase()), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Óöning}, year={2000}}", importFormatPreferences); assertEquals("Ooen", BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", - ',', new BibDatabase()), true)); + new BibDatabase()), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Ŕöning}, year={2000}}", importFormatPreferences); assertEquals("Roen", BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", - ',', new BibDatabase()), true)); + new BibDatabase()), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Śöning}, year={2000}}", importFormatPreferences); assertEquals("Soen", BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", - ',', new BibDatabase()), true)); + new BibDatabase()), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Úöning}, year={2000}}", importFormatPreferences); assertEquals("Uoen", BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", - ',', new BibDatabase()), true)); + new BibDatabase()), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Ýöning}, year={2000}}", importFormatPreferences); assertEquals("Yoen", BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", - ',', new BibDatabase()), true)); + new BibDatabase()), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Źöning}, year={2000}}", importFormatPreferences); assertEquals("Zoen", BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", - ',', new BibDatabase()), true)); + new BibDatabase()), true)); } /** @@ -196,31 +196,31 @@ public void testMakeLabelAndCheckLegalKeysAccentGrave() throws ParseException { "@ARTICLE{kohn, author={Andreas Àöning}, year={2000}}", importFormatPreferences); assertEquals("Aoen", BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", - ',', new BibDatabase()), true)); + new BibDatabase()), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Èöning}, year={2000}}", importFormatPreferences); assertEquals("Eoen", BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", - ',', new BibDatabase()), true)); + new BibDatabase()), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Ìöning}, year={2000}}", importFormatPreferences); assertEquals("Ioen", BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", - ',', new BibDatabase()), true)); + new BibDatabase()), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Òöning}, year={2000}}", importFormatPreferences); assertEquals("Ooen", BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", - ',', new BibDatabase()), true)); + new BibDatabase()), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Ùöning}, year={2000}}", importFormatPreferences); assertEquals("Uoen", BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry0.get(), "auth3", - ',', new BibDatabase()), true)); + new BibDatabase()), true)); } /** @@ -309,7 +309,7 @@ public void testUniversity() throws ParseException { "@ARTICLE{kohn, author={{Link{\\\"{o}}ping University}}}", importFormatPreferences); assertEquals("UniLinkoeping", BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry.get(), "auth", - ',', new BibDatabase()), true)); + new BibDatabase()), true)); } @Test @@ -325,7 +325,7 @@ public void testcrossrefUniversity() throws Exception { assertEquals("UniLinkoeping", BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry1, "auth", - ',', database), true)); + database), true)); } @Test @@ -335,7 +335,7 @@ public void testDepartment() throws ParseException { importFormatPreferences); assertEquals("UniLinkoepingEE", BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry.get(), "auth", - ',', new BibDatabase()), true)); + new BibDatabase()), true)); } @Test @@ -351,7 +351,7 @@ public void testcrossrefDepartment() throws Exception { assertEquals("UniLinkoepingEE", BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry1, "auth", - ',', database), true)); + database), true)); } @Test @@ -361,7 +361,7 @@ public void testSchool() throws ParseException { importFormatPreferences); assertEquals("UniLinkoepingCE", BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry.get(), "auth", - ',', new BibDatabase()), true)); + new BibDatabase()), true)); } @Test @@ -377,7 +377,7 @@ public void testcrossrefSchool() throws Exception { assertEquals("UniLinkoepingCE", BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry1, "auth", - ',', database), true)); + database), true)); } @Test @@ -386,7 +386,7 @@ public void testInstituteOfTechnology() throws ParseException { "@ARTICLE{kohn, author={{Massachusetts Institute of Technology}}}", importFormatPreferences); assertEquals("MIT", BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry.get(), "auth", - ',', new BibDatabase()), true)); + new BibDatabase()), true)); } @Test @@ -402,7 +402,7 @@ public void testcrossrefInstituteOfTechnology() throws Exception { assertEquals("MIT", BibtexKeyGenerator.cleanKey(BibtexKeyGenerator.generateKey(entry1, "auth", - ',', database), true)); + database), true)); } @Test @@ -851,15 +851,15 @@ public void keywordNKeywordsSeparatedBySpace() { BibEntry entry = new BibEntry(); entry.setField("keywords", "w1, w2a w2b, w3"); - String result = BibtexKeyGenerator.generateKey(entry, "keyword1", ',', new BibDatabase()); + String result = BibtexKeyGenerator.generateKey(entry, "keyword1"); assertEquals("w1", result); // check keywords with space - result = BibtexKeyGenerator.generateKey(entry, "keyword2", ',', new BibDatabase()); - assertEquals("w2a w2b", result); + result = BibtexKeyGenerator.generateKey(entry, "keyword2"); + assertEquals("w2aw2b", result); // check out of range - result = BibtexKeyGenerator.generateKey(entry, "keyword4", ',', new BibDatabase()); + result = BibtexKeyGenerator.generateKey(entry, "keyword4"); assertEquals("", result); } @@ -874,7 +874,7 @@ public void crossrefkeywordNKeywordsSeparatedBySpace() { database.insertEntry(entry1); entry2.setField("keywords", "w1, w2a w2b, w3"); - String result = BibtexKeyGenerator.generateKey(entry1, "keyword1", ',', database); + String result = BibtexKeyGenerator.generateKey(entry1, "keyword1", database); assertEquals("w1", result); } @@ -885,15 +885,15 @@ public void keywordsNKeywordsSeparatedBySpace() { entry.setField("keywords", "w1, w2a w2b, w3"); // all keywords - String result = BibtexKeyGenerator.generateKey(entry, "keywords", ',', new BibDatabase()); + String result = BibtexKeyGenerator.generateKey(entry, "keywords"); assertEquals("w1w2aw2bw3", result); // check keywords with space - result = BibtexKeyGenerator.generateKey(entry, "keywords2", ',', new BibDatabase()); + result = BibtexKeyGenerator.generateKey(entry, "keywords2"); assertEquals("w1w2aw2b", result); // check out of range - result = BibtexKeyGenerator.generateKey(entry, "keywords55", ',', new BibDatabase()); + result = BibtexKeyGenerator.generateKey(entry, "keywords55"); assertEquals("w1w2aw2bw3", result); } @@ -908,7 +908,7 @@ public void crossrefkeywordsNKeywordsSeparatedBySpace() { database.insertEntry(entry1); entry2.setField("keywords", "w1, w2a w2b, w3"); - String result = BibtexKeyGenerator.generateKey(entry1, "keywords", ',', database); + String result = BibtexKeyGenerator.generateKey(entry1, "keywords", database); assertEquals("w1w2aw2bw3", result); } @@ -927,7 +927,7 @@ public void testCheckLegalKeyDoNotEnforceLegal() { assertEquals("", BibtexKeyGenerator.cleanKey("\n\t\r", false)); } - @Test + @Test(expected = NullPointerException.class) public void testCheckLegalNullInNullOut() { assertNull(BibtexKeyGenerator.cleanKey(null, true)); assertNull(BibtexKeyGenerator.cleanKey(null, false)); @@ -937,9 +937,9 @@ public void testCheckLegalNullInNullOut() { public void testApplyModifiers() { BibEntry entry = new BibEntry(); entry.setField("title", "Green Scheduling of Whatever"); - assertEquals("GSo", BibtexKeyGenerator.generateKey(entry, "shorttitleINI", ',', new BibDatabase())); - assertEquals("Green Scheduling of", BibtexKeyGenerator.generateKey(entry, "shorttitle", - ',', new BibDatabase())); + assertEquals("GSo", BibtexKeyGenerator.generateKey(entry, "shorttitleINI")); + assertEquals("GreenSchedulingof", BibtexKeyGenerator.generateKey(entry, "shorttitle", + new BibDatabase())); } @Test @@ -953,8 +953,8 @@ public void testcrossrefShorttitle() { database.insertEntry(entry1); entry2.setField("title", "Green Scheduling of Whatever"); - assertEquals("Green Scheduling of", BibtexKeyGenerator.generateKey(entry1, "shorttitle", - ',', database)); + assertEquals("GreenSchedulingof", BibtexKeyGenerator.generateKey(entry1, "shorttitle", + database)); } @Test @@ -968,7 +968,20 @@ public void testcrossrefShorttitleInitials() { database.insertEntry(entry1); entry2.setField("title", "Green Scheduling of Whatever"); - assertEquals("GSo", BibtexKeyGenerator.generateKey(entry1, "shorttitleINI", ',', database)); + assertEquals("GSo", BibtexKeyGenerator.generateKey(entry1, "shorttitleINI", database)); } + @Test + public void generateKeyStripsColonFromTitle() throws Exception { + BibEntry entry = new BibEntry(); + entry.setField("title", "Green Scheduling of: Whatever"); + assertEquals("GreenSchedulingOfWhatever", BibtexKeyGenerator.generateKey(entry, "title")); + } + + @Test + public void generateKeyStripsApostropheFromTitle() throws Exception { + BibEntry entry = new BibEntry(); + entry.setField("title", "Green Scheduling of `Whatever`"); + assertEquals("GreenSchedulingofWhatever", BibtexKeyGenerator.generateKey(entry, "title")); + } } diff --git a/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithoutDatabaseTest.java b/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithoutDatabaseTest.java index fc0bd39f903..3713cf4a7cc 100644 --- a/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithoutDatabaseTest.java +++ b/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithoutDatabaseTest.java @@ -22,7 +22,7 @@ public void setUp() { @Test public void makeLabelForFileSearch() { String label = - BibtexKeyGenerator.generateKey(entry, "auth", ',', null); + BibtexKeyGenerator.generateKey(entry, "auth", null); assertEquals("Doe", label); } @@ -34,7 +34,7 @@ public void makeEditorLabelForFileSearch() { localEntry.setField("title", "An awesome paper on JabRef"); String label = - BibtexKeyGenerator.generateKey(localEntry, "auth", ',', null); + BibtexKeyGenerator.generateKey(localEntry, "auth", null); assertEquals("Doe", label); } From 3acea8a907ba671c69b452e1b85605b6f6538ac5 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Sat, 23 Dec 2017 14:21:25 +0100 Subject: [PATCH 3/6] Minor code review and fix tests --- .../logic/bibtexkeypattern/BibtexKeyGenerator.java | 12 +++++++----- src/main/resources/l10n/JabRef_da.properties | 2 +- src/main/resources/l10n/JabRef_de.properties | 2 +- src/main/resources/l10n/JabRef_el.properties | 2 +- src/main/resources/l10n/JabRef_en.properties | 2 +- src/main/resources/l10n/JabRef_es.properties | 2 +- src/main/resources/l10n/JabRef_fa.properties | 2 +- src/main/resources/l10n/JabRef_fr.properties | 2 +- src/main/resources/l10n/JabRef_in.properties | 2 +- src/main/resources/l10n/JabRef_it.properties | 2 +- src/main/resources/l10n/JabRef_ja.properties | 2 +- src/main/resources/l10n/JabRef_nl.properties | 2 +- src/main/resources/l10n/JabRef_no.properties | 2 +- src/main/resources/l10n/JabRef_pt_BR.properties | 2 +- src/main/resources/l10n/JabRef_ru.properties | 2 +- src/main/resources/l10n/JabRef_sv.properties | 2 +- src/main/resources/l10n/JabRef_tr.properties | 2 +- src/main/resources/l10n/JabRef_vi.properties | 2 +- src/main/resources/l10n/JabRef_zh.properties | 2 +- .../bibtexkeypattern/MakeLabelWithDatabaseTest.java | 4 ++-- .../MakeLabelWithoutDatabaseTest.java | 6 ++---- 21 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGenerator.java b/src/main/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGenerator.java index 022ba25a945..3ee8bf7e131 100644 --- a/src/main/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGenerator.java +++ b/src/main/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGenerator.java @@ -29,6 +29,8 @@ public class BibtexKeyGenerator extends BracketedPattern { * All single characters that we can use for extending a key to make it unique. */ private static final String APPENDIX_CHARACTERS = "abcdefghijklmnopqrstuvwxyz"; + private static final String KEY_ILLEGAL_CHARACTERS = "{}(),\\\"#~^':`"; + private static final String KEY_UNWANTED_CHARACTERS = "{}(),\\\""; private final AbstractBibtexKeyPattern citeKeyPattern; private final BibDatabase database; private final BibtexKeyPatternPreferences bibtexKeyPatternPreferences; @@ -40,9 +42,9 @@ public BibtexKeyGenerator(BibDatabaseContext bibDatabaseContext, BibtexKeyPatter } public BibtexKeyGenerator(AbstractBibtexKeyPattern citeKeyPattern, BibDatabase database, BibtexKeyPatternPreferences bibtexKeyPatternPreferences) { - this.citeKeyPattern = citeKeyPattern; - this.database = database; - this.bibtexKeyPatternPreferences = bibtexKeyPatternPreferences; + this.citeKeyPattern = Objects.requireNonNull(citeKeyPattern); + this.database = Objects.requireNonNull(database); + this.bibtexKeyPatternPreferences = Objects.requireNonNull(bibtexKeyPatternPreferences); } static String generateKey(BibEntry entry, String value) { @@ -90,7 +92,7 @@ public static String cleanKey(String key, boolean enforceLegalKey) { StringBuilder newKey = new StringBuilder(); for (int i = 0; i < key.length(); i++) { char c = key.charAt(i); - if (!Character.isWhitespace(c) && ("{}(),\\\"".indexOf(c) == -1)) { + if (!Character.isWhitespace(c) && (KEY_UNWANTED_CHARACTERS.indexOf(c) == -1)) { newKey.append(c); } } @@ -100,7 +102,7 @@ public static String cleanKey(String key, boolean enforceLegalKey) { StringBuilder newKey = new StringBuilder(); for (int i = 0; i < key.length(); i++) { char c = key.charAt(i); - if (!Character.isWhitespace(c) && ("{}(),\\\"#~^':`".indexOf(c) == -1)) { + if (!Character.isWhitespace(c) && (KEY_ILLEGAL_CHARACTERS.indexOf(c) == -1)) { newKey.append(c); } } diff --git a/src/main/resources/l10n/JabRef_da.properties b/src/main/resources/l10n/JabRef_da.properties index 56749309ffb..39b36085ce8 100644 --- a/src/main/resources/l10n/JabRef_da.properties +++ b/src/main/resources/l10n/JabRef_da.properties @@ -1,4 +1,5 @@ + #! #! created/edited by Popeye version 0.55 (github.com/JabRef/popeye) #! encoding:UTF-8 @@ -1884,7 +1885,6 @@ should_contain_a_protocol= Copy_preview= Automatically_setting_file_links= Regenerating_BibTeX_keys_according_to_metadata= -No_meta_data_present_in_BIB_file._Cannot_regenerate_BibTeX_keys= Regenerate_all_keys_for_the_entries_in_a_BibTeX_file= Show_debug_level_messages= Default_bibliography_mode= diff --git a/src/main/resources/l10n/JabRef_de.properties b/src/main/resources/l10n/JabRef_de.properties index 59f72f492d4..0fadb045415 100644 --- a/src/main/resources/l10n/JabRef_de.properties +++ b/src/main/resources/l10n/JabRef_de.properties @@ -1,4 +1,5 @@ + #! #! created/edited by Popeye version 0.55 (github.com/JabRef/popeye) #! encoding:UTF-8 @@ -1884,7 +1885,6 @@ should_contain_a_protocol=sollte_ein_Protokoll_beinhalten Copy_preview=Kopiere_Vorschau Automatically_setting_file_links=Dateilinks_werden_automatisch_gesetzt Regenerating_BibTeX_keys_according_to_metadata=Regeneriere_BibTeX-Keys_anhand_ihrer_Metadaten -No_meta_data_present_in_BIB_file._Cannot_regenerate_BibTeX_keys=Keine_Metadaten_in_Bibdatei_vorhanden._Kann_keine_BibTeX-Keys_regenerieren Regenerate_all_keys_for_the_entries_in_a_BibTeX_file=Regeneriere_alle_BibTeX-Keys_für_Einträge_in_einer_BibTeX_Datei Show_debug_level_messages=Zeige_Debug_Level_Meldungen Default_bibliography_mode=Standard_Bibliographiemodus diff --git a/src/main/resources/l10n/JabRef_el.properties b/src/main/resources/l10n/JabRef_el.properties index c81a9362b5d..3a209183ec6 100644 --- a/src/main/resources/l10n/JabRef_el.properties +++ b/src/main/resources/l10n/JabRef_el.properties @@ -1,4 +1,5 @@ + #! #! created/edited by Popeye version 0.55 (github.com/JabRef/popeye) #! encoding:UTF-8 @@ -1884,7 +1885,6 @@ should_contain_a_protocol= Copy_preview= Automatically_setting_file_links= Regenerating_BibTeX_keys_according_to_metadata= -No_meta_data_present_in_BIB_file._Cannot_regenerate_BibTeX_keys= Regenerate_all_keys_for_the_entries_in_a_BibTeX_file= Show_debug_level_messages= Default_bibliography_mode= diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 269893a990d..7bed0d4e24d 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -1,4 +1,5 @@ + #! #! created/edited by Popeye version 0.55 (github.com/JabRef/popeye) #! encoding:UTF-8 @@ -1884,7 +1885,6 @@ should_contain_a_protocol=should_contain_a_protocol Copy_preview=Copy_preview Automatically_setting_file_links=Automatically_setting_file_links Regenerating_BibTeX_keys_according_to_metadata=Regenerating_BibTeX_keys_according_to_metadata -No_meta_data_present_in_BIB_file._Cannot_regenerate_BibTeX_keys=No_meta_data_present_in_BIB_file._Cannot_regenerate_BibTeX_keys Regenerate_all_keys_for_the_entries_in_a_BibTeX_file=Regenerate_all_keys_for_the_entries_in_a_BibTeX_file Show_debug_level_messages=Show_debug_level_messages Default_bibliography_mode=Default_bibliography_mode diff --git a/src/main/resources/l10n/JabRef_es.properties b/src/main/resources/l10n/JabRef_es.properties index e4a79916c82..5890c503121 100644 --- a/src/main/resources/l10n/JabRef_es.properties +++ b/src/main/resources/l10n/JabRef_es.properties @@ -1,4 +1,5 @@ + #! #! created/edited by Popeye version 0.55 (github.com/JabRef/popeye) #! encoding:UTF-8 @@ -1884,7 +1885,6 @@ should_contain_a_protocol=Debería_contener_un_protocolo Copy_preview=Copiar_vista_previa Automatically_setting_file_links=Estableciendo_automáticamente_enlaces_de_archivo Regenerating_BibTeX_keys_according_to_metadata=Regenerando_claves_BibTeX_de_acuerdo_a_los_metadatos -No_meta_data_present_in_BIB_file._Cannot_regenerate_BibTeX_keys=No_hay_metadatos_en_el_BIB_file._No_se_pueden_regenerar_las_claves_BibTex Regenerate_all_keys_for_the_entries_in_a_BibTeX_file=Regenerar_todas_las_claves_para_las_entradas_de_un_archivo_BibTeX Show_debug_level_messages=Mostrar_mensajes_de_nivel_de_depuración Default_bibliography_mode=Modo_de_bibliografía_por_defecto diff --git a/src/main/resources/l10n/JabRef_fa.properties b/src/main/resources/l10n/JabRef_fa.properties index dd3189d3938..3eddc6bfbab 100644 --- a/src/main/resources/l10n/JabRef_fa.properties +++ b/src/main/resources/l10n/JabRef_fa.properties @@ -1,4 +1,5 @@ + #! #! created/edited by Popeye version 0.55 (github.com/JabRef/popeye) #! encoding:UTF-8 @@ -1884,7 +1885,6 @@ should_contain_a_protocol= Copy_preview= Automatically_setting_file_links= Regenerating_BibTeX_keys_according_to_metadata= -No_meta_data_present_in_BIB_file._Cannot_regenerate_BibTeX_keys= Regenerate_all_keys_for_the_entries_in_a_BibTeX_file= Show_debug_level_messages= Default_bibliography_mode= diff --git a/src/main/resources/l10n/JabRef_fr.properties b/src/main/resources/l10n/JabRef_fr.properties index 4f6610e0460..4f1a9fec5b5 100644 --- a/src/main/resources/l10n/JabRef_fr.properties +++ b/src/main/resources/l10n/JabRef_fr.properties @@ -1,4 +1,5 @@ + #! #! created/edited by Popeye version 0.55 (github.com/JabRef/popeye) #! encoding:UTF-8 @@ -1884,7 +1885,6 @@ should_contain_a_protocol=doit_contenir_un_protocole Copy_preview=Copier_la_prévisualisation Automatically_setting_file_links=Définition_automatique_des_liens_de_fichier Regenerating_BibTeX_keys_according_to_metadata=Régénération_des_clefs_BibTeX_à_partir_des_métadonnées -No_meta_data_present_in_BIB_file._Cannot_regenerate_BibTeX_keys=Aucune_métadonnée_dans_le_fichier_BibTeX._Les_clefs_n'ont_pas_pu_être_régénérées Regenerate_all_keys_for_the_entries_in_a_BibTeX_file=Régénére_toutes_les_clefs_pour_les_entrées_d'un_fichier_BibTeX Show_debug_level_messages=Afficher_les_messages_de_débogage Default_bibliography_mode=Mode_bibliographique_par_défaut diff --git a/src/main/resources/l10n/JabRef_in.properties b/src/main/resources/l10n/JabRef_in.properties index 16d7d11dff3..4f8b12f53cb 100644 --- a/src/main/resources/l10n/JabRef_in.properties +++ b/src/main/resources/l10n/JabRef_in.properties @@ -1,4 +1,5 @@ + #! #! created/edited by Popeye version 0.55 (github.com/JabRef/popeye) #! encoding:UTF-8 @@ -1884,7 +1885,6 @@ should_contain_a_protocol= Copy_preview= Automatically_setting_file_links= Regenerating_BibTeX_keys_according_to_metadata= -No_meta_data_present_in_BIB_file._Cannot_regenerate_BibTeX_keys= Regenerate_all_keys_for_the_entries_in_a_BibTeX_file= Show_debug_level_messages= Default_bibliography_mode=Mode_bibliografi_bawaan diff --git a/src/main/resources/l10n/JabRef_it.properties b/src/main/resources/l10n/JabRef_it.properties index 0cf089aae3e..eb87794ec82 100644 --- a/src/main/resources/l10n/JabRef_it.properties +++ b/src/main/resources/l10n/JabRef_it.properties @@ -1,4 +1,5 @@ + #! #! created/edited by Popeye version 0.55 (github.com/JabRef/popeye) #! encoding:UTF-8 @@ -1884,7 +1885,6 @@ should_contain_a_protocol=deve_contenere_un_protocollo Copy_preview=Copia_l'anteprima Automatically_setting_file_links=Seleziona_automaticamente_i_collegamenti_ai_file Regenerating_BibTeX_keys_according_to_metadata=Rigenera_le_chiavi_BibTeX_secondo_i_metadati -No_meta_data_present_in_BIB_file._Cannot_regenerate_BibTeX_keys=Non_ci_sono_meta_nel_fil_BIB._Non_posso_rigenerare_le_chiavi_BibTeX Regenerate_all_keys_for_the_entries_in_a_BibTeX_file=Rigenera_tutte_le_chiavi_per_i_campi_di_un_file_BibTeX Show_debug_level_messages=Mostra_i_messaggi_del_livello_di_debug Default_bibliography_mode=Modalità_bibliografica_predefinita diff --git a/src/main/resources/l10n/JabRef_ja.properties b/src/main/resources/l10n/JabRef_ja.properties index bc9041616e2..4ffb63ff2c2 100644 --- a/src/main/resources/l10n/JabRef_ja.properties +++ b/src/main/resources/l10n/JabRef_ja.properties @@ -1,4 +1,5 @@ + #! #! created/edited by Popeye version 0.55 (github.com/JabRef/popeye) #! encoding:UTF-8 @@ -1884,7 +1885,6 @@ should_contain_a_protocol=プロトコルを含む必要あり Copy_preview=プレビューをコピー Automatically_setting_file_links=ファイルリンクを自動的に設定 Regenerating_BibTeX_keys_according_to_metadata=メタデータにしたがってBibTeX鍵を再生成 -No_meta_data_present_in_BIB_file._Cannot_regenerate_BibTeX_keys=bibファイルにメタデータがありません.BibTeX鍵を再生成することができません Regenerate_all_keys_for_the_entries_in_a_BibTeX_file=BibTeXファイル中全項目の鍵を再生成 Show_debug_level_messages=デバッグレベルメッセージを表示 Default_bibliography_mode=既定の書誌情報モード diff --git a/src/main/resources/l10n/JabRef_nl.properties b/src/main/resources/l10n/JabRef_nl.properties index 067015bd7de..bebf0816447 100644 --- a/src/main/resources/l10n/JabRef_nl.properties +++ b/src/main/resources/l10n/JabRef_nl.properties @@ -1,4 +1,5 @@ + #! #! created/edited by Popeye version 0.55 (github.com/JabRef/popeye) #! encoding:UTF-8 @@ -1884,7 +1885,6 @@ should_contain_a_protocol= Copy_preview= Automatically_setting_file_links= Regenerating_BibTeX_keys_according_to_metadata= -No_meta_data_present_in_BIB_file._Cannot_regenerate_BibTeX_keys= Regenerate_all_keys_for_the_entries_in_a_BibTeX_file= Show_debug_level_messages= Default_bibliography_mode= diff --git a/src/main/resources/l10n/JabRef_no.properties b/src/main/resources/l10n/JabRef_no.properties index 5153834cd97..3a2fc53b914 100644 --- a/src/main/resources/l10n/JabRef_no.properties +++ b/src/main/resources/l10n/JabRef_no.properties @@ -1,4 +1,5 @@ + #! #! created/edited by Popeye version 0.55 (github.com/JabRef/popeye) #! encoding:UTF-8 @@ -1884,7 +1885,6 @@ should_contain_a_protocol= Copy_preview= Automatically_setting_file_links= Regenerating_BibTeX_keys_according_to_metadata= -No_meta_data_present_in_BIB_file._Cannot_regenerate_BibTeX_keys= Regenerate_all_keys_for_the_entries_in_a_BibTeX_file= Show_debug_level_messages= Default_bibliography_mode= diff --git a/src/main/resources/l10n/JabRef_pt_BR.properties b/src/main/resources/l10n/JabRef_pt_BR.properties index e10edea1c0b..3518a2632d2 100644 --- a/src/main/resources/l10n/JabRef_pt_BR.properties +++ b/src/main/resources/l10n/JabRef_pt_BR.properties @@ -1,4 +1,5 @@ + #! #! created/edited by Popeye version 0.55 (github.com/JabRef/popeye) #! encoding:UTF-8 @@ -1884,7 +1885,6 @@ should_contain_a_protocol= Copy_preview= Automatically_setting_file_links= Regenerating_BibTeX_keys_according_to_metadata= -No_meta_data_present_in_BIB_file._Cannot_regenerate_BibTeX_keys= Regenerate_all_keys_for_the_entries_in_a_BibTeX_file= Show_debug_level_messages= Default_bibliography_mode= diff --git a/src/main/resources/l10n/JabRef_ru.properties b/src/main/resources/l10n/JabRef_ru.properties index cce25011c8c..4dc21eec75d 100644 --- a/src/main/resources/l10n/JabRef_ru.properties +++ b/src/main/resources/l10n/JabRef_ru.properties @@ -1,4 +1,5 @@ + #! #! created/edited by Popeye version 0.55 (github.com/JabRef/popeye) #! encoding:UTF-8 @@ -1884,7 +1885,6 @@ should_contain_a_protocol=должно_содержать_протокол Copy_preview=Копировать_предварительный_просмотр Automatically_setting_file_links=Автоуказание_ссылок_на_файлы Regenerating_BibTeX_keys_according_to_metadata=Восстановление_ключей_BibTeX_на_основе_метаданных -No_meta_data_present_in_BIB_file._Cannot_regenerate_BibTeX_keys=В_файле_BIB_отсутствуют_метаданные._Восстановление_ключей_BibTeX_невозможно. Regenerate_all_keys_for_the_entries_in_a_BibTeX_file=Восстановление_всех_ключей_для_записей_в_файле_BibTeX Show_debug_level_messages=Показать_сообщения_об_отладке Default_bibliography_mode=Режим_библиографии_по_умолчанию diff --git a/src/main/resources/l10n/JabRef_sv.properties b/src/main/resources/l10n/JabRef_sv.properties index fa21d5cb03a..4ed4d8ae862 100644 --- a/src/main/resources/l10n/JabRef_sv.properties +++ b/src/main/resources/l10n/JabRef_sv.properties @@ -1,4 +1,5 @@ + #! #! created/edited by Popeye version 0.55 (github.com/JabRef/popeye) #! encoding:UTF-8 @@ -1884,7 +1885,6 @@ should_contain_a_protocol=ska_innehålla_ett_protokoll Copy_preview=Kopiera_postvisning Automatically_setting_file_links=Skapar_fillänkar_automatiskt Regenerating_BibTeX_keys_according_to_metadata=Generera_BibTeX-nycklar_enligt_metadata -No_meta_data_present_in_BIB_file._Cannot_regenerate_BibTeX_keys= Regenerate_all_keys_for_the_entries_in_a_BibTeX_file=Generera_BibTeX-nycklar_för_alla_poster_i_en_BibTeX-fil Show_debug_level_messages=Visa_fler_felmeddelanden_för_avlusning Default_bibliography_mode=Standardläge_för_databas diff --git a/src/main/resources/l10n/JabRef_tr.properties b/src/main/resources/l10n/JabRef_tr.properties index 74e45e403db..d952ae56d60 100644 --- a/src/main/resources/l10n/JabRef_tr.properties +++ b/src/main/resources/l10n/JabRef_tr.properties @@ -1,4 +1,5 @@ + #! #! created/edited by Popeye version 0.55 (github.com/JabRef/popeye) #! encoding:UTF-8 @@ -1884,7 +1885,6 @@ should_contain_a_protocol=bir_protokol_içermeli Copy_preview=Kopyalama_önizleme Automatically_setting_file_links=Dosya_bağlantıları_otomatik_olarak_ayarlanıyor Regenerating_BibTeX_keys_according_to_metadata=Üstveri_(metadata)_uyarınca_BibTeX_anahtarları_yeniden_oluşturuluyor -No_meta_data_present_in_BIB_file._Cannot_regenerate_BibTeX_keys=Bibdosyasında_üstveri_yok._Bibtex_anahtarları_yeniden_oluşturulamıyor Regenerate_all_keys_for_the_entries_in_a_BibTeX_file=Bir_BibTeX_dosyasındaki_tüm_girdiler_için_tüm_anahtarları_yeniden_oluştur Show_debug_level_messages=Hata_ayıklama_düzeyi_mesajları_göster Default_bibliography_mode=Öntanımlı_bibliyografya_kipi diff --git a/src/main/resources/l10n/JabRef_vi.properties b/src/main/resources/l10n/JabRef_vi.properties index 7e664ca3514..01d5efa86b0 100644 --- a/src/main/resources/l10n/JabRef_vi.properties +++ b/src/main/resources/l10n/JabRef_vi.properties @@ -1,4 +1,5 @@ + #! #! created/edited by Popeye version 0.55 (github.com/JabRef/popeye) #! encoding:UTF-8 @@ -1884,7 +1885,6 @@ should_contain_a_protocol= Copy_preview= Automatically_setting_file_links=Tự_động_thiết_lập_liên_kết_với_tập_tin Regenerating_BibTeX_keys_according_to_metadata= -No_meta_data_present_in_BIB_file._Cannot_regenerate_BibTeX_keys= Regenerate_all_keys_for_the_entries_in_a_BibTeX_file= Show_debug_level_messages= Default_bibliography_mode= diff --git a/src/main/resources/l10n/JabRef_zh.properties b/src/main/resources/l10n/JabRef_zh.properties index a4d977d64ba..9305fcb552e 100644 --- a/src/main/resources/l10n/JabRef_zh.properties +++ b/src/main/resources/l10n/JabRef_zh.properties @@ -1,4 +1,5 @@ + #! #! created/edited by Popeye version 0.55 (github.com/JabRef/popeye) #! encoding:UTF-8 @@ -1884,7 +1885,6 @@ should_contain_a_protocol= Copy_preview=拷贝预览 Automatically_setting_file_links=自动设置文件链接 Regenerating_BibTeX_keys_according_to_metadata=基于_metadata_重新生成_BibTeX_键值 -No_meta_data_present_in_BIB_file._Cannot_regenerate_BibTeX_keys=在_BIB_file_中没有找到_meta_data,无法重建_BibTeX_key Regenerate_all_keys_for_the_entries_in_a_BibTeX_file=重新生成_BibTeX_文件中所有记录的键值 Show_debug_level_messages=显示调试级别消息 Default_bibliography_mode=默认的参考文献模式 diff --git a/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithDatabaseTest.java b/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithDatabaseTest.java index 37a9a5105c6..38880288509 100644 --- a/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithDatabaseTest.java +++ b/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithDatabaseTest.java @@ -206,11 +206,11 @@ public void generateKeyEmptyFieldDefaultText() { } @Test - public void generateKeyEmptyFieldColonInDefaultText() { + public void generateKeyEmptyFieldNoColonInDefaultText() { bibtexKeyPattern.setDefaultValue("[author:(Problem:No Author Provided)]"); entry.clearField("author"); new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); - assertEquals(Optional.of("Problem:NoAuthorProvided"), entry.getCiteKeyOptional()); + assertEquals(Optional.of("ProblemNoAuthorProvided"), entry.getCiteKeyOptional()); } @Test diff --git a/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithoutDatabaseTest.java b/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithoutDatabaseTest.java index 3713cf4a7cc..88af32ce21b 100644 --- a/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithoutDatabaseTest.java +++ b/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithoutDatabaseTest.java @@ -21,8 +21,7 @@ public void setUp() { @Test public void makeLabelForFileSearch() { - String label = - BibtexKeyGenerator.generateKey(entry, "auth", null); + String label = BibtexKeyGenerator.generateKey(entry, "auth"); assertEquals("Doe", label); } @@ -33,8 +32,7 @@ public void makeEditorLabelForFileSearch() { localEntry.setField("year", "2016"); localEntry.setField("title", "An awesome paper on JabRef"); - String label = - BibtexKeyGenerator.generateKey(localEntry, "auth", null); + String label = BibtexKeyGenerator.generateKey(localEntry, "auth"); assertEquals("Doe", label); } From cfb296a092076519facfd047500cfe623abbc3ac Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Sat, 23 Dec 2017 14:38:42 +0100 Subject: [PATCH 4/6] Fix localization --- src/main/resources/l10n/JabRef_de.properties | 1 - src/main/resources/l10n/JabRef_en.properties | 1 - src/main/resources/l10n/JabRef_es.properties | 1 - src/main/resources/l10n/JabRef_fr.properties | 1 - src/main/resources/l10n/JabRef_in.properties | 1 - src/main/resources/l10n/JabRef_it.properties | 1 - src/main/resources/l10n/JabRef_ja.properties | 1 - src/main/resources/l10n/JabRef_ru.properties | 1 - src/main/resources/l10n/JabRef_tr.properties | 1 - src/main/resources/l10n/JabRef_zh.properties | 1 - 10 files changed, 10 deletions(-) diff --git a/src/main/resources/l10n/JabRef_de.properties b/src/main/resources/l10n/JabRef_de.properties index 91359d83d79..f97eeb74552 100644 --- a/src/main/resources/l10n/JabRef_de.properties +++ b/src/main/resources/l10n/JabRef_de.properties @@ -1880,7 +1880,6 @@ should\ contain\ a\ protocol=sollte ein Protokoll beinhalten Copy\ preview=Kopiere Vorschau Automatically\ setting\ file\ links=Dateilinks werden automatisch gesetzt Regenerating\ BibTeX\ keys\ according\ to\ metadata=Regeneriere BibTeX-Keys anhand ihrer Metadaten -No\ meta\ data\ present\ in\ BIB\ file.\ Cannot\ regenerate\ BibTeX\ keys=Keine Metadaten in Bibdatei vorhanden. Kann keine BibTeX-Keys regenerieren Regenerate\ all\ keys\ for\ the\ entries\ in\ a\ BibTeX\ file=Regeneriere alle BibTeX-Keys für Einträge in einer BibTeX Datei Show\ debug\ level\ messages=Zeige Debug Level Meldungen Default\ bibliography\ mode=Standard Bibliographiemodus diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index abd463a6c6a..993a70c0f72 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -1879,7 +1879,6 @@ should\ contain\ a\ protocol=should contain a protocol Copy\ preview=Copy preview Automatically\ setting\ file\ links=Automatically setting file links Regenerating\ BibTeX\ keys\ according\ to\ metadata=Regenerating BibTeX keys according to metadata -No\ meta\ data\ present\ in\ BIB\ file.\ Cannot\ regenerate\ BibTeX\ keys=No meta data present in BIB file. Cannot regenerate BibTeX keys Regenerate\ all\ keys\ for\ the\ entries\ in\ a\ BibTeX\ file=Regenerate all keys for the entries in a BibTeX file Show\ debug\ level\ messages=Show debug level messages Default\ bibliography\ mode=Default bibliography mode diff --git a/src/main/resources/l10n/JabRef_es.properties b/src/main/resources/l10n/JabRef_es.properties index be3f7315ecd..f138942c45d 100644 --- a/src/main/resources/l10n/JabRef_es.properties +++ b/src/main/resources/l10n/JabRef_es.properties @@ -1865,7 +1865,6 @@ should\ contain\ a\ protocol=Debería contener un protocolo Copy\ preview=Copiar vista previa Automatically\ setting\ file\ links=Estableciendo automáticamente enlaces de archivo Regenerating\ BibTeX\ keys\ according\ to\ metadata=Regenerando claves BibTeX de acuerdo a los metadatos -No\ meta\ data\ present\ in\ BIB\ file.\ Cannot\ regenerate\ BibTeX\ keys=No hay metadatos en el BIB file. No se pueden regenerar las claves BibTex Regenerate\ all\ keys\ for\ the\ entries\ in\ a\ BibTeX\ file=Regenerar todas las claves para las entradas de un archivo BibTeX Show\ debug\ level\ messages=Mostrar mensajes de nivel de depuración Default\ bibliography\ mode=Modo de bibliografía por defecto diff --git a/src/main/resources/l10n/JabRef_fr.properties b/src/main/resources/l10n/JabRef_fr.properties index ed850e539f9..bba55114d5b 100644 --- a/src/main/resources/l10n/JabRef_fr.properties +++ b/src/main/resources/l10n/JabRef_fr.properties @@ -1880,7 +1880,6 @@ should\ contain\ a\ protocol=doit contenir un protocole Copy\ preview=Copier la prévisualisation Automatically\ setting\ file\ links=Définition automatique des liens de fichier Regenerating\ BibTeX\ keys\ according\ to\ metadata=Régénération des clefs BibTeX à partir des métadonnées -No\ meta\ data\ present\ in\ BIB\ file.\ Cannot\ regenerate\ BibTeX\ keys=Aucune métadonnée dans le fichier BibTeX. Les clefs n'ont pas pu être régénérées Regenerate\ all\ keys\ for\ the\ entries\ in\ a\ BibTeX\ file=Régénére toutes les clefs pour les entrées d'un fichier BibTeX Show\ debug\ level\ messages=Afficher les messages de débogage Default\ bibliography\ mode=Mode bibliographique par défaut diff --git a/src/main/resources/l10n/JabRef_in.properties b/src/main/resources/l10n/JabRef_in.properties index 93acd521800..fd1f08a62ce 100644 --- a/src/main/resources/l10n/JabRef_in.properties +++ b/src/main/resources/l10n/JabRef_in.properties @@ -1879,7 +1879,6 @@ should\ contain\ a\ protocol=harus berisi sebuah protokol Copy\ preview=Tinjauan Salinan Automatically\ setting\ file\ links=Pengaturan link file secara otomatis Regenerating\ BibTeX\ keys\ according\ to\ metadata=Regenerasi BibTeX kunci menurut metadata -No\ meta\ data\ present\ in\ BIB\ file.\ Cannot\ regenerate\ BibTeX\ keys=Data meta terdapat dalam BIB file. Tidak dapat meregenerasi kunci BibTeX Regenerate\ all\ keys\ for\ the\ entries\ in\ a\ BibTeX\ file=Regenerasi semua kunci pada entri di BibTeX file Show\ debug\ level\ messages=Tampilkan pesan debug Default\ bibliography\ mode=Mode bibliografi bawaan diff --git a/src/main/resources/l10n/JabRef_it.properties b/src/main/resources/l10n/JabRef_it.properties index 8c7d0a7fc45..61e330c7d9f 100644 --- a/src/main/resources/l10n/JabRef_it.properties +++ b/src/main/resources/l10n/JabRef_it.properties @@ -1867,7 +1867,6 @@ should\ contain\ a\ protocol=deve contenere un protocollo Copy\ preview=Copia l'anteprima Automatically\ setting\ file\ links=Seleziona automaticamente i collegamenti ai file Regenerating\ BibTeX\ keys\ according\ to\ metadata=Rigenera le chiavi BibTeX secondo i metadati -No\ meta\ data\ present\ in\ BIB\ file.\ Cannot\ regenerate\ BibTeX\ keys=Non ci sono meta nel fil BIB. Non posso rigenerare le chiavi BibTeX Regenerate\ all\ keys\ for\ the\ entries\ in\ a\ BibTeX\ file=Rigenera tutte le chiavi per i campi di un file BibTeX Show\ debug\ level\ messages=Mostra i messaggi del livello di debug Default\ bibliography\ mode=Modalità bibliografica predefinita diff --git a/src/main/resources/l10n/JabRef_ja.properties b/src/main/resources/l10n/JabRef_ja.properties index d4174f6d69d..5e86b82b667 100644 --- a/src/main/resources/l10n/JabRef_ja.properties +++ b/src/main/resources/l10n/JabRef_ja.properties @@ -1878,7 +1878,6 @@ should\ contain\ a\ protocol=プロトコルを含む必要あり Copy\ preview=プレビューをコピー Automatically\ setting\ file\ links=ファイルリンクを自動的に設定 Regenerating\ BibTeX\ keys\ according\ to\ metadata=メタデータにしたがってBibTeX鍵を再生成 -No\ meta\ data\ present\ in\ BIB\ file.\ Cannot\ regenerate\ BibTeX\ keys=bibファイルにメタデータがありません.BibTeX鍵を再生成することができません Regenerate\ all\ keys\ for\ the\ entries\ in\ a\ BibTeX\ file=BibTeXファイル中全項目の鍵を再生成 Show\ debug\ level\ messages=デバッグレベルメッセージを表示 Default\ bibliography\ mode=既定の書誌情報モード diff --git a/src/main/resources/l10n/JabRef_ru.properties b/src/main/resources/l10n/JabRef_ru.properties index 095f1ee3adb..d2a2a3ce8f1 100644 --- a/src/main/resources/l10n/JabRef_ru.properties +++ b/src/main/resources/l10n/JabRef_ru.properties @@ -1837,7 +1837,6 @@ should\ contain\ a\ protocol=должно содержать протокол Copy\ preview=Копировать предварительный просмотр Automatically\ setting\ file\ links=Автоуказание ссылок на файлы Regenerating\ BibTeX\ keys\ according\ to\ metadata=Восстановление ключей BibTeX на основе метаданных -No\ meta\ data\ present\ in\ BIB\ file.\ Cannot\ regenerate\ BibTeX\ keys=В файле BIB отсутствуют метаданные. Восстановление ключей BibTeX невозможно. Regenerate\ all\ keys\ for\ the\ entries\ in\ a\ BibTeX\ file=Восстановление всех ключей для записей в файле BibTeX Show\ debug\ level\ messages=Показать сообщения об отладке Default\ bibliography\ mode=Режим библиографии по умолчанию diff --git a/src/main/resources/l10n/JabRef_tr.properties b/src/main/resources/l10n/JabRef_tr.properties index 674cef91308..81ea10fe11e 100644 --- a/src/main/resources/l10n/JabRef_tr.properties +++ b/src/main/resources/l10n/JabRef_tr.properties @@ -1875,7 +1875,6 @@ should\ contain\ a\ protocol=bir protokol içermeli Copy\ preview=Kopyalama önizleme Automatically\ setting\ file\ links=Dosya bağlantıları otomatik olarak ayarlanıyor Regenerating\ BibTeX\ keys\ according\ to\ metadata=Üstveri (metadata) uyarınca BibTeX anahtarları yeniden oluşturuluyor -No\ meta\ data\ present\ in\ BIB\ file.\ Cannot\ regenerate\ BibTeX\ keys=Bibdosyasında üstveri yok. Bibtex anahtarları yeniden oluşturulamıyor Regenerate\ all\ keys\ for\ the\ entries\ in\ a\ BibTeX\ file=Bir BibTeX dosyasındaki tüm girdiler için tüm anahtarları yeniden oluştur Show\ debug\ level\ messages=Hata ayıklama düzeyi mesajları göster Default\ bibliography\ mode=Öntanımlı bibliyografya kipi diff --git a/src/main/resources/l10n/JabRef_zh.properties b/src/main/resources/l10n/JabRef_zh.properties index ffc4b7ebf81..fa31bc3527d 100644 --- a/src/main/resources/l10n/JabRef_zh.properties +++ b/src/main/resources/l10n/JabRef_zh.properties @@ -1762,7 +1762,6 @@ Unabbreviate=展开缩写 Copy\ preview=拷贝预览 Automatically\ setting\ file\ links=自动设置文件链接 Regenerating\ BibTeX\ keys\ according\ to\ metadata=基于 metadata 重新生成 BibTeX 键值 -No\ meta\ data\ present\ in\ BIB\ file.\ Cannot\ regenerate\ BibTeX\ keys=在 BIB file 中没有找到 meta data,无法重建 BibTeX key Regenerate\ all\ keys\ for\ the\ entries\ in\ a\ BibTeX\ file=重新生成 BibTeX 文件中所有记录的键值 Show\ debug\ level\ messages=显示调试级别消息 Default\ bibliography\ mode=默认的参考文献模式 From fbde491f2f92331084705e9001ff83d795e9bb08 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Sat, 23 Dec 2017 20:57:34 +0100 Subject: [PATCH 5/6] Fix build after merge --- .../org/jabref/logic/bibtexkeypattern/BibtexKeyGenerator.java | 2 +- .../java/org/jabref/logic/util/io/CiteKeyBasedFileFinder.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGenerator.java b/src/main/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGenerator.java index 3ee8bf7e131..32dd5fe0da1 100644 --- a/src/main/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGenerator.java +++ b/src/main/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGenerator.java @@ -28,7 +28,7 @@ public class BibtexKeyGenerator extends BracketedPattern { /* * All single characters that we can use for extending a key to make it unique. */ - private static final String APPENDIX_CHARACTERS = "abcdefghijklmnopqrstuvwxyz"; + public static final String APPENDIX_CHARACTERS = "abcdefghijklmnopqrstuvwxyz"; private static final String KEY_ILLEGAL_CHARACTERS = "{}(),\\\"#~^':`"; private static final String KEY_UNWANTED_CHARACTERS = "{}(),\\\""; private final AbstractBibtexKeyPattern citeKeyPattern; diff --git a/src/main/java/org/jabref/logic/util/io/CiteKeyBasedFileFinder.java b/src/main/java/org/jabref/logic/util/io/CiteKeyBasedFileFinder.java index c00caa994d5..1486f4537c9 100644 --- a/src/main/java/org/jabref/logic/util/io/CiteKeyBasedFileFinder.java +++ b/src/main/java/org/jabref/logic/util/io/CiteKeyBasedFileFinder.java @@ -15,7 +15,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; +import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator; import org.jabref.model.entry.BibEntry; import org.jabref.model.strings.StringUtil; import org.jabref.model.util.FileHelper; @@ -73,7 +73,7 @@ private boolean matches(String filename, String citeKey) { // The file name starts with the key, that's already a good start // However, we do not want to match "JabRefa" for "JabRef" since this is probably a file belonging to another entry published in the same time / same name char charAfterKey = filename.charAt(citeKey.length()); - return !BibtexKeyPatternUtil.CHARS.contains(Character.toString(charAfterKey)); + return !BibtexKeyGenerator.APPENDIX_CHARACTERS.contains(Character.toString(charAfterKey)); } return false; } From 55e071b0c4eb76a9e205504a317669c407e1270b Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Tue, 2 Jan 2018 21:08:57 +0100 Subject: [PATCH 6/6] Merge --- .../org/jabref/gui/entryeditor/EntryEditor.java | 7 +++---- .../fieldeditors/BibtexKeyEditorViewModel.java | 14 ++++---------- .../bibtexkeypattern/BibtexKeyGenerator.java | 16 +--------------- .../logic/integrity/ValidBibtexKeyChecker.java | 6 +++--- 4 files changed, 11 insertions(+), 32 deletions(-) diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index 3bfc5967dd3..7330ec7f969 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -53,7 +53,9 @@ public class EntryEditor extends BorderPane { private final BibDatabaseContext bibDatabaseContext; private final CountingUndoManager undoManager; - + private final BasePanel panel; + private final List searchListeners = new ArrayList<>(); + private final List tabs; /** * A reference to the entry this editor works on. */ @@ -61,9 +63,6 @@ public class EntryEditor extends BorderPane { @FXML private TabPane tabbed; @FXML private Button typeChangeButton; @FXML private Button fetcherButton; - private final BasePanel panel; - private final List searchListeners = new ArrayList<>(); - private final List tabs; private SourceTab sourceTab; @FXML private Label typeLabel; diff --git a/src/main/java/org/jabref/gui/fieldeditors/BibtexKeyEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/BibtexKeyEditorViewModel.java index f8d6d140a89..8c7147f81d0 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/BibtexKeyEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/BibtexKeyEditorViewModel.java @@ -1,15 +1,12 @@ package org.jabref.gui.fieldeditors; -import java.util.Optional; - import javax.swing.undo.UndoManager; import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider; import org.jabref.gui.undo.UndoableKeyChange; +import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator; import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences; -import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; import org.jabref.logic.integrity.FieldCheckers; -import org.jabref.model.FieldChange; import org.jabref.model.database.BibDatabaseContext; public class BibtexKeyEditorViewModel extends AbstractEditorViewModel { @@ -25,11 +22,8 @@ public BibtexKeyEditorViewModel(String fieldName, AutoCompleteSuggestionProvider } public void generateKey() { - Optional fieldChange = BibtexKeyPatternUtil.makeAndSetLabel( - bibDatabaseContext.getMetaData().getCiteKeyPattern(keyPatternPreferences.getKeyPattern()), - bibDatabaseContext.getDatabase(), - entry, - keyPatternPreferences); - fieldChange.ifPresent(change -> undoManager.addEdit(new UndoableKeyChange(change))); + new BibtexKeyGenerator(bibDatabaseContext, keyPatternPreferences) + .generateAndSetKey(entry) + .ifPresent(change -> undoManager.addEdit(new UndoableKeyChange(change))); } } diff --git a/src/main/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGenerator.java b/src/main/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGenerator.java index db56c589d1d..c541b285330 100644 --- a/src/main/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGenerator.java +++ b/src/main/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGenerator.java @@ -23,12 +23,11 @@ * This is the utility class of the LabelPattern package. */ public class BibtexKeyGenerator extends BracketedPattern { - private static final Log LOGGER = LogFactory.getLog(BibtexKeyGenerator.class); - /* * All single characters that we can use for extending a key to make it unique. */ public static final String APPENDIX_CHARACTERS = "abcdefghijklmnopqrstuvwxyz"; + private static final Log LOGGER = LogFactory.getLog(BibtexKeyGenerator.class); private static final String KEY_ILLEGAL_CHARACTERS = "{}(),\\\"#~^':`"; private static final String KEY_UNWANTED_CHARACTERS = "{}(),\\\""; private final AbstractBibtexKeyPattern citeKeyPattern; @@ -75,19 +74,6 @@ private static String getAppendix(int number) { } } - /** - * This method returns a String similar to the one passed in, except that it is molded into a form that is - * acceptable for bibtex. - *

- * Watch-out that the returned string might be of length 0 afterwards. - * - * @param key the key to clean - * @param enforceLegalKey make sure that the key is legal in all respects - */ - public static Optional makeAndSetLabel(AbstractBibtexKeyPattern citeKeyPattern, BibDatabase database, BibEntry entry, - return entry.setCiteKey(newKey); - } - public static String cleanKey(String key, boolean enforceLegalKey) { if (!enforceLegalKey) { // User doesn't want us to enforce legal characters. We must still look diff --git a/src/main/java/org/jabref/logic/integrity/ValidBibtexKeyChecker.java b/src/main/java/org/jabref/logic/integrity/ValidBibtexKeyChecker.java index 63710c4893c..7d9456773f8 100644 --- a/src/main/java/org/jabref/logic/integrity/ValidBibtexKeyChecker.java +++ b/src/main/java/org/jabref/logic/integrity/ValidBibtexKeyChecker.java @@ -2,7 +2,7 @@ import java.util.Optional; -import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; +import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator; import org.jabref.logic.l10n.Localization; /** @@ -18,8 +18,8 @@ public ValidBibtexKeyChecker(boolean enforceLegalKey) { @Override public Optional checkValue(String value) { - String cleaned = BibtexKeyPatternUtil.checkLegalKey(value, enforceLegalKey); - if ((cleaned == null) || cleaned.equals(value)) { + String cleaned = BibtexKeyGenerator.cleanKey(value, enforceLegalKey); + if (cleaned.equals(value)) { return Optional.empty(); } else { return Optional.of(Localization.lang("Invalid BibTeX key"));