forked from JabRef/jabref
/
TexBibEntriesResolverResult.java
125 lines (102 loc) · 3.46 KB
/
TexBibEntriesResolverResult.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package org.jabref.model.texparser;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.StringJoiner;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.entry.BibEntry;
import com.google.common.collect.Multimap;
public class TexBibEntriesResolverResult {
private final TexParserResult texParserResult;
private final List<String> unresolvedKeys;
private final List<BibEntry> newEntries;
private int crossRefsCount;
public TexBibEntriesResolverResult(TexParserResult texParserResult) {
this.texParserResult = texParserResult;
this.unresolvedKeys = new ArrayList<>();
this.newEntries = new ArrayList<>();
this.crossRefsCount = 0;
}
public TexParserResult getTexParserResult() {
return texParserResult;
}
public List<String> getUnresolvedKeys() {
return unresolvedKeys;
}
public List<BibEntry> getNewEntries() {
return newEntries;
}
public int getCrossRefsCount() {
return crossRefsCount;
}
/**
* Return the citations multimap from the TexParserResult object.
*/
public Multimap<String, Citation> getCitations() {
return texParserResult.getCitations();
}
/**
* Return a set of strings with the keys of the citations multimap from the TexParserResult object.
*/
public Set<String> getCitationsKeySet() {
return texParserResult.getCitationsKeySet();
}
/**
* Add an unresolved key to the list.
*/
public void addUnresolvedKey(String key) {
unresolvedKeys.add(key);
}
/**
* Check if an entry with the given key is present in the list of new entries.
*/
public boolean checkEntryNewDatabase(String key) {
return newEntries.stream().anyMatch(e -> e.getCiteKeyOptional().get().equals(key));
}
/**
* Add 1 to the cross references counter.
*/
public void increaseCrossRefsCount() {
crossRefsCount++;
}
/**
* Insert into the list of new entries an entry with the given key.
*/
public void insertEntry(BibDatabase masterDatabase, String key) {
insertEntry(masterDatabase.getEntryByKey(key).get());
}
/**
* Insert into the list of new entries the given entry.
*/
public void insertEntry(BibEntry entry) {
newEntries.add(entry);
}
@Override
public String toString() {
return new StringJoiner(", ", this.getClass().getSimpleName() + "[", "]")
.add("texParserResult = " + texParserResult)
.add("unresolvedKeys = " + unresolvedKeys)
.add("newEntries = " + newEntries)
.add("crossRefsCount = " + crossRefsCount)
.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
TexBibEntriesResolverResult that = (TexBibEntriesResolverResult) o;
return Objects.equals(texParserResult, that.texParserResult)
&& Objects.equals(unresolvedKeys, that.unresolvedKeys)
&& Objects.equals(newEntries, that.newEntries)
&& Objects.equals(crossRefsCount, that.crossRefsCount);
}
@Override
public int hashCode() {
return Objects.hash(texParserResult, unresolvedKeys, newEntries, crossRefsCount);
}
}