Top Description Fields Constructors Methods
org.jabref.model.database

public Class BibDatabase

extends Object
Class Inheritance
Imports
java.math.BigInteger, java.security.SecureRandom, java.util.ArrayList, .Arrays, .Collection, .Collections, .Comparator, .HashMap, .HashSet, .List, .Map, .Objects, .Optional, .Set, .TreeSet, java.util.concurrent.ConcurrentHashMap, java.util.regex.Pattern, java.util.stream.Collectors, javafx.collections.FXCollections, .ObservableList, org.jabref.logic.bibtex.FieldWriter, org.jabref.model.database.event.EntriesAddedEvent, .EntriesRemovedEvent, org.jabref.model.entry.BibEntry, .BibtexString, .Month, org.jabref.model.entry.event.EntriesEventSource, .EntryChangedEvent, .FieldChangedEvent, org.jabref.model.entry.field.Field, .FieldFactory, .StandardField, org.jabref.model.strings.StringUtil, com.google.common.eventbus.EventBus, .Subscribe, org.slf4j.Logger, .LoggerFactory

A bibliography database. This is the "bib" file (or the library stored in a shared SQL database)

Field Summary

Modifier and TypeField and Description
private Map<String, BibtexString>
private final ObservableList<BibEntry>
entries

State attributes

private final Map<String, BibEntry>
private String
private final EventBus
private static final Logger
private String
private String
private static final Pattern
private String

Constructor Summary

AccessConstructor and Description
public
BibDatabase(List<BibEntry> entries, String newLineSeparator)

public
public

Method Summary

Modifier and TypeMethod and Description
public synchronized void
addString(BibtexString string)

Inserts a Bibtex String.

public void
public boolean
containsEntryWithId(String id)

Returns whether an entry with the given ID exists (-> entry_type + hashcode).

public void
copyPreamble(BibDatabase
another BibDatabase
database
)

Copies the preamble of another BibDatabase.

public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

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

public String

Returns:

The generated sharedDatabaseID
generateSharedDatabaseID
()

Generates and sets a random ID which is globally unique.

public Set<Field>

Returns:

set of fieldnames, that are visible
getAllVisibleFields
()

Returns a set of Strings, that contains all field names that are visible.

public ObservableList<BibEntry>
public synchronized List<BibEntry>

Returns:

list of entries that contains the given key
getEntriesByCitationKey
(String key)

Collects entries having the specified citation key and returns these entries as list.

public List<BibEntry>
getEntriesSorted(Comparator<BibEntry> comparator)

Returns the list of entries sorted by the given comparator.

public synchronized Optional<BibEntry>
getEntryByCitationKey(String key)

Returns the entry with the given citation key.

public BibEntry
public int
getEntryCount()

Returns the number of entries.

public String
public String
getNewLineSeparator()

Returns the string used to indicate a linebreak

public long
getNumberOfCitationKeyOccurrences(String key)

Returns the number of occurrences of the given citation key in this database.

public synchronized Optional<String>
getPreamble()

Returns the database's preamble.

public Optional<BibEntry>
public Optional<String>
public BibtexString
getString(String id)

Returns the string with the given id.

public Optional<BibtexString>
getStringByName(String name)

Returns the string with the given name/label

public int
getStringCount()

Returns the number of strings.

public Set<String>
getStringKeySet()

Returns a Set of keys to all BibtexString objects in the database.

public Collection<BibtexString>
getStringValues()

Returns a Collection of all BibtexString objects in the database.

public List<BibtexString>
getUsedStrings(Collection<BibEntry> entries)

Get all strings used in the entries.

public boolean
hasEntries()

Checks if the database contains entries.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean
hasNoStrings()

Check if there are strings.

public synchronized boolean
hasStringByName(String label)

Returns true if a string with the given label already exists.

public int

Returns:

The index of the given entry in the list of entries, or -1 if the entry is not in the list.
indexOf
(BibEntry bibEntry)

public synchronized void
insertEntries(BibEntry... entries)

public synchronized void
public synchronized void
insertEntries(List<BibEntry> newEntries, EntriesEventSource eventSource)

public synchronized void
public synchronized void
insertEntry(BibEntry
entry to insert
entry
,
EntriesEventSource
source the event is sent from
eventSource
)

Inserts the entry.

public boolean
isDuplicateCitationKeyExisting(String key)

Checks if there is more than one occurrence of the citation key.

public boolean
public void
public void
registerListener(Object
listener (subscriber) to add
listener
)

Registers a listener object (subscriber) to the internal event bus.

private void
public synchronized void
removeEntries(List<BibEntry>
Entries to delete
toBeDeleted
)

Removes the given entries.

public synchronized void
removeEntries(List<BibEntry>
Entry to delete
toBeDeleted
,
EntriesEventSource
Source the event is sent from
eventSource
)

Removes the given entries.

public synchronized void
public synchronized void
removeEntry(BibEntry bibEntry, EntriesEventSource eventSource)

public void
removeString(String id)

Removes the string with the given id.

private String
resolveContent(String result, Set<String> usedIds, Set<String> allUsedIds)

public String
resolveForStrings(String content)

Resolves any references to strings contained in this field content, if possible.

public List<BibEntry>

Returns:

a list of bibtexentries, with all strings resolved. It is dependent on the value of inPlace whether copies are made or the given BibtexEntries are modified.
resolveForStrings
(Collection<BibEntry>
A collection of BibtexEntries in which all strings of the form #xxx# will be resolved against the hash map of string references stored in the database.
entriesToResolve
,
boolean
If inPlace is true then the given BibtexEntries will be modified, if false then copies of the BibtexEntries are made before resolving the strings.
inPlace
)

Take the given collection of BibEntry and resolve any string references.

public BibEntry

Returns:

a BibEntry with all string references resolved. It is dependent on the value of inPlace whether a copy is made or the given BibtexEntries is modified.
resolveForStrings
(BibEntry
A BibEntry in which all strings of the form #xxx# will be resolved against the hash map of string references stored in the database.
entry
,
boolean
If inPlace is true then the given BibEntry will be modified, if false then a copy is made using close made before resolving the strings.
inPlace
)

Take the given BibEntry and resolve any string references.

private String
resolveString(String label, Set<String> usedIds, Set<String> allUsedIds)

If the label represents a string contained in this database, returns that string's content.

public void
setEpilog(String epilog)

public void
setNewLineSeparator(String newLineSeparator)

Set the newline separator.

public synchronized void
setPreamble(String preamble)

Sets the database's preamble.

public void
setSharedDatabaseID(String sharedDatabaseID)

public void
setStrings(List<BibtexString>
The collection of strings to set
stringsToAdd
)

Replaces the existing lists of BibTexString with the given one Duplicates throw KeyCollisionException

public void
unregisterListener(Object
listener (subscriber) to remove
listener
)

Unregisters an listener object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

bibtexStringsback to summary
private Map<String, BibtexString> bibtexStrings
entriesback to summary
private final ObservableList<BibEntry> entries

State attributes

entriesIdback to summary
private final Map<String, BibEntry> entriesId
epilogback to summary
private String epilog
eventBusback to summary
private final EventBus eventBus
LOGGERback to summary
private static final Logger LOGGER
newLineSeparatorback to summary
private String newLineSeparator
preambleback to summary
private String preamble
RESOLVE_CONTENT_PATTERNback to summary
private static final Pattern RESOLVE_CONTENT_PATTERN
sharedDatabaseIDback to summary
private String sharedDatabaseID

Constructor Detail

BibDatabaseback to summary
public BibDatabase(List<BibEntry> entries, String newLineSeparator)
BibDatabaseback to summary
public BibDatabase(List<BibEntry> entries)
BibDatabaseback to summary
public BibDatabase()

Method Detail

addStringback to summary
public synchronized void addString(BibtexString string) throws KeyCollisionException

Inserts a Bibtex String.

clearSharedDatabaseIDback to summary
public void clearSharedDatabaseID()
containsEntryWithIdback to summary
public boolean containsEntryWithId(String id)

Returns whether an entry with the given ID exists (-> entry_type + hashcode).

copyPreambleback to summary
public void copyPreamble(BibDatabase database)

Copies the preamble of another BibDatabase.

Parameters
database:BibDatabase

another BibDatabase

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

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

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
generateSharedDatabaseIDback to summary
public String generateSharedDatabaseID()

Generates and sets a random ID which is globally unique.

Returns:String

The generated sharedDatabaseID

getAllVisibleFieldsback to summary
public Set<Field> getAllVisibleFields()

Returns a set of Strings, that contains all field names that are visible. This means that the fields are not internal fields. Internal fields are fields, that are starting with "_".

Returns:Set<Field>

set of fieldnames, that are visible

getEntriesback to summary
public ObservableList<BibEntry> getEntries()
getEntriesByCitationKeyback to summary
public synchronized List<BibEntry> getEntriesByCitationKey(String key)

Collects entries having the specified citation key and returns these entries as list. The order of the entries is the order they appear in the database.

Returns:List<BibEntry>

list of entries that contains the given key

getEntriesSortedback to summary
public List<BibEntry> getEntriesSorted(Comparator<BibEntry> comparator)

Returns the list of entries sorted by the given comparator.

getEntryByCitationKeyback to summary
public synchronized Optional<BibEntry> getEntryByCitationKey(String key)

Returns the entry with the given citation key.

getEntryByIdback to summary
public BibEntry getEntryById(String id)
getEntryCountback to summary
public int getEntryCount()

Returns the number of entries.

getEpilogback to summary
public String getEpilog()
getNewLineSeparatorback to summary
public String getNewLineSeparator()

Returns the string used to indicate a linebreak

getNumberOfCitationKeyOccurrencesback to summary
public long getNumberOfCitationKeyOccurrences(String key)

Returns the number of occurrences of the given citation key in this database.

getPreambleback to summary
public synchronized Optional<String> getPreamble()

Returns the database's preamble. If the preamble text consists only of whitespace, then also an empty optional is returned.

getReferencedEntryback to summary
public Optional<BibEntry> getReferencedEntry(BibEntry entry)
getSharedDatabaseIDback to summary
public Optional<String> getSharedDatabaseID()
getStringback to summary
public BibtexString getString(String id)

Returns the string with the given id.

getStringByNameback to summary
public Optional<BibtexString> getStringByName(String name)

Returns the string with the given name/label

getStringCountback to summary
public int getStringCount()

Returns the number of strings.

getStringKeySetback to summary
public Set<String> getStringKeySet()

Returns a Set of keys to all BibtexString objects in the database. These are in no sorted order.

getStringValuesback to summary
public Collection<BibtexString> getStringValues()

Returns a Collection of all BibtexString objects in the database. These are in no particular order.

getUsedStringsback to summary
public List<BibtexString> getUsedStrings(Collection<BibEntry> entries)

Get all strings used in the entries.

hasEntriesback to summary
public boolean hasEntries()

Checks if the database contains entries.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
hasNoStringsback to summary
public boolean hasNoStrings()

Check if there are strings.

hasStringByNameback to summary
public synchronized boolean hasStringByName(String label)

Returns true if a string with the given label already exists.

indexOfback to summary
public int indexOf(BibEntry bibEntry)

Implementation Note

New entries are always added to the end of the list and always get a higher ID. See BibEntry, IdGenerator, insertEntries. Therefore, using binary search to find the index.

Implementation Note

IDs are zero-padded strings, so there is no need to convert them to integers for comparison.

Returns:int

The index of the given entry in the list of entries, or -1 if the entry is not in the list.

insertEntriesback to summary
public synchronized void insertEntries(BibEntry... entries)
insertEntriesback to summary
public synchronized void insertEntries(List<BibEntry> entries)
insertEntriesback to summary
public synchronized void insertEntries(List<BibEntry> newEntries, EntriesEventSource eventSource)
insertEntryback to summary
public synchronized void insertEntry(BibEntry entry)
insertEntryback to summary
public synchronized void insertEntry(BibEntry entry, EntriesEventSource eventSource)

Inserts the entry.

Parameters
entry:BibEntry

entry to insert

eventSource:EntriesEventSource

source the event is sent from

isDuplicateCitationKeyExistingback to summary
public boolean isDuplicateCitationKeyExisting(String key)

Checks if there is more than one occurrence of the citation key.

isSharedback to summary
public boolean isShared()
postEventback to summary
public void postEvent(Object event)
registerListenerback to summary
public void registerListener(Object listener)

Registers a listener object (subscriber) to the internal event bus. The following events are posted:

- EntriesAddedEvent - EntryChangedEvent - EntriesRemovedEvent

Parameters
listener:Object

listener (subscriber) to add

relayEntryChangeEventback to summary
private void relayEntryChangeEvent(FieldChangedEvent event)
Annotations
@Subscribe
removeEntriesback to summary
public synchronized void removeEntries(List<BibEntry> toBeDeleted)

Removes the given entries. The entries removed based on the id BibEntry#getId()

Parameters
toBeDeleted:List<BibEntry>

Entries to delete

removeEntriesback to summary
public synchronized void removeEntries(List<BibEntry> toBeDeleted, EntriesEventSource eventSource)

Removes the given entries. The entries are removed based on the id BibEntry#getId()

Parameters
toBeDeleted:List<BibEntry>

Entry to delete

eventSource:EntriesEventSource

Source the event is sent from

removeEntryback to summary
public synchronized void removeEntry(BibEntry bibEntry)
removeEntryback to summary
public synchronized void removeEntry(BibEntry bibEntry, EntriesEventSource eventSource)
removeStringback to summary
public void removeString(String id)

Removes the string with the given id.

resolveContentback to summary
private String resolveContent(String result, Set<String> usedIds, Set<String> allUsedIds)
resolveForStringsback to summary
public String resolveForStrings(String content)

Resolves any references to strings contained in this field content, if possible.

resolveForStringsback to summary
public List<BibEntry> resolveForStrings(Collection<BibEntry> entriesToResolve, boolean inPlace)

Take the given collection of BibEntry and resolve any string references.

Parameters
entriesToResolve:Collection<BibEntry>

A collection of BibtexEntries in which all strings of the form #xxx# will be resolved against the hash map of string references stored in the database.

inPlace:boolean

If inPlace is true then the given BibtexEntries will be modified, if false then copies of the BibtexEntries are made before resolving the strings.

Returns:List<BibEntry>

a list of bibtexentries, with all strings resolved. It is dependent on the value of inPlace whether copies are made or the given BibtexEntries are modified.

resolveForStringsback to summary
public BibEntry resolveForStrings(BibEntry entry, boolean inPlace)

Take the given BibEntry and resolve any string references.

Parameters
entry:BibEntry

A BibEntry in which all strings of the form #xxx# will be resolved against the hash map of string references stored in the database.

inPlace:boolean

If inPlace is true then the given BibEntry will be modified, if false then a copy is made using close made before resolving the strings.

Returns:BibEntry

a BibEntry with all string references resolved. It is dependent on the value of inPlace whether a copy is made or the given BibtexEntries is modified.

resolveStringback to summary
private String resolveString(String label, Set<String> usedIds, Set<String> allUsedIds)

If the label represents a string contained in this database, returns that string's content. Resolves references to other strings, taking care not to follow a circular reference pattern. If the string is undefined, returns null.

setEpilogback to summary
public void setEpilog(String epilog)
setNewLineSeparatorback to summary
public void setNewLineSeparator(String newLineSeparator)

Set the newline separator.

setPreambleback to summary
public synchronized void setPreamble(String preamble)

Sets the database's preamble.

setSharedDatabaseIDback to summary
public void setSharedDatabaseID(String sharedDatabaseID)
setStringsback to summary
public void setStrings(List<BibtexString> stringsToAdd)

Replaces the existing lists of BibTexString with the given one Duplicates throw KeyCollisionException

Parameters
stringsToAdd:List<BibtexString>

The collection of strings to set

unregisterListenerback to summary
public void unregisterListener(Object listener)

Unregisters an listener object.

Parameters
listener:Object

listener (subscriber) to remove