/** * Constructs a {@link WaveletAndDeltas} from wavelet data and a tail of the * sequence of transformed deltas leading to that snapshot. Takes a copy of * the WaveletData so that operations can happily applied to it. * * The resulting version of the last delta must match the snapshot's version. * * @param snapshot the state of the wavelet after the deltas have been * applied. * @param deltas the deltas in the order they have been applied to the * wavelet. * @throws OperationException if the operations can not be rolled back to * create a snapshot before the deltas have been applied. */ public static WaveletAndDeltas create(ReadableWaveletData snapshot, DeltaSequence deltas) throws OperationException { HashedVersion endVersion = deltas.isEmpty() ? snapshot.getHashedVersion() : deltas.getEndVersion(); Preconditions.checkArgument(snapshot.getVersion() == endVersion.getVersion(), String.format("Version of snapshot %s doesn't match the end version %s", snapshot.getVersion(), endVersion)); ObservableWaveletData preDeltaWavelet = WaveletDataUtil.copyWavelet(snapshot); rollback(preDeltaWavelet, deltas); ObservableWaveletData postDeltaWavelet = WaveletDataUtil.copyWavelet(snapshot); return new WaveletAndDeltas(preDeltaWavelet, postDeltaWavelet, deltas); }