List<IndexEntry> bkwdEntries = null;
if (addedLinks.size() > 0) {
fwdEntries = new ArrayList<IndexEntry>(Math.max(addedLinks.size(), removedLinks.size()));
bkwdEntries = new ArrayList<IndexEntry>(fwdEntries.size());
for (FieldedLink link : addedLinks) {
IndexEntry fwdEntry = createForwardIndexEntry(vtag, sourceRecord, link.getFieldTypeId());
fwdEntry.setIdentifier(link.getAbsoluteRecordId().toBytes());
fwdEntries.add(fwdEntry);
IndexEntry bkwdEntry = createBackwardIndexEntry(vtag, link.getAbsoluteRecordId(), link.getFieldTypeId());
bkwdEntry.setIdentifier(sourceAsBytes);
bkwdEntries.add(bkwdEntry);
}
forwardIndex.addEntries(fwdEntries);
backwardIndex.addEntries(bkwdEntries);
}
// Apply removed links
if (removedLinks.size() > 0) {
if (fwdEntries != null) {
fwdEntries.clear();
bkwdEntries.clear();
} else {
fwdEntries = new ArrayList<IndexEntry>(removedLinks.size());
bkwdEntries = new ArrayList<IndexEntry>(fwdEntries.size());
}
for (FieldedLink link : removedLinks) {
IndexEntry bkwdEntry = createBackwardIndexEntry(vtag, link.getAbsoluteRecordId(), link.getFieldTypeId());
bkwdEntry.setIdentifier(sourceAsBytes);
bkwdEntries.add(bkwdEntry);
IndexEntry fwdEntry = createForwardIndexEntry(vtag, sourceRecord, link.getFieldTypeId());
fwdEntry.setIdentifier(link.getAbsoluteRecordId().toBytes());
fwdEntries.add(fwdEntry);
}
backwardIndex.removeEntries(bkwdEntries);
forwardIndex.removeEntries(fwdEntries);
}