Verified Owner
Top Description Fields Constructors Methods
org.jabref.model.entry

public Class BibEntry

extends Object
Class Inheritance
Annotations
@AllowedToUseLogic:because it needs access to parser and writers
Imports
java.io.IOException, .StringWriter, java.util.ArrayList, .Arrays, .Collection, .Comparator, .HashMap, .HashSet, .LinkedHashSet, .List, .Map, .Objects, .Optional, .SequencedSet, .Set, .TreeSet, java.util.concurrent.ConcurrentHashMap, java.util.function.BiFunction, .Predicate, java.util.stream.Collectors, javafx.beans.Observable, javafx.beans.property.ObjectProperty, .SimpleObjectProperty, javafx.collections.FXCollections, .ObservableMap, org.jabref.architecture.AllowedToUseLogic, org.jabref.logic.bibtex.BibEntryWriter, .FieldPreferences, .FieldWriter, .FileFieldWriter, org.jabref.logic.exporter.BibWriter, org.jabref.logic.importer.util.FileFieldParser, org.jabref.logic.util.strings.StringUtil, org.jabref.model.FieldChange, org.jabref.model.database.BibDatabase, .BibDatabaseMode, org.jabref.model.entry.event.EntriesEventSource, .FieldAddedOrRemovedEvent, .FieldChangedEvent, org.jabref.model.entry.field.Field, .InternalField, .OrFields, .StandardField, org.jabref.model.entry.identifier.DOI, .ISBN, org.jabref.model.entry.types.EntryType, .IEEETranEntryType, .StandardEntryType, org.jabref.model.strings.LatexToUnicodeAdapter, org.jabref.model.util.MultiKeyMap, com.google.common.annotations.VisibleForTesting, com.google.common.eventbus.EventBus, com.tobiasdiez.easybind.EasyBind, com.tobiasdiez.easybind.optional.OptionalBinding, org.jspecify.annotations.NonNull, .Nullable, org.slf4j.Logger, .LoggerFactory

Represents a Bib(La)TeX entry, which can be BibTeX or BibLaTeX.

Example:

Some comment
Some comment

Field Summary

Modifier and TypeField and Description
private boolean
changed

Marks whether the complete serialization, which was read from file, should be used.

private String
commentsBeforeEntry

The part before the start of the entry

public static final EntryType
public static final String
private final EventBus
private ObservableMap<Field, String>
private final MultiKeyMap<StandardField, Character, KeywordList>
fieldsAsKeywords

Cache that stores the field as keyword lists (format <Field, Separator, Keyword list>)

private final Map<Field, Set<String>>
fieldsAsWords

Map to store the words in every field

private String
private final Map<Field, String>
latexFreeFields

Cache that stores latex free versions of fields.

private static final Logger
private String
parsedSerialization

Stores the text "rendering" of the entry as read by the BibTeX reader.

private final SharedBibEntryData
private final ObjectProperty<EntryType>

Constructor Summary

AccessConstructor and Description
public
BibEntry()

Constructs a new BibEntry.

public
BibEntry(String citationKey)

public
BibEntry(EntryType type)

Constructs a new BibEntry.

public
BibEntry(EntryType type, String citationKey)

public
BibEntry(BibEntry other)

Returns a copy of this entry.

Method Summary

Modifier and TypeMethod and Description
public Optional<FieldChange>
public Optional<FieldChange>
addFile(int index, LinkedFile file)

public Optional<FieldChange>
addFiles(List<LinkedFile> filesToAdd)

public void
addKeyword(@NonNull String
Keyword to add
keyword
,
Character delimiter)

Check if a keyword already exists (case insensitive), if not: add it

public void
addKeyword(Keyword keyword, Character delimiter)

public void
addKeywords(@NonNull Collection<String>
Keywords to add
keywords
,
Character delimiter)

Add multiple keywords to entry

public boolean

Returns:

true if all fields are set or could be resolved, false otherwise.
allFieldsPresent
(Collection<OrFields>
An array of field names to be checked.
fields
,
BibDatabase
The database in which to look up crossref'd entries, if any. This argument can be null, meaning that no attempt will be made to follow crossrefs.
database
)

Determines whether this entry has all the given fields present.

public Optional<FieldChange>
public Optional<FieldChange>
clearField(Field
The field to clear.
field
)

Remove the mapping for the field name, and notify listeners about the change.

public Optional<FieldChange>
clearField(Field
the field to clear.
field
,
EntriesEventSource
the source a new FieldChangedEvent should be posten from.
eventSource
)

Remove the mapping for the field name, and notify listeners about the change including the EntriesEventSource.

public boolean
equals(Object o)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

private Optional<String>

Returns:

determined field value
genericGetFieldOrAlias
(Field
the field
field
,
BiFunction<BibEntry, Field, Optional<String>>
the method to get the value of a given field in a given entry
getFieldValue
)

Internal method used to get the content of a field (or its alias)

Used by getFieldOrAlias(Field) and getFieldOrAliasLatexFree(Field)

private Optional<String>
public String
public String

Returns:

A short textual description of the entry in the format: Author1, Author2: Title (Year)
getAuthorTitleYear
(int
The maximum number of characters (additional characters are replaced by "..."). Set to 0 to disable truncation.
maxCharacters
)

Creates a short textual description of the entry in the format: Author1, Author2: Title (Year)

If 0 is passed as maxCharacters, the description is not truncated.

public @NonNull Optional<String>
getCitationKey()

If not present, BibEntry#getAuthorTitleYear(int) can be used

public com.tobiasdiez.easybind.optional.OptionalBinding<String>
public SequencedSet<String>

Returns:

List of citation keys; empty list if field is empty or not available.
getCites
()

Checks StandardField#CITES for a list of citation keys and returns them.

public Optional<DOI>
public Optional<String>
getField(Field field)

Returns the contents of the given field as an Optional.

public KeywordList
getFieldAsKeywords(Field field, Character keywordSeparator)

public Set<String>
public com.tobiasdiez.easybind.optional.OptionalBinding<String>
public Optional<String>
public Map<Field, String>
public Optional<String>
getFieldOrAlias(Field field)

Returns the contents of the given field or its alias as an Optional

The following aliases are considered (old bibtex <-> new biblatex) based on the biblatex documentation, chapter 2.2.5:

  • address <-> location
  • annote <-> annotation
  • archiveprefix <-> eprinttype
  • journal <-> journaltitle
  • key <-> sortkey
  • pdf <-> file
  • primaryclass <-> eprintclass
  • school <-> institution
public Optional<String>

Returns:

the stored latex-free content of the field (or its alias)
getFieldOrAliasLatexFree
(Field
the name of the field
name
)

Return the LaTeX-free contents of the given field or its alias an Optional

For details see also getFieldOrAlias(Field)

public SequencedSet<Field>
getFields()

Returns an unmodifiable sequence containing the names of all fields that are set for this particular entry.

public SequencedSet<Field>
getFields(Predicate<Field> selector)

Returns an unmodifiable sequence containing the names of all fields that are a) set for this particular entry and b) matching the given predicate

public ObservableMap<Field, String>
public Collection<String>
public List<LinkedFile>

Returns:

the list of linked files, is never null but can be empty. Changes to the underlying list will have no effect on the entry itself. Use addFile(LinkedFile).
getFiles
()

Gets a list of linked files.

public String
getId()

This id changes on each run of JabRef (because it is currently generated as increasing number).

public Optional<ISBN>
public String
public String
getKeyAuthorTitleYear(int maxCharacters)

public KeywordList
public Optional<Month>
public Observable[]
getObservables()

Returns a list of observables that represent the data of the entry.

public String
public Optional<Date>

Returns:

will return the publication date of the entry or null if no year was found.
getPublicationDate
()

Will return the publication date of the given bibtex entry conforming to ISO 8601, i.e. either YYYY or YYYY-MM.

public Optional<String>
public Optional<String>

Returns:

The resolved field value or null if not found.
getResolvedFieldOrAlias
(Field
The field to return the value of.
field
,
@Nullable BibDatabase
The database of the bibtex entry.
database
)

Returns the text stored in the given field of the given bibtex entry which belongs to the given database.

public Optional<String>
public KeywordList
public SharedBibEntryData
private Optional<Field>

Returns:

the mapped field or null if there is no valid mapping available
getSourceField
(Field
field name of the BibEntry
targetField
,
EntryType
type of the BibEntry
targetEntry
,
EntryType
type of the cross-referenced BibEntry
sourceEntry
)

Map an (empty) field of a BibEntry to a field of a cross-referenced entry.

public @NonNull String

Returns:

String representation - empty string in case of an error (to ease calling)
getStringRepresentation
(BibEntry entry, BibDatabaseMode type, BibEntryTypesManager entryTypesManager, FieldPreferences fieldPreferences)

Uses \n as newline separator

Method similar to org.jabref.gui.entryeditor.SourceTab#getSourceString(BibEntry, BibDatabaseMode, FieldPreferences)

public Optional<String>

Returns:

an Optional containing the title of a BibTeX entry in case it exists, otherwise return an empty Optional.
getTitle
()

Returns the title of the given BibTeX entry as an Optional.

public EntryType
getType()

Returns this entry's type.

public String
public Optional<Season>
public boolean
public boolean
public boolean
hasField(Field field)

Returns true if the entry has the given field, or false if it is not set.

public Boolean

Returns:

true if the entry contains the file
hasFile
(LinkedFile
the file that is checked if it's in the entry or not
file
)

Checks if the BibEntry contains the linked file

public int
hashCode()

Overrides java.lang.Object.hashCode.

On purpose, this hashes the "content" of the BibEntry, not the sharedBibEntryData.

private void
public boolean
public void
mergeWith(BibEntry
another BibEntry from which fields are sourced from
other
)

Merge this entry's fields with another BibEntry.

public void
mergeWith(BibEntry
another BibEntry from which fields are sourced from
other
,
Set<Field>
collection of Fields in which 'other' has a priority into final result
otherPrioritizedFields
)

Merge this entry's fields with another BibEntry.

public Optional<FieldChange>
putKeywords(List<String> keywords, @NonNull Character delimiter)

public Optional<FieldChange>
public void
public Optional<FieldChange>
removeKeywords(KeywordList keywordsToRemove, Character keywordDelimiter)

public void
replaceDownloadedFile(String
the link to the file, which was downloaded
linkToDownloadedFile
,
LinkedFile
the path to be added to the entry
downloadedFile
)

Helper method to add a downloaded file to the entry.

public Optional<FieldChange>
replaceKeywords(KeywordList keywordsToReplace, Keyword newValue, Character keywordDelimiter)

public void
setChanged(boolean changed)

public Optional<FieldChange>
setCitationKey(String
The cite key to set. Must not be null; use clearCitationKey() to remove the cite key.
newKey
)

Sets the citation key.

public Optional<FieldChange>
public void
public void
setDate(Date date)

public void
setField(@NonNull Map<Field, String> fields)

Sets a number of fields simultaneously.

public Optional<FieldChange>
setField(@NonNull Field
The field to set
field
,
@Nullable String
The value to set - "null" for clear. Useful for cleaner code at fetchers.
value
,
@NonNull EntriesEventSource
Source the event is sent from
eventSource
)

Set a field, and notify listeners about the change.

public Optional<FieldChange>
setField(Field
The field to set.
field
,
@Nullable String
The value to set - "null" for clear. Useful for cleaner code at fetchers.
value
)

Set a field, and notify listeners about the change.

public Optional<FieldChange>
public void
setId(@NonNull String
The ID to be used
id
)

Sets this entry's identifier (ID).

public Optional<FieldChange>
setLangid(Langid parsedLangid)

public Optional<FieldChange>
setMonth(Month parsedMonth)

public void
setParsedSerialization(String parsedSerialization)

public Optional<FieldChange>
setType(EntryType type)

Sets this entry's type.

public Optional<FieldChange>
setType(@NonNull EntryType newType, EntriesEventSource eventSource)

Sets this entry's type and sets the changed flag to true

If the new entry type equals the old entry type no changed flag is set.

public String

Returns:

A user-readable string NOT A VALID BibTeX string
toString
()

Overrides java.lang.Object.toString.

Serializes all fields, even the JabRef internal ones.

public void
trimLeft()

Trims whitespaces at the beginning of the BibEntry

public ObjectProperty<EntryType>
public void
public BibEntry
withChanged(boolean changed)

Required to trigger new serialization of the entry.

public BibEntry
public BibEntry
withDate(Date date)

public BibEntry
withField(Field field, String value)

public BibEntry
withFields(Map<Field, String> content)

A copy is made of the parameter

public BibEntry
public BibEntry
withMonth(Month parsedMonth)

public BibEntry
withUserComments(String commentsBeforeEntry)

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait