52
52
/**
53
53
* Represents a Bib(La)TeX entry, which can be BibTeX or BibLaTeX.
54
54
* <p>
55
- * Example:
55
+ * Example:
56
56
*
57
- * <pre>{@code
57
+ * <pre>{@code
58
58
* Some commment
59
59
* @misc{key,
60
60
* fieldName = {fieldValue},
61
61
* otherFieldName = {otherVieldValue}
62
62
* }
63
63
* }</pre>
64
- *
65
- * Then,
64
+ * <p>
65
+ * Then,
66
66
* <ul>
67
67
* <li>"Some comment" is the comment before the entry,</li>
68
68
* <li>"misc" is the entry type</li>
@@ -157,14 +157,20 @@ public Optional<FieldChange> setMonth(Month parsedMonth) {
157
157
return setField (StandardField .MONTH , parsedMonth .getJabRefFormat ());
158
158
}
159
159
160
+ /**
161
+ * Retrieves the first resolved field or its alias from the provided OrFields object using Stream API.
162
+ *
163
+ * @param fields The OrFields object containing a list of fields to be resolved.
164
+ * @param database The BibDatabase used for resolving the field or its alias.
165
+ * @return An Optional containing the first resolved field or alias if present,
166
+ * otherwise an empty Optional.
167
+ */
160
168
public Optional <String > getResolvedFieldOrAlias (OrFields fields , BibDatabase database ) {
161
- for (Field field : fields .getFields ()) {
162
- Optional <String > value = getResolvedFieldOrAlias (field , database );
163
- if (value .isPresent ()) {
164
- return value ;
165
- }
166
- }
167
- return Optional .empty ();
169
+ return fields .getFields ().stream ()
170
+ .map (field -> getResolvedFieldOrAlias (field , database ))
171
+ .filter (Optional ::isPresent )
172
+ .map (Optional ::get )
173
+ .findFirst ();
168
174
}
169
175
170
176
/**
@@ -478,7 +484,7 @@ public boolean hasField(Field field) {
478
484
479
485
/**
480
486
* Internal method used to get the content of a field (or its alias)
481
- *
487
+ * <p>
482
488
* Used by {@link #getFieldOrAlias(Field)} and {@link #getFieldOrAliasLatexFree(Field)}
483
489
*
484
490
* @param field the field
@@ -711,7 +717,7 @@ public String toString() {
711
717
* Author1, Author2: Title (Year)
712
718
*/
713
719
public String getAuthorTitleYear (int maxCharacters ) {
714
- String [] s = new String []{getField (StandardField .AUTHOR ).orElse ("N/A" ), getField (StandardField .TITLE ).orElse ("N/A" ),
720
+ String [] s = new String [] {getField (StandardField .AUTHOR ).orElse ("N/A" ), getField (StandardField .TITLE ).orElse ("N/A" ),
715
721
getField (StandardField .YEAR ).orElse ("N/A" )};
716
722
717
723
String text = s [0 ] + ": \" " + s [1 ] + "\" (" + s [2 ] + ')' ;
@@ -907,7 +913,7 @@ public boolean equals(Object o) {
907
913
908
914
/**
909
915
* On purpose, this hashes the "content" of the BibEntry, not the {@link #sharedBibEntryData}.
910
- *
916
+ * <p>
911
917
* The content is
912
918
*
913
919
* <ul>
@@ -928,7 +934,8 @@ public void registerListener(Object object) {
928
934
public void unregisterListener (Object object ) {
929
935
try {
930
936
this .eventBus .unregister (object );
931
- } catch (IllegalArgumentException e ) {
937
+ } catch (
938
+ IllegalArgumentException e ) {
932
939
// occurs if the event source has not been registered, should not prevent shutdown
933
940
LOGGER .debug ("Problem unregistering" , e );
934
941
}
@@ -1106,7 +1113,7 @@ public Observable[] getObservables() {
1106
1113
* This method. adds the given path (as file) to the entry and removes the url.
1107
1114
*
1108
1115
* @param linkToDownloadedFile the link to the file, which was downloaded
1109
- * @param downloadedFile the path to be added to the entry
1116
+ * @param downloadedFile the path to be added to the entry
1110
1117
*/
1111
1118
public void replaceDownloadedFile (String linkToDownloadedFile , LinkedFile downloadedFile ) {
1112
1119
List <LinkedFile > linkedFiles = this .getFiles ();
@@ -1144,7 +1151,7 @@ public void mergeWith(BibEntry other) {
1144
1151
* Merge this entry's fields with another BibEntry. Non-intersecting fields will be automatically merged. In cases of
1145
1152
* intersection, priority is given to THIS entry's field value, UNLESS specified otherwise in the arguments.
1146
1153
*
1147
- * @param other another BibEntry from which fields are sourced from
1154
+ * @param other another BibEntry from which fields are sourced from
1148
1155
* @param otherPrioritizedFields collection of Fields in which 'other' has a priority into final result
1149
1156
*/
1150
1157
public void mergeWith (BibEntry other , Set <Field > otherPrioritizedFields ) {
@@ -1174,4 +1181,52 @@ public boolean isEmpty() {
1174
1181
}
1175
1182
return StandardField .AUTOMATIC_FIELDS .containsAll (this .getFields ());
1176
1183
}
1184
+
1185
+ public void addCrossref (BibEntry crossrefEntry ) {
1186
+ // Adding cross-references
1187
+ this .setField (StandardField .CROSSREF , crossrefEntry .getCitationKey ().toString ());
1188
+ // Updating Cells
1189
+ updateCell ();
1190
+ }
1191
+
1192
+ public void addFileFromCrossref (LinkedFile file ) {
1193
+ List <LinkedFile > linkedFiles = this .getFiles ();
1194
+ // If the cross-referenced entry already has documentation from the cross-referenced entry, the documentation is not updated
1195
+ if (!linkedFiles .stream ().anyMatch (f -> f .getLink ().equalsIgnoreCase (file .getLink ()))) {
1196
+ linkedFiles .add (file );
1197
+ // Updated documents
1198
+ updateFiles (linkedFiles );
1199
+ }
1200
+ }
1201
+
1202
+ public void removeCrossref () {
1203
+ // Removing cross-references
1204
+ // this.removeCrossrefedEntry(StandardField.ENTRYSET);
1205
+ // Updating Cells
1206
+ updateCell ();
1207
+ }
1208
+
1209
+ public void updateCitationKey (String newCitationKey ) {
1210
+ // Changing the reference key of a cross-reference entry
1211
+ this .setField (InternalField .KEY_FIELD , newCitationKey );
1212
+ // Updating Cells
1213
+ updateCell ();
1214
+ }
1215
+
1216
+ public void removeCrossrefedEntry (BibEntry crossrefedEntry ) {
1217
+ // Remove cross-referenced entries
1218
+ crossrefedEntry .removeCrossref ();
1219
+ // Updating Cells
1220
+ updateCell ();
1221
+ }
1222
+
1223
+ private void updateCell () {
1224
+ // Logic for updating cells
1225
+ // ...
1226
+ }
1227
+
1228
+ private void updateFiles (List <LinkedFile > linkedFiles ) {
1229
+ // Logic for updating documents
1230
+ // ...
1231
+ }
1177
1232
}
0 commit comments