Search in sources :

Example 1 with CrossRefEntryComparator

use of org.jabref.logic.bibtex.comparator.CrossRefEntryComparator in project jabref by JabRef.

the class BibDatabaseWriter method getSaveComparators.

private static List<Comparator<BibEntry>> getSaveComparators(SavePreferences preferences, MetaData metaData) {
    List<Comparator<BibEntry>> comparators = new ArrayList<>();
    Optional<SaveOrderConfig> saveOrder = getSaveOrder(preferences, metaData);
    // Take care, using CrossRefEntry-Comparator, that referred entries occur after referring
    // ones. This is a necessary requirement for BibTeX to be able to resolve referenced entries correctly.
    comparators.add(new CrossRefEntryComparator());
    if (!saveOrder.isPresent()) {
        // entries will be sorted based on their internal IDs
        comparators.add(new IdComparator());
    } else {
        // use configured sorting strategy
        comparators.add(new FieldComparator(saveOrder.get().sortCriteria[0]));
        comparators.add(new FieldComparator(saveOrder.get().sortCriteria[1]));
        comparators.add(new FieldComparator(saveOrder.get().sortCriteria[2]));
        comparators.add(new FieldComparator(BibEntry.KEY_FIELD));
    }
    return comparators;
}
Also used : CrossRefEntryComparator(org.jabref.logic.bibtex.comparator.CrossRefEntryComparator) IdComparator(org.jabref.logic.bibtex.comparator.IdComparator) ArrayList(java.util.ArrayList) FieldComparator(org.jabref.logic.bibtex.comparator.FieldComparator) FieldComparator(org.jabref.logic.bibtex.comparator.FieldComparator) CrossRefEntryComparator(org.jabref.logic.bibtex.comparator.CrossRefEntryComparator) IdComparator(org.jabref.logic.bibtex.comparator.IdComparator) BibtexStringComparator(org.jabref.logic.bibtex.comparator.BibtexStringComparator) Comparator(java.util.Comparator) SaveOrderConfig(org.jabref.model.metadata.SaveOrderConfig)

Aggregations

ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 BibtexStringComparator (org.jabref.logic.bibtex.comparator.BibtexStringComparator)1 CrossRefEntryComparator (org.jabref.logic.bibtex.comparator.CrossRefEntryComparator)1 FieldComparator (org.jabref.logic.bibtex.comparator.FieldComparator)1 IdComparator (org.jabref.logic.bibtex.comparator.IdComparator)1 SaveOrderConfig (org.jabref.model.metadata.SaveOrderConfig)1