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

public Class AuthorList

extends Object
implements Iterable<Author>
Class Inheritance
All Implemented Interfaces
java.lang.Iterable
Annotations
@AllowedToUseLogic:because it needs access to AuthorList parser
Imports
java.util.Collections, .Iterator, .List, .Map, .Objects, .WeakHashMap, java.util.function.Function, java.util.stream.Collector, .Collectors, org.jabref.architecture.AllowedToUseLogic, org.jabref.logic.importer.AuthorListParser, org.jspecify.annotations.NonNull

This is an immutable class representing information of either author or editor field in bibtex record.

Constructor performs parsing of raw field text and stores preformatted data. Various accessor methods return author/editor field in different formats.

Parsing algorithm is designed to satisfy two requirements: (a) when author's name is typed correctly, the result should coincide with the one of BiBTeX; (b) for erroneous names, output should be reasonable (but may differ from BiBTeX output). The following rules are used:

  1. 'author field' is a sequence of tokens;
    • tokens are separated by sequences of whitespaces (Character.isWhitespace(c)==true), commas (,), dashes (-), and tildas (~);
    • every comma separates tokens, while sequences of other separators are equivalent to a single separator; for example: "a - b" consists of 2 tokens ("a" and "b"), while "a,-,b" consists of 3 tokens ("a", "", and "b")
    • anything enclosed in braces belongs to a single token; for example: "abc x{a,b,-~ c}x" consists of 2 tokens, while "abc xa,b,-~ cx" consists of 4 tokens ("abc", "xa","b", and "cx");
    • a token followed immediately by a dash is "dash-terminated" token, and all other tokens are "space-terminated" tokens; for example: in "a-b- c - d" tokens "a" and "b" are dash-terminated and "c" and "d" are space-terminated;
    • for the purposes of splitting of 'author name' into parts and construction of abbreviation of first name, one needs definitions of first letter of a token, case of a token, and abbreviation of a token:
      • 'first letter' of a token is the first letter character (Character.isLetter(c)==true) that does not belong to a sequence of letters that immediately follows "\" character, with one exception: if "\" is followed by "aa", "AA", "ae", "AE", "l", "L", "o", "O", "oe", "OE", "i", or "j" followed by non-letter, the 'first letter' of a token is a letter that follows "\"; for example: in "a{x}b" 'first letter' is "a", in "{\"{U}}bel" 'first letter' is "U", in "{\noopsort{\"o}}xyz" 'first letter' is "o", in "{\AE}x" 'first letter' is "A", in "\aex\ijk\Oe\j" 'first letter' is "j"; if there is no letter satisfying the above rule, 'first letter' is undefined;
      • token is "lower-case" token if its first letter is defined and is lower-case (Character.isLowerCase(c)==true), and token is "upper-case" token otherwise;
      • 'abbreviation' of a token is the shortest prefix of the token that (a) contains 'first letter' and (b) is braces-balanced; if 'first letter' is undefined, 'abbreviation' is the token itself; in the above examples, 'abbreviation's are "a", "{\"{U}}", "{\noopsort{\"o}}", "{\AE}", "\aex\ijk\Oe\j";
    • the behavior based on the above definitions will be erroneous only in one case: if the first-name-token is "{\noopsort{A}}john", we abbreviate it as "{\noopsort{A}}.", while BiBTeX produces "j."; fixing this problem, however, requires processing of the preabmle;
  2. 'author names' in 'author field' are subsequences of tokens separated by token "and" ("and" is case-insensitive); if 'author name' is an empty sequence of tokens, it is ignored; for examle, both "John Smith and Peter Black" and "and and John Smith and and Peter Black" consists of 2 'author name's "Johm Smith" and "Peter Black" (in erroneous situations, this is a bit different from BiBTeX behavior);
  3. 'author name' consists of 'first-part', 'von-part', 'last-part', and 'junior-part', each of which is a sequence of tokens; how a sequence of tokens has to be split into these parts, depends the number of commas:
    • no commas, all tokens are upper-case: 'junior-part' and 'von-part' are empty, 'last-part' consist of the last token, 'first-part' consists of all other tokens ('first-part' is empty if 'author name' consists of a single token); for example, in "John James Smith", 'last-part'="Smith" and 'first-part'="John James";
    • no commas, there exists lower-case token: 'junior-part' is empty, 'first-part' consists of all upper-case tokens before the first lower-case token, 'von-part' consists of lower-case tokens starting the first lower-case token and ending the lower-case token that is followed by upper-case token, 'last-part' consists of the rest of tokens; note that both 'first-part' and 'latst-part' may be empty and 'last-part' may contain lower-case tokens; for example: in "von der", 'first-part'='last-part'="", 'von-part'="von der"; in "Charles Louis Xavier Joseph de la Vall{\'e}e la Poussin", 'first-part'="Charles Louis Xavier Joseph", 'von-part'="de la", 'last-part'="Vall{\'e}e la Poussin";
    • one comma: 'junior-part' is empty, 'first-part' consists of all tokens after comma, 'von-part' consists of the longest sequence of lower-case tokens in the very beginning, 'last-part' consists of all tokens after 'von-part' and before comma; note that any part can be empty; for example: in "de la Vall{\'e}e la Poussin, Charles Louis Xavier Joseph", 'first-part'="Charles Louis Xavier Joseph", 'von-part'="de la", 'last-part'="Vall{\'e}e la Poussin"; in "Joseph de la Vall{\'e}e la Poussin, Charles Louis Xavier", 'first-part'="Charles Louis Xavier", 'von-part'="", 'last-part'="Joseph de la Vall{\'e}e la Poussin";
    • two or more commas (any comma after the second one is ignored; it merely separates tokens): 'junior-part' consists of all tokens between first and second commas, 'first-part' consists of all tokens after the second comma, tokens before the first comma are split into 'von-part' and 'last-part' similarly to the case of one comma; for example: in "de la Vall{\'e}e Poussin, Jr., Charles Louis Xavier Joseph", 'first-part'="Charles Louis Xavier Joseph", 'von-part'="de la", 'last-part'="Vall{\'e}e la Poussin", and 'junior-part'="Jr.";
  4. when 'first-part', 'last-part', 'von-part', or 'junior-part' is reconstructed from tokens, tokens in a part are separated either by space or by dash, depending on whether the token before the separator was space-terminated or dash-terminated; for the last token in a part it does not matter whether it was dash- or space-terminated;
  5. when 'first-part' is abbreviated, each token is replaced by its abbreviation followed by a period; separators are the same as in the case of non-abbreviated name; for example: in "Heinrich-{\"{U}}bel Kurt von Minich", 'first-part'="Heinrich-{\"{U}}bel Kurt", and its abbreviation is "H.-{\"{U}}. K."

Field Summary

Modifier and TypeField and Description
private static final Map<String, AuthorList>
private final List<Author>
private AuthorList

Constructor Summary

AccessConstructor and Description
private
AuthorList(List<Author>
the list of authors which should underlie this instance
authors
)

Creates a new list of authors.

Method Summary

Modifier and TypeMethod and Description
private static String
andCoordinatedConjunction(List<Author> authors, Function<Author, String> style, boolean oxfordComma)

private static String
andCoordinatedConjunction(List<String> authors, boolean oxfordComma)

public static Collector<Author, ?, AuthorList>
public boolean

Returns:

`true` iff the other object is an AuthorList, all contained authors are in the same order (and these authors' fields are `Objects.equals`)
equals
(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Compare this object with the given one.

public static String
fixAuthorFirstNameFirst(String authors)

This is a convenience method for getAuthorsFirstFirstAnds()

public static String
fixAuthorFirstNameFirstCommas(String authors, boolean abbreviate, boolean oxfordComma)

This is a convenience method for getAuthorsFirstFirst()

public static String
fixAuthorForAlphabetization(String authors)

This is a convenience method for getAuthorsForAlphabetization()

public static String
fixAuthorLastNameFirst(String authors)

This is a convenience method for getAuthorsLastFirstAnds(true)

public static String
fixAuthorLastNameFirst(String authors, boolean abbreviate)

This is a convenience method for getAuthorsLastFirstAnds()

public static String
fixAuthorLastNameFirstCommas(String authors, boolean abbreviate, boolean oxfordComma)

This is a convenience method for getAuthorsLastFirst()

public static String
fixAuthorLastNameOnlyCommas(String authors, boolean oxfordComma)

This is a convenience method for getAuthorsLastOnly()

public static String
fixAuthorNatbib(String authors)

This is a convenience method for getAuthorsNatbib()

public String

Returns:

formatted list of authors.
getAsFirstLastNames
(boolean
whether to abbreivate first names.
abbreviate
,
boolean
Whether to put a comma before the and at the end.
oxfordComma
)

Returns the list of authors separated by commas with first names before last name; first names are abbreviated or not depending on parameter.

public String

Returns:

formatted list of authors.
getAsFirstLastNamesWithAnd
()

Returns the list of authors separated by "and"s with first names before last name; first names are not abbreviated.

public String
getAsLastFirstFirstLastNamesWithAnd(boolean
first names.
abbreviate
)

Returns a list of authors separated with "and".

public String

Returns:

formatted list of authors.
getAsLastFirstNames
(boolean
whether to abbreivate first names.
abbreviate
,
boolean
Whether to put a comma before the and at the end.
oxfordComma
)

Returns the list of authors separated by commas with first names after last name; first names are abbreviated or not depending on parameter.

public String

Returns:

formatted list of authors.
getAsLastFirstNamesWithAnd
(boolean abbreviate)

Returns the list of authors separated by "and"s with first names after last name; first names are not abbreviated.

public String

Returns:

formatted list of authors.
getAsLastNames
(boolean
Whether to put a comma before the and at the end.
oxfordComma
)

Returns the list of authors separated by commas with last name only; If the list consists of two or more authors, "and" is inserted before the last author's name.

public String

Returns:

formatted list of authors.
getAsNatbib
()

Returns the list of authors in "natbib" format.

public Author

Returns:

the Author object.
getAuthor
(int
Index of the author (from 0 to size()-1).
i
)

Returns the Author object for the i-th author.

public List<Author>

Returns:

the List<Author> object.
getAuthors
()

Returns the list of Author objects.

public String

Returns:

formatted list of authors
getForAlphabetization
()

Returns the list of authors in a form suitable for alphabetization.

public int

Returns:

the number of author names in this object.
getNumberOfAuthors
()

Returns the number of author names in this object.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean

Returns:

true if there are no authors in the list.
isEmpty
()

Returns true if there are no authors in the list.

public Iterator<Author>
iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

public AuthorList
latexFree()

Returns a LaTeX-free version of this `AuthorList`.

public static AuthorList
of(List<Author> authors)

public static AuthorList
of(Author... authors)

public static AuthorList

Returns:

An AuthorList object representing the given authors.
parse
(final @NonNull String
The string of authors or editors in bibtex format to parse.
authors
)

Retrieve an AuthorList for the given string of authors or editors.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

AUTHOR_CACHEback to summary
private static final Map<String, AuthorList> AUTHOR_CACHE
authorsback to summary
private final List<Author> authors
latexFreeAuthorsback to summary
private AuthorList latexFreeAuthors

Constructor Detail

AuthorListback to summary
private AuthorList(List<Author> authors)

Creates a new list of authors.

Don't call this constructor directly but rather use the getAuthorList() method which caches its results.

Parameters
authors:List<Author>

the list of authors which should underlie this instance

Method Detail

andCoordinatedConjunctionback to summary
private static String andCoordinatedConjunction(List<Author> authors, Function<Author, String> style, boolean oxfordComma)
andCoordinatedConjunctionback to summary
private static String andCoordinatedConjunction(List<String> authors, boolean oxfordComma)
collectback to summary
public static Collector<Author, ?, AuthorList> collect()
equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Compare this object with the given one.

Parameters
o:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

`true` iff the other object is an AuthorList, all contained authors are in the same order (and these authors' fields are `Objects.equals`)

Annotations
@Override
fixAuthorFirstNameFirstback to summary
public static String fixAuthorFirstNameFirst(String authors)

This is a convenience method for getAuthorsFirstFirstAnds()

See Also
AuthorList#getAsFirstLastNamesWithAnd
fixAuthorFirstNameFirstCommasback to summary
public static String fixAuthorFirstNameFirstCommas(String authors, boolean abbreviate, boolean oxfordComma)

This is a convenience method for getAuthorsFirstFirst()

See Also
AuthorList#getAsFirstLastNames
fixAuthorForAlphabetizationback to summary
public static String fixAuthorForAlphabetization(String authors)

This is a convenience method for getAuthorsForAlphabetization()

See Also
AuthorList#getForAlphabetization
fixAuthorLastNameFirstback to summary
public static String fixAuthorLastNameFirst(String authors)

This is a convenience method for getAuthorsLastFirstAnds(true)

See Also
AuthorList#getAsLastFirstNamesWithAnd
fixAuthorLastNameFirstback to summary
public static String fixAuthorLastNameFirst(String authors, boolean abbreviate)

This is a convenience method for getAuthorsLastFirstAnds()

See Also
AuthorList#getAsLastFirstNamesWithAnd
fixAuthorLastNameFirstCommasback to summary
public static String fixAuthorLastNameFirstCommas(String authors, boolean abbreviate, boolean oxfordComma)

This is a convenience method for getAuthorsLastFirst()

See Also
AuthorList#getAsLastFirstNames
fixAuthorLastNameOnlyCommasback to summary
public static String fixAuthorLastNameOnlyCommas(String authors, boolean oxfordComma)

This is a convenience method for getAuthorsLastOnly()

See Also
AuthorList#getAsLastNames
fixAuthorNatbibback to summary
public static String fixAuthorNatbib(String authors)

This is a convenience method for getAuthorsNatbib()

See Also
AuthorList#getAsNatbib
getAsFirstLastNamesback to summary
public String getAsFirstLastNames(boolean abbreviate, boolean oxfordComma)

Returns the list of authors separated by commas with first names before last name; first names are abbreviated or not depending on parameter. If the list consists of three or more authors, "and" is inserted before the last author's name.

  • "John Smith" ==> "John Smith" or "J. Smith"
  • "John Smith and Black Brown, Peter" ==> "John Smith and Peter Black Brown" or "J. Smith and P. Black Brown"
  • "John von Neumann and John Smith and Black Brown, Peter" ==> "John von Neumann, John Smith and Peter Black Brown" or "J. von Neumann, J. Smith and P. Black Brown"
Parameters
abbreviate:boolean

whether to abbreivate first names.

oxfordComma:boolean

Whether to put a comma before the and at the end.

Returns:String

formatted list of authors.

See Also
serial comma for an detailed explaination about the Oxford comma.
getAsFirstLastNamesWithAndback to summary
public String getAsFirstLastNamesWithAnd()

Returns the list of authors separated by "and"s with first names before last name; first names are not abbreviated.

  • "John Smith" ==> "John Smith"
  • "John Smith and Black Brown, Peter" ==> "John Smith and Peter Black Brown"
  • "John von Neumann and John Smith and Black Brown, Peter" ==> "John von Neumann and John Smith and Peter Black Brown"
Returns:String

formatted list of authors.

getAsLastFirstFirstLastNamesWithAndback to summary
public String getAsLastFirstFirstLastNamesWithAnd(boolean abbreviate)

Returns a list of authors separated with "and". The first author is formatted with Author#getFamilyGiven(boolean) and each subsequent author is formatted with Author#getGivenFamily(boolean).

Parameters
abbreviate:boolean

first names.

getAsLastFirstNamesback to summary
public String getAsLastFirstNames(boolean abbreviate, boolean oxfordComma)

Returns the list of authors separated by commas with first names after last name; first names are abbreviated or not depending on parameter. If the list consists of three or more authors, "and" is inserted before the last author's name.

  • "John Smith" ==> "Smith, John" or "Smith, J."
  • "John Smith and Black Brown, Peter" ==> "Smith, John and Black Brown, Peter" or "Smith, J. and Black Brown, P."
  • "John von Neumann and John Smith and Black Brown, Peter" ==> "von Neumann, John, Smith, John and Black Brown, Peter" or "von Neumann, J., Smith, J. and Black Brown, P.".
Parameters
abbreviate:boolean

whether to abbreivate first names.

oxfordComma:boolean

Whether to put a comma before the and at the end.

Returns:String

formatted list of authors.

See Also
serial comma for an detailed explaination about the Oxford comma.
getAsLastFirstNamesWithAndback to summary
public String getAsLastFirstNamesWithAnd(boolean abbreviate)

Returns the list of authors separated by "and"s with first names after last name; first names are not abbreviated.

  • "John Smith" ==> "Smith, John"
  • "John Smith and Black Brown, Peter" ==> "Smith, John and Black Brown, Peter"
  • "John von Neumann and John Smith and Black Brown, Peter" ==> "von Neumann, John and Smith, John and Black Brown, Peter".
Returns:String

formatted list of authors.

getAsLastNamesback to summary
public String getAsLastNames(boolean oxfordComma)

Returns the list of authors separated by commas with last name only; If the list consists of two or more authors, "and" is inserted before the last author's name.

  • "John Smith" ==> "Smith"
  • "John Smith and Black Brown, Peter" ==> "Smith and Black Brown"
  • "John von Neumann and John Smith and Black Brown, Peter" ==> "von Neumann, Smith and Black Brown".
Parameters
oxfordComma:boolean

Whether to put a comma before the and at the end.

Returns:String

formatted list of authors.

See Also
serial comma for an detailed explaination about the Oxford comma.
getAsNatbibback to summary
public String getAsNatbib()

Returns the list of authors in "natbib" format.

  • "John Smith" -> "Smith"
  • "John Smith and Black Brown, Peter" ==> "Smith and Black Brown"
  • "John von Neumann and John Smith and Black Brown, Peter" ==> "von Neumann et al."
Returns:String

formatted list of authors.

getAuthorback to summary
public Author getAuthor(int i)

Returns the Author object for the i-th author.

Parameters
i:int

Index of the author (from 0 to size()-1).

Returns:Author

the Author object.

getAuthorsback to summary
public List<Author> getAuthors()

Returns the list of Author objects.

Returns:List<Author>

the List<Author> object.

getForAlphabetizationback to summary
public String getForAlphabetization()

Returns the list of authors in a form suitable for alphabetization. This means that last names come first, never preceded by "von" particles, and that any braces are removed. First names are abbreviated so the same name is treated similarly if abbreviated in one case and not in another. This form is not intended to be suitable for presentation, only for sorting.

  • "John Smith" ==> "Smith, J.";
Returns:String

formatted list of authors

getNumberOfAuthorsback to summary
public int getNumberOfAuthors()

Returns the number of author names in this object.

Returns:int

the number of author names in this object.

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
isEmptyback to summary
public boolean isEmpty()

Returns true if there are no authors in the list.

Returns:boolean

true if there are no authors in the list.

iteratorback to summary
public Iterator<Author> iterator()

Implements java.lang.Iterable.iterator.

Doc from java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

Returns:Iterator<Author>

an Iterator.

Annotations
@Override
latexFreeback to summary
public AuthorList latexFree()

Returns a LaTeX-free version of this `AuthorList`.

ofback to summary
public static AuthorList of(List<Author> authors)
ofback to summary
public static AuthorList of(Author... authors)
parseback to summary
public static AuthorList parse(final @NonNull String authors)

Retrieve an AuthorList for the given string of authors or editors.

This function tries to cache the parsed AuthorLists by the string passed in.

Parameters
authors:@NonNull String

The string of authors or editors in bibtex format to parse.

Returns:AuthorList

An AuthorList object representing the given authors.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override