Source:
<code>public void synchronizeLocalDatabase() { if (!checkCurrentConnection()) { return; } List<BibEntry> localEntries = bibDatabase.getEntries(); Map<Integer, Integer> idVersionMap = dbmsProcessor.getSharedIDVersionMapping(); removeNotSharedEntries(localEntries, idVersionMap.keySet()); List<Integer> entriesToDrag = new ArrayList<>(); for (Map.Entry<Integer, Integer> idVersionEntry : idVersionMap.entrySet()) { boolean match = false; for (BibEntry localEntry : localEntries) { if (idVersionEntry.getKey() == localEntry.getSharedBibEntryData().getSharedID()) { match = true; if (idVersionEntry.getValue() > localEntry.getSharedBibEntryData().getVersion()) { Optional<BibEntry> sharedEntry = dbmsProcessor.getSharedEntry(idVersionEntry.getKey()); if (sharedEntry.isPresent()) { localEntry.setType(sharedEntry.get().getType(), EntryEventSource.SHARED); localEntry.getSharedBibEntryData() .setVersion(sharedEntry.get().getSharedBibEntryData().getVersion()); for (Field field : sharedEntry.get().getFields()) { Optional<String> sharedFieldValue = sharedEntry.get().getField(field); <START> if (sharedFieldValue.isPresent()) { <END> localEntry.setField(field, sharedFieldValue.get(), EntryEventSource.SHARED); } } Set<Field> redundantLocalEntryFields = localEntry.getFields(); redundantLocalEntryFields.removeAll(sharedEntry.get().getFields()); for (Field redundantField : redundantLocalEntryFields) { localEntry.clearField(redundantField, EntryEventSource.SHARED); } } } } } if (!match) { entriesToDrag.add(idVersionEntry.getKey()); } } for (BibEntry bibEntry : dbmsProcessor.getSharedEntries(entriesToDrag)) { bibDatabase.insertEntry(bibEntry, EntryEventSource.SHARED); } }</code><technical_language>This a good case for ifPresent lambda, I guess</technical_language>

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