Top Description Fields Constructors Methods
org.jabref.logic.citationkeypattern

public Class CitationKeyGenerator

extends BracketedPattern
Class Inheritance
Imports
java.util.Arrays, .List, .Objects, .Optional, java.util.function.Function, java.util.regex.PatternSyntaxException, org.jabref.model.FieldChange, org.jabref.model.database.BibDatabase, .BibDatabaseContext, org.jabref.model.entry.BibEntry, org.jabref.model.entry.types.EntryType, org.jabref.model.strings.StringUtil, org.slf4j.Logger, .LoggerFactory

This is the utility class of the LabelPattern package.

Field Summary

Modifier and TypeField and Description
public static final String
APPENDIX_CHARACTERS

All single characters that we can use for extending a key to make it unique.

private final CitationKeyPatternPreferences
private final AbstractCitationKeyPatterns
private final BibDatabase
public static final String
DEFAULT_UNWANTED_CHARACTERS

List of unwanted characters.

private static final List<Character>
private static final Logger
private final String

Constructor Summary

AccessConstructor and Description
public
CitationKeyGenerator(BibDatabaseContext bibDatabaseContext, CitationKeyPatternPreferences citationKeyPatternPreferences)

public
CitationKeyGenerator(AbstractCitationKeyPatterns citeKeyPattern, BibDatabase database, CitationKeyPatternPreferences citationKeyPatternPreferences)

Method Summary

Modifier and TypeMethod and Description
private String

Returns:

a key, if needed, with an appended letter
appendLettersToKey
(String
the new key
key
,
String
the old key
oldKey
)

A letter will be appended to the key based on the user's preferences, either always or to prevent duplicated keys.

public static String
cleanKey(String key, String unwantedCharacters)

private String
private Function<String, String>

Returns:

a cleaned citation key for the given BibEntry
expandBracketContent
(BibEntry
the BibEntry that a citation key is generated for
entry
)

A helper method to create a Function that takes a single bracketed expression, expands it, and cleans the key.

public Optional<FieldChange>

Returns:

the change to the key (or an empty optional if the key was not changed)
generateAndSetKey
(BibEntry
the entry to generate the key for
entry
)

Generates a citation key for the given entry, and sets the key.

public String

Returns:

a citation key based on the user's preferences
generateKey
(BibEntry entry)

Generate a citation key for the given BibEntry.

private static String

Returns:

The String to append.
getAppendix
(int
The appendix number.
number
)

Computes an appendix to a citation key that could make it unique.

public static String
public static String
removeUnwantedCharacters(String key, String unwantedCharacters)

private String

Returns:

the citation key where matches to the regex are replaced
replaceWithRegex
(String
the citation key
key
)

Using preferences, replace matches to the provided regex with a string.

Inherited from org.jabref.logic.citationkeypattern.BracketedPattern:
allAuthorsapplyModifiersauthAuthEaauthEtalauthIniNauthorsAlphaauthShortcamelizeSignificantWordsInTitleexpandexpandexpandexpandBracketContentexpandBracketsexpandBracketsfirstPagegetCamelizedTitlegetCamelizedTitle_NgetFieldValuegetTitleWordslastPageoneAuthorPlusInitialspagePrefixparseFieldAndModifiersremoveSmallWordstoString

Field Detail

APPENDIX_CHARACTERSback to summary
public static final String APPENDIX_CHARACTERS

All single characters that we can use for extending a key to make it unique.

citationKeyPatternPreferencesback to summary
private final CitationKeyPatternPreferences citationKeyPatternPreferences
citeKeyPatternback to summary
private final AbstractCitationKeyPatterns citeKeyPattern
databaseback to summary
private final BibDatabase database
DEFAULT_UNWANTED_CHARACTERSback to summary
public static final String DEFAULT_UNWANTED_CHARACTERS

List of unwanted characters. These will be removed at the end. Note that + is a wanted character to indicate "et al." in authorsAlpha. Example: "ABC+". See org.jabref.logic.citationkeypattern.BracketedPatternTest#authorsAlpha() for examples.

DISALLOWED_CHARACTERSback to summary
private static final List<Character> DISALLOWED_CHARACTERS
LOGGERback to summary
private static final Logger LOGGER

Hides org.jabref.logic.citationkeypattern.BracketedPattern.LOGGER.

unwantedCharactersback to summary
private final String unwantedCharacters

Constructor Detail

CitationKeyGeneratorback to summary
public CitationKeyGenerator(BibDatabaseContext bibDatabaseContext, CitationKeyPatternPreferences citationKeyPatternPreferences)
CitationKeyGeneratorback to summary
public CitationKeyGenerator(AbstractCitationKeyPatterns citeKeyPattern, BibDatabase database, CitationKeyPatternPreferences citationKeyPatternPreferences)

Method Detail

appendLettersToKeyback to summary
private String appendLettersToKey(String key, String oldKey)

A letter will be appended to the key based on the user's preferences, either always or to prevent duplicated keys.

Parameters
key:String

the new key

oldKey:String

the old key

Returns:String

a key, if needed, with an appended letter

cleanKeyback to summary
public static String cleanKey(String key, String unwantedCharacters)
createCitationKeyFromPatternback to summary
private String createCitationKeyFromPattern(BibEntry entry)
expandBracketContentback to summary
private Function<String, String> expandBracketContent(BibEntry entry)

A helper method to create a Function that takes a single bracketed expression, expands it, and cleans the key.

Parameters
entry:BibEntry

the BibEntry that a citation key is generated for

Returns:Function<String, String>

a cleaned citation key for the given BibEntry

generateAndSetKeyback to summary
public Optional<FieldChange> generateAndSetKey(BibEntry entry)

Generates a citation key for the given entry, and sets the key.

Parameters
entry:BibEntry

the entry to generate the key for

Returns:Optional<FieldChange>

the change to the key (or an empty optional if the key was not changed)

generateKeyback to summary
public String generateKey(BibEntry entry)

Generate a citation key for the given BibEntry.

Parameters
entry:BibEntry

a BibEntry

Returns:String

a citation key based on the user's preferences

getAppendixback to summary
private static String getAppendix(int number)

Computes an appendix to a citation key that could make it unique. We use a-z for numbers 0-25, and then aa-az, ba-bz, etc.

Parameters
number:int

The appendix number.

Returns:String

The String to append.

removeDefaultUnwantedCharactersback to summary
public static String removeDefaultUnwantedCharacters(String key)
removeUnwantedCharactersback to summary
public static String removeUnwantedCharacters(String key, String unwantedCharacters)
replaceWithRegexback to summary
private String replaceWithRegex(String key)

Using preferences, replace matches to the provided regex with a string.

Parameters
key:String

the citation key

Returns:String

the citation key where matches to the regex are replaced