Source:
public Map<String, Map<Diff, Set<TObject>>> diffRecordStartEnd(long record, long start, long end, AccessToken creds, TransactionToken transaction, String environment) throws TSecurityException, TTransactionException, TException { PrettyLinkedTableMap<String, Diff, Set<TObject>> result = PrettyLinkedTableMap .newPrettyLinkedTableMap(); result.setRowName("Value"); Map<String, Set<TObject>> startBrowse = selectRecordTime(record, start, creds, transaction, environment); Map<String, Set<TObject>> endBrowse = selectRecordTime(record, end, creds, transaction, environment); Set<String> startBrowseKeySet = startBrowse.keySet(); Set<String> endBrowseKeySet = endBrowse.keySet(); Set<String> xor = Sets.symmetricDifference(startBrowseKeySet, endBrowseKeySet); Set<String> intersection = Sets.intersection(startBrowseKeySet, endBrowseKeySet); for (String current : xor) { if(!startBrowseKeySet.contains(current)) result.put(current, Diff.ADDED, endBrowse.get(current)); else { result.put(current, Diff.REMOVED, startBrowse.get(current)); } } for (String currentKey : intersection) { Set<TObject> startValue = startBrowse.get(currentKey); Set<TObject> endValue = endBrowse.get(currentKey); Set<TObject> xorValue = Sets.symmetricDifference(startValue, endValue); for (TObject currentValue : xorValue) { if(!startValue.contains(currentValue)) result.put(currentKey, Diff.ADDED, Sets.newHashSet(currentValue)); else { result.put(currentKey, Diff.REMOVED, Sets.newHashSet(currentValue)); } } } return result; }

Target:
public Map<String, Map<Diff, Set<TObject>>> diffRecordStartEnd(long record, long start, long end, AccessToken creds, TransactionToken transaction, String environment) throws TException { checkAccess(creds, transaction); try { Compoundable store = getStore(transaction, environment); Map<String, Map<Diff, Set<TObject>>> result = Maps .newLinkedHashMap(); AtomicOperation atomic = null; Map<String, Set<TObject>> startBrowse = null; Map<String, Set<TObject>> endBrowse = null; while (atomic == null || !atomic.commit()) { atomic = store.startAtomicOperation(); try { startBrowse = store.select(record, start); endBrowse = store.select(record, end); } catch (AtomicStateException e) { atomic = null; } } Set<String> startBrowseKeySet = startBrowse.keySet(); Set<String> endBrowseKeySet = endBrowse.keySet(); Set<String> xor = Sets.symmetricDifference(startBrowseKeySet, endBrowseKeySet); Set<String> intersection = Sets.intersection(startBrowseKeySet, endBrowseKeySet); for (String current : xor) { Map<Diff, Set<TObject>> entry = Maps.newHashMap(); if(!startBrowseKeySet.contains(current)) { entry.put(Diff.ADDED, endBrowse.get(current)); result.put(current, entry); } else { entry.put(Diff.REMOVED, endBrowse.get(current)); result.put(current, entry); } } for (String currentKey : intersection) { Set<TObject> startValue = startBrowse.get(currentKey); Set<TObject> endValue = endBrowse.get(currentKey); Set<TObject> xorValue = Sets.symmetricDifference(startValue, endValue); for (TObject currentValue : xorValue) { Map<Diff, Set<TObject>> entry = Maps.newHashMap(); if(!startValue.contains(currentValue)) { entry.put(Diff.ADDED, Sets.newHashSet(currentValue)); result.put(currentKey, entry); } else { entry.put(Diff.REMOVED, Sets.newHashSet(currentValue)); result.put(currentKey, entry); } } } return result; } catch (TransactionStateException e) { throw new TTransactionException(); } }