1 | /** | | 1 | /** |
2 | * Returns the list of authors separated by "and"s with first names after | | 2 | * Returns the list of authors separated by commas with first names after |
3 | * last name; first names are not abbreviated. | | 3 | * last name; first names are abbreviated or not depending on parameter. If |
4 | * <p> | | 4 | * the list consists of three or more authors, "and" is inserted before the |
5 | * <ul> | | 5 | * last author's name. |
6 | * <li>"John Smith" ==> "Smith, John"</li> | | 6 | * <p> |
7 | * <li>"John Smith and Black Brown, Peter" ==> "Smith, John and Black | | 7 | * |
8 | * Brown, Peter"</li> | | 8 | * <ul> |
9 | * <li>"John von Neumann and John Smith and Black Brown, Peter" ==> "von | | 9 | * <li> "John Smith" ==> "Smith, John" or "Smith, J."</li> |
10 | * Neumann, John and Smith, John and Black Brown, Peter".</li> | | 10 | * <li> "John Smith and Black Brown, Peter" ==> "Smith, John and Black |
11 | * </ul> | | 11 | * Brown, Peter" or "Smith, J. and Black Brown, P."</li> |
12 | * | | 12 | * <li> "John von Neumann and John Smith and Black Brown, Peter" ==> "von |
13 | * @return formatted list of authors. | | 13 | * Neumann, John, Smith, John and Black Brown, Peter" or "von Neumann, J., |
14 | */ | | 14 | * Smith, J. and Black Brown, P.".</li> |
15 | public String getAuthorsLastFirstAnds(boolean abbreviate) { | | 15 | * </ul> |
16 | int abbrInt = (abbreviate ? 0 : 1); | | 16 | * |
17 | // Check if we've computed this before: | | 17 | * @param abbreviate |
18 | if (authorLastFirstAnds[abbrInt] != null) | | 18 | * whether to abbreivate first names. |
19 | return authorLastFirstAnds[abbrInt]; | | 19 | * |
20 | | | 20 | * @param oxfordComma |
21 | StringBuffer res = new StringBuffer(); | | 21 | * Whether to put a comma before the and at the end. |
22 | if (size() > 0) { | | 22 | * |
23 | res.append(getAuthor(0).getLastFirst(abbreviate)); | | 23 | * @see http://en.wikipedia.org/wiki/Serial_comma For an detailed |
24 | for (int i = 1; i < size(); i++) { | | 24 | * explaination about the Oxford comma. |
25 | res.append(" and "); | | 25 | * |
26 | res.append(getAuthor(i).getLastFirst(abbreviate)); | | 26 | * @return formatted list of authors. |
27 | } | | 27 | */ |
28 | } | | 28 | public String getAuthorsLastFirst(boolean abbreviate, boolean oxfordComma) { |
29 | | | 29 | int abbrInt = (abbreviate ? 0 : 1); |
30 | authorLastFirstAnds[abbrInt] = res.toString(); | | 30 | abbrInt += (oxfordComma ? 0 : 2); |
31 | return authorLastFirstAnds[abbrInt]; | | 31 | |
32 | } | | 32 | // Check if we've computed this before: |
| | | 33 | if (authorsLastFirst[abbrInt] != null) |
| | | 34 | return authorsLastFirst[abbrInt]; |
| | | 35 | |
| | | 36 | StringBuffer res = new StringBuffer(); |
| | | 37 | if (size() > 0) { |
| | | 38 | res.append(getAuthor(0).getLastFirst(abbreviate)); |
| | | 39 | int i = 1; |
| | | 40 | while (i < size() - 1) { |
| | | 41 | res.append(", "); |
| | | 42 | res.append(getAuthor(i).getLastFirst(abbreviate)); |
| | | 43 | i++; |
| | | 44 | } |
| | | 45 | if (size() > 2 && oxfordComma) |
| | | 46 | res.append(","); |
| | | 47 | if (size() > 1) { |
| | | 48 | res.append(" and "); |
| | | 49 | res.append(getAuthor(i).getLastFirst(abbreviate)); |
| | | 50 | } |
| | | 51 | } |
| | | 52 | authorsLastFirst[abbrInt] = res.toString(); |
| | | 53 | return authorsLastFirst[abbrInt]; |
| | | 54 | } |