Source:
public void synchronizeLocalDatabase() { if (!checkCurrentConnection()) { return; } List<BibEntry> localEntries = bibDatabase.getEntries(); Map<Integer, Integer> idVersionMap = dbmsProcessor.getSharedIDVersionMapping(); removeNotSharedEntries(localEntries, idVersionMap.keySet()); List<Integer> entriesToInsertIntoLocalDatabase = new ArrayList<>(); for (Map.Entry<Integer, Integer> idVersionEntry : idVersionMap.entrySet()) { boolean remoteEntryMatchingOneLocalEntryFound = false; for (BibEntry localEntry : localEntries) { if (idVersionEntry.getKey().equals(localEntry.getSharedBibEntryData().getSharedID())) { remoteEntryMatchingOneLocalEntryFound = true; if (idVersionEntry.getValue() > localEntry.getSharedBibEntryData().getVersion()) { Optional<BibEntry> sharedEntry = dbmsProcessor.getSharedEntry(idVersionEntry.getKey()); if (sharedEntry.isPresent()) { localEntry.setType(sharedEntry.get().getType(), EntriesEventSource.SHARED); localEntry.getSharedBibEntryData() .setVersion(sharedEntry.get().getSharedBibEntryData().getVersion()); sharedEntry.get().getFieldMap().forEach( (field, value) -> localEntry.setField(field, value, EntriesEventSource.SHARED) ); localEntry.getFields().stream() .filter(field -> !sharedEntry.get().hasField(field)) .forEach( field -> localEntry.clearField(field, EntriesEventSource.SHARED) ); } } } } if (!remoteEntryMatchingOneLocalEntryFound) { entriesToInsertIntoLocalDatabase.add(idVersionEntry.getKey()); } } if (!entriesToInsertIntoLocalDatabase.isEmpty()) { for (BibEntry bibEntry : dbmsProcessor.getSharedEntries(entriesToInsertIntoLocalDatabase)) { bibDatabase.insertEntry(bibEntry, EntriesEventSource.SHARED); } } }

Target:
public void synchronizeLocalDatabase() { if (!checkCurrentConnection()) { return; } List<BibEntry> localEntries = bibDatabase.getEntries(); Map<Integer, Integer> idVersionMap = dbmsProcessor.getSharedIDVersionMapping(); removeNotSharedEntries(localEntries, idVersionMap.keySet()); List<Integer> entriesToInsertIntoLocalDatabase = new ArrayList<>(); for (Map.Entry<Integer, Integer> idVersionEntry : idVersionMap.entrySet()) { boolean remoteEntryMatchingOneLocalEntryFound = false; for (BibEntry localEntry : localEntries) { if (idVersionEntry.getKey().equals(localEntry.getSharedBibEntryData().getSharedID())) { remoteEntryMatchingOneLocalEntryFound = true; if (idVersionEntry.getValue() > localEntry.getSharedBibEntryData().getVersion()) { Optional<BibEntry> sharedEntry = dbmsProcessor.getSharedEntry(idVersionEntry.getKey()); if (sharedEntry.isPresent()) { localEntry.setType(sharedEntry.get().getType(), EntriesEventSource.SHARED); localEntry.getSharedBibEntryData() .setVersion(sharedEntry.get().getSharedBibEntryData().getVersion()); sharedEntry.get().getFieldMap().forEach( (field, value) -> localEntry.setField(field, value, EntriesEventSource.SHARED) ); localEntry.getFields().stream() .filter(field -> !sharedEntry.get().hasField(field)) .forEach( field -> localEntry.clearField(field, EntriesEventSource.SHARED) ); } } } } if (!remoteEntryMatchingOneLocalEntryFound) { entriesToInsertIntoLocalDatabase.add(idVersionEntry.getKey()); } } if (!entriesToInsertIntoLocalDatabase.isEmpty()) { bibDatabase.insertEntries(dbmsProcessor.getSharedEntries(entriesToInsertIntoLocalDatabase), EntriesEventSource.SHARED); } }