/** * Lookups record by mutation id, if it's found removes it from the history and invalidates snapshot record. * Snapshot record is superposition of all record versions in the history. */ Set<String> revert(UUID mutationId) { int recordIndex = -1; for (int i = 0; i < history.size(); i++) { if (mutationId.equals(history.get(i).mutationId())) { recordIndex = i; break; } } if (recordIndex == -1) { return Collections.emptySet(); } Set<String> changedKeys = new HashSet<>(); changedKeys.add(history.remove(recordIndex).key()); for (int i = Math.max(0, recordIndex - 1); i < history.size(); i++) { Record record = history.get(i); if (i == Math.max(0, recordIndex - 1)) { snapshot = record.clone(); } else { changedKeys.addAll(snapshot.mergeWith(record)); } } return changedKeys; } }
/** * Lookups record by mutation id, if it's found removes it from the history and invalidates snapshot record. * Snapshot record is superposition of all record versions in the history. */ Set<String> revert(UUID mutationId) { int recordIndex = -1; for (int i = 0; i < history.size(); i++) { if (mutationId.equals(history.get(i).mutationId())) { recordIndex = i; break; } } if (recordIndex == -1) { return Collections.emptySet(); } Set<String> changedKeys = new HashSet<>(); changedKeys.add(history.remove(recordIndex).key()); for (int i = Math.max(0, recordIndex - 1); i < history.size(); i++) { Record record = history.get(i); if (i == Math.max(0, recordIndex - 1)) { snapshot = record.clone(); } else { changedKeys.addAll(snapshot.mergeWith(record)); } } return changedKeys; } }
/** * Lookups record by mutation id, if it's found removes it from the history and invalidates snapshot record. * Snapshot record is superposition of all record versions in the history. */ Set<String> revert(UUID mutationId) { int recordIndex = -1; for (int i = 0; i < history.size(); i++) { if (mutationId.equals(history.get(i).mutationId())) { recordIndex = i; break; } } if (recordIndex == -1) { return Collections.emptySet(); } Set<String> changedKeys = new HashSet<>(); changedKeys.add(history.remove(recordIndex).key()); for (int i = Math.max(0, recordIndex - 1); i < history.size(); i++) { Record record = history.get(i); if (i == Math.max(0, recordIndex - 1)) { snapshot = record.clone(); } else { changedKeys.addAll(snapshot.mergeWith(record)); } } return changedKeys; } }