private static Map<PrimaryRowColumn, List<Entry<Key, Value>>> groupLocksByPrimary(
List<Entry<Key, Value>> locks) {
Map<PrimaryRowColumn, List<Entry<Key, Value>>> groupedLocks = new HashMap<>();
Map<PrimaryRowColumn, Long> transactorIds = new HashMap<>();
for (Entry<Key, Value> lock : locks) {
LockValue lockVal = new LockValue(lock.getValue().get());
PrimaryRowColumn prc =
new PrimaryRowColumn(lockVal.getPrimaryRow(), lockVal.getPrimaryColumn(), lock.getKey()
.getTimestamp() & ColumnConstants.TIMESTAMP_MASK);
List<Entry<Key, Value>> lockList = groupedLocks.get(prc);
if (lockList == null) {
lockList = new ArrayList<>();
groupedLocks.put(prc, lockList);
}
Long trid = transactorIds.get(prc);
if (trid == null) {
transactorIds.put(prc, lockVal.getTransactor());
} else if (!trid.equals(lockVal.getTransactor())) {
throw new IllegalStateException("transactor ids not equals " + prc + " " + lock.getKey()
+ " " + trid + " " + lockVal.getTransactor());
}
lockList.add(lock);
}
return groupedLocks;
}