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