forked from JabRef/jabref
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
173 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 0 additions & 76 deletions
76
.../java/org/jabref/logic/quality/consistency/PaperConsistencyCheckResultMarkdownWriter.java
This file was deleted.
Oops, something went wrong.
85 changes: 85 additions & 0 deletions
85
src/main/java/org/jabref/logic/quality/consistency/PaperConsistencyCheckResultTxtWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package org.jabref.logic.quality.consistency; | ||
|
||
import java.io.IOException; | ||
import java.io.Writer; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import org.jabref.model.database.BibDatabaseMode; | ||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.model.entry.BibEntryTypesManager; | ||
import org.jabref.model.entry.field.Field; | ||
|
||
/** | ||
* Outputs the findings as plain text. | ||
* <p> | ||
* The symbols from {@link PaperConsistencyCheckResultWriter} are used. | ||
*/ | ||
public class PaperConsistencyCheckResultTxtWriter extends PaperConsistencyCheckResultWriter { | ||
|
||
private List<Integer> columnWidths; | ||
|
||
public PaperConsistencyCheckResultTxtWriter(PaperConsistencyCheck.Result result, Writer writer) { | ||
super(result, writer); | ||
initializeColumnWidths(); | ||
} | ||
|
||
public PaperConsistencyCheckResultTxtWriter(PaperConsistencyCheck.Result result, Writer writer, BibEntryTypesManager entryTypesManager, BibDatabaseMode bibDatabaseMode) { | ||
super(result, writer, entryTypesManager, bibDatabaseMode); | ||
initializeColumnWidths(); | ||
} | ||
|
||
public void writeFindings() throws IOException { | ||
writer.write("Paper Consistency Check Result\n\n"); | ||
writer.write(allFieldNames.stream().collect(Collectors.joining(" | ", "", "\n"))); | ||
writer.write(columnWidths.stream().map(width -> "-".repeat(width)).collect(Collectors.joining(" | ", "| ", " | \n"))); | ||
super.writeFindings(); | ||
} | ||
|
||
private void initializeColumnWidths() { | ||
columnWidths = new ArrayList<>(allFieldNames.size() + 2); | ||
|
||
Integer max = getColumnWidthOfEntryTypes(); | ||
columnWidths.add(max); | ||
|
||
max = getColumnWidthOfCitationKeys(max); | ||
columnWidths.add(max); | ||
|
||
columnWidths.addAll(allFieldNames.stream().map(String::length).toList()); | ||
} | ||
|
||
private Integer getColumnWidthOfEntryTypes() { | ||
Integer max = result.entryTypeToResultMap().keySet() | ||
.stream() | ||
.map(entryType -> entryType.getDisplayName().length()) | ||
.max(Integer::compareTo) | ||
.get(); | ||
max = Math.max(max, "entry type".length()); | ||
return max; | ||
} | ||
|
||
private Integer getColumnWidthOfCitationKeys(Integer max) { | ||
result.entryTypeToResultMap().values() | ||
.stream() | ||
.flatMap(entryTypeResult -> entryTypeResult.sortedEntries().stream()) | ||
.map(entry -> entry.getCitationKey().orElse("").length()) | ||
.max(Integer::compareTo) | ||
.get(); | ||
return Math.max(max, "citation key".length()); | ||
} | ||
|
||
@Override | ||
protected void writeBibEntry(BibEntry bibEntry, String entryType, Set<Field> requiredFields, Set<Field> optionalFields) throws IOException { | ||
List<String> theRecord = getFindingsAsList(bibEntry, entryType, requiredFields, optionalFields); | ||
String output = theRecord.stream() | ||
.map(string -> String.format("%-" + columnWidths.get(theRecord.indexOf(string)) + "s", string)) | ||
.collect(Collectors.joining(" | ", "| ", " |\n")); | ||
writer.write(output); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.