-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
MsBibAuthor.java
65 lines (51 loc) · 1.67 KB
/
MsBibAuthor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package org.jabref.logic.msbib;
import org.jabref.logic.formatter.bibtexfields.RemoveEnclosingBracesFormatter;
import org.jabref.model.entry.Author;
public class MsBibAuthor {
private static final RemoveEnclosingBracesFormatter REMOVE_BRACES_FORMATTER = new RemoveEnclosingBracesFormatter();
private String firstName;
private String middleName;
private final Author author;
private boolean isCorporate;
public MsBibAuthor(Author author) {
this.author = author;
StringBuilder sb = new StringBuilder();
author.getGivenName().ifPresent(firstNames -> {
String[] names = firstNames.split(" ");
for (int i = 1; i < names.length; i++) {
sb.append(names[i]);
sb.append(" ");
}
this.middleName = sb.toString().trim();
this.firstName = names[0];
});
}
public MsBibAuthor(Author author, boolean isCorporate) {
this(author);
this.isCorporate = isCorporate;
}
public String getFirstName() {
if (!"".equals(firstName)) {
return firstName;
}
return author.getGivenName().orElse(null);
}
public String getMiddleName() {
if ("".equals(middleName)) {
return null;
}
return middleName;
}
public String getLastName() {
return REMOVE_BRACES_FORMATTER.format(author.getNamePrefixAndFamilyName());
}
public String getFirstLast() {
return author.getGivenFamily(false);
}
public String getLastFirst() {
return author.getFamilyGiven(false);
}
public boolean isCorporate() {
return isCorporate;
}
}