1 | /** | | 1 | /** |
2 | * Returns the list of authors in a form suitable for alphabetization. This | | 2 | * Returns the list of authors separated by commas with last name only; If |
3 | * means that last names come first, never preceded by "von" particles, and | | 3 | * the list consists of three or more authors, "and" is inserted before the |
4 | * that any braces are removed. First names are abbreviated so the same name | | 4 | * last author's name. |
5 | * is treated similarly if abbreviated in one case and not in another. This | | 5 | * <p> |
6 | * form is not intended to be suitable for presentation, only for sorting. | | 6 | * |
7 | * | | 7 | * <ul> |
8 | * <p> | | 8 | * <li> "John Smith" ==> "Smith"</li> |
9 | * <ul> | | 9 | * <li> "John Smith and Black Brown, Peter" ==> "Smith and Black Brown"</li> |
10 | * <li>"John Smith" ==> "Smith, J.";</li> | | 10 | * <li> "John von Neumann and John Smith and Black Brown, Peter" ==> "von |
11 | * | | 11 | * Neumann, Smith and Black Brown".</li> |
12 | * | | 12 | * </ul> |
13 | * @return formatted list of authors | | 13 | * |
14 | */ | | 14 | * @param oxfordComma |
15 | public String getAuthorsForAlphabetization() { | | 15 | * Whether to put a comma before the and at the end. |
16 | if (authorsAlph != null) | | 16 | * |
17 | return authorsAlph; | | 17 | * @see http://en.wikipedia.org/wiki/Serial_comma For an detailed |
18 | | | 18 | * explaination about the Oxford comma. |
19 | StringBuffer res = new StringBuffer(); | | 19 | * |
20 | if (size() > 0) { | | 20 | * @return formatted list of authors. |
21 | res.append(getAuthor(0).getNameForAlphabetization()); | | 21 | */ |
22 | for (int i = 1; i < size(); i++) { | | 22 | public String getAuthorsLastOnly(boolean oxfordComma) { |
23 | res.append(" and "); | | 23 | int abbrInt = (oxfordComma ? 0 : 1); |
24 | res.append(getAuthor(i).getNameForAlphabetization()); | | 24 | |
25 | } | | 25 | // Check if we've computed this before: |
26 | } | | 26 | if (authorsLastOnly[abbrInt] != null) |
27 | authorsAlph = res.toString(); | | 27 | return authorsLastOnly[abbrInt]; |
28 | return authorsAlph; | | 28 | |
29 | } | | 29 | StringBuffer res = new StringBuffer(); |
| | | 30 | if (size() > 0) { |
| | | 31 | res.append(getAuthor(0).getLastOnly()); |
| | | 32 | int i = 1; |
| | | 33 | while (i < size() - 1) { |
| | | 34 | res.append(", "); |
| | | 35 | res.append(getAuthor(i).getLastOnly()); |
| | | 36 | i++; |
| | | 37 | } |
| | | 38 | if (size() > 2 && oxfordComma) |
| | | 39 | res.append(","); |
| | | 40 | if (size() > 1) { |
| | | 41 | res.append(" and "); |
| | | 42 | res.append(getAuthor(i).getLastOnly()); |
| | | 43 | } |
| | | 44 | } |
| | | 45 | authorsLastOnly[abbrInt] = res.toString(); |
| | | 46 | return authorsLastOnly[abbrInt]; |
| | | 47 | } |