1 | @SuppressWarnings("unchecked") | | 1 | @SuppressWarnings("unchecked") |
2 | public OOCalcDatabase(BibtexDatabase bibtex, Set<String> keySet) { | | 2 | public static List<BibtexEntry> getSortedEntries(BibtexDatabase database, Set<String> keySet, boolean isSaveOperation) { |
3 | // Make a list of comparators for sorting the entries: | | 3 | boolean inOriginalOrder = isSaveOperation ? Globals.prefs.getBoolean("saveInOriginalOrder") : |
4 | List<FieldComparator> comparators = new ArrayList<FieldComparator>(); | | 4 | Globals.prefs.getBoolean("exportInOriginalOrder"); |
5 | comparators.add(new FieldComparator("author")); | | 5 | List<Comparator<BibtexEntry>> comparators; |
6 | comparators.add(new FieldComparator("year")); | | 6 | if (inOriginalOrder) { |
7 | comparators.add(new FieldComparator(BibtexFields.KEY_FIELD)); | | 7 | // Sort entries based on their creation order, utilizing the fact |
8 | // Use glazed lists to get a sorted view of the entries: | | 8 | // that IDs used for entries are increasing, sortable numbers. |
9 | BasicEventList entryList = new BasicEventList(); | | 9 | comparators = new ArrayList<Comparator<BibtexEntry>>(); |
10 | // Set up a list of all entries, if keySet==null, or the entries whose | | 10 | comparators.add(new CrossRefEntryComparator()); |
11 | // ids are in keySet, otherwise: | | 11 | comparators.add(new IdComparator()); |
12 | if (keySet == null) | | 12 | } else { |
13 | entryList.addAll(bibtex.getEntries()); | | 13 | comparators = getSaveComparators(isSaveOperation); |
14 | else { | | 14 | } |
15 | for (String key : keySet) | | 15 | |
16 | entryList.add(bibtex.getEntryById(key)); | | 16 | // Use glazed lists to get a sorted view of the entries: |
17 | } | | 17 | FieldComparatorStack<BibtexEntry> comparatorStack = new FieldComparatorStack<BibtexEntry>(comparators); |
18 | | | 18 | BasicEventList entryList = new BasicEventList(); |
19 | entries = new SortedList(entryList, new FieldComparatorStack(comparators)); | | 19 | SortedList sorter = new SortedList(entryList, comparatorStack); |
20 | | | 20 | |
21 | } | | 21 | if (keySet == null) |
| | | 22 | keySet = database.getKeySet(); |
| | | 23 | |
| | | 24 | if (keySet != null) { |
| | | 25 | Iterator<String> i = keySet.iterator(); |
| | | 26 | |
| | | 27 | for (; i.hasNext();) { |
| | | 28 | sorter.add(database.getEntryById((i.next()))); |
| | | 29 | } |
| | | 30 | } |
| | | 31 | return sorter; |
| | | 32 | } |