Search in sources :

Example 1 with BibtexStringComparator

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

the class BibDatabaseWriter method writeStrings.

/**
     * Write all strings in alphabetical order, modified to produce a safe (for
     * BibTeX) order of the strings if they reference each other.
     *
     * @param database The database whose strings we should write.
     */
private void writeStrings(BibDatabase database, Boolean reformatFile, LatexFieldFormatterPreferences latexFieldFormatterPreferences) throws SaveException {
    List<BibtexString> strings = database.getStringKeySet().stream().map(database::getString).collect(Collectors.toList());
    strings.sort(new BibtexStringComparator(true));
    // First, make a Map of all entries:
    Map<String, BibtexString> remaining = new HashMap<>();
    int maxKeyLength = 0;
    for (BibtexString string : strings) {
        remaining.put(string.getName(), string);
        maxKeyLength = Math.max(maxKeyLength, string.getName().length());
    }
    for (BibtexString.Type t : BibtexString.Type.values()) {
        boolean isFirstStringInType = true;
        for (BibtexString bs : strings) {
            if (remaining.containsKey(bs.getName()) && (bs.getType() == t)) {
                writeString(bs, isFirstStringInType, remaining, maxKeyLength, reformatFile, latexFieldFormatterPreferences);
                isFirstStringInType = false;
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) BibtexString(org.jabref.model.entry.BibtexString) BibtexStringComparator(org.jabref.logic.bibtex.comparator.BibtexStringComparator) BibtexString(org.jabref.model.entry.BibtexString)

Example 2 with BibtexStringComparator

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

the class StringDialog method sortStrings.

private void sortStrings() {
    // Rebuild our sorted set of strings:
    strings = new ArrayList<>();
    for (String s : base.getStringKeySet()) {
        strings.add(base.getString(s));
    }
    Collections.sort(strings, new BibtexStringComparator(false));
}
Also used : UndoableRemoveString(org.jabref.gui.undo.UndoableRemoveString) UndoableInsertString(org.jabref.gui.undo.UndoableInsertString) BibtexString(org.jabref.model.entry.BibtexString) BibtexStringComparator(org.jabref.logic.bibtex.comparator.BibtexStringComparator)

Aggregations

BibtexStringComparator (org.jabref.logic.bibtex.comparator.BibtexStringComparator)2 BibtexString (org.jabref.model.entry.BibtexString)2 HashMap (java.util.HashMap)1 UndoableInsertString (org.jabref.gui.undo.UndoableInsertString)1 UndoableRemoveString (org.jabref.gui.undo.UndoableRemoveString)1