String rangeClientName = null;
VectorClock rangeVersionFrom = null;
VectorClock rangeVersionTo = null;
for (int i=0; i<winnersApplyBranchList.size(); i++) {
DatabaseVersionHeader currentDatabaseVersionHeader = winnersApplyBranchList.get(i);
DatabaseVersionHeader nextDatabaseVersionHeader = (i+1 < winnersApplyBranchList.size()) ? winnersApplyBranchList.get(i+1) : null;
// First of range for this client
if (rangeClientName == null) {
rangeClientName = currentDatabaseVersionHeader.getClient();
rangeVersionFrom = currentDatabaseVersionHeader.getVectorClock();
rangeVersionTo = currentDatabaseVersionHeader.getVectorClock();
}
// Still in range for this client
else {
rangeVersionTo = currentDatabaseVersionHeader.getVectorClock();
}
// Now load this stuff from the database file (or not)
// - If the database file exists, load the range and reset it
// - If not, only force a load if this is the range end
File databaseVersionFile = databaseFileList.getExactDatabaseVersionFile(currentDatabaseVersionHeader);
if (databaseVersionFile != null) {
databaseSerializer.load(winnerBranchDatabase, databaseVersionFile, rangeVersionFrom, rangeVersionTo, DatabaseReadType.FULL, filterType, ignoredMostRecentPurgeVersions);
rangeClientName = null;
}
else {
boolean lastDatabaseVersionHeader = nextDatabaseVersionHeader == null;
boolean nextClientIsDifferent = !lastDatabaseVersionHeader && !currentDatabaseVersionHeader.getClient().equals(nextDatabaseVersionHeader.getClient());
boolean rangeEnds = lastDatabaseVersionHeader || nextClientIsDifferent;
if (rangeEnds) {
databaseVersionFile = databaseFileList.getNextDatabaseVersionFile(currentDatabaseVersionHeader);