Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Added ability to apply patch to existing list inplace#152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
wumpz merged 3 commits intojava-diff-utils:masterfromandre161292:feature/apply-to-original-collection
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -58,7 +58,7 @@ protected VerifyChunk verifyChunkToFitTarget(List<T> target) throws PatchFailedE
return getSource().verifyChunk(target);
}

protected VerifyChunkverifyAntApplyTo(List<T> target) throws PatchFailedException {
protected VerifyChunkverifyAndApplyTo(List<T> target) throws PatchFailedException {
final VerifyChunk verify = verifyChunkToFitTarget(target);
if (verify == VerifyChunk.OK) {
applyTo(target);
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,22 +48,35 @@ public Patch(int estimatedPatchSize) {
}

/**
*Apply this patch to thegiven target
*Creates a new list, thepatch is being applied to.
*
* @return the patched text
* @throws PatchFailedException if can't apply patch
* @param target The list to apply the changes to.
* @return A new list containing the applied patch.
* @throws PatchFailedException if the patch cannot be applied
*/
public List<T> applyTo(List<T> target) throws PatchFailedException {
List<T> result = new ArrayList<>(target);
applyToExisting(result);
return result;
}

/**
* Applies the patch to the supplied list.
*
* @param target The list to apply the changes to. This list has to be modifiable,
* otherwise exceptions may be thrown, depending on the used type of list.
* @throws PatchFailedException if the patch cannot be applied
* @throws RuntimeException (or similar) if the list is not modifiable.
*/
public void applyToExisting(List<T> target) throws PatchFailedException {
ListIterator<AbstractDelta<T>> it = getDeltas().listIterator(deltas.size());
while (it.hasPrevious()) {
AbstractDelta<T> delta = it.previous();
VerifyChunk valid = delta.verifyAntApplyTo(result);
VerifyChunk valid = delta.verifyAndApplyTo(target);
if (valid != VerifyChunk.OK) {
conflictOutput.processConflict(valid, delta,result);
conflictOutput.processConflict(valid, delta,target);
}
}
return result;
}

private static class PatchApplyingContext<T> {
Expand DownExpand Up@@ -220,19 +233,33 @@ public Patch withConflictOutput(ConflictOutput<T> conflictOutput) {
}

/**
* Restore the text to original. Opposite to applyTo() method.
* Creates a new list, containing the restored state of the given list.
* Opposite to {@link #applyTo(List)} method.
*
* @param targetthe given target
* @return the restoredtext
* @param targetThe list to copy and apply changes to.
* @returnA new list, containingthe restoredstate.
*/
public List<T> restore(List<T> target) {
List<T> result = new ArrayList<>(target);
restoreToExisting(result);
return result;
}


/**
* Restores all changes within the given list.
* Opposite to {@link #applyToExisting(List)} method.
*
* @param target The list to restore changes in. This list has to be modifiable,
* otherwise exceptions may be thrown, depending on the used type of list.
* @throws RuntimeException (or similar) if the list is not modifiable.
*/
public void restoreToExisting(List<T> target) {
ListIterator<AbstractDelta<T>> it = getDeltas().listIterator(deltas.size());
while (it.hasPrevious()) {
AbstractDelta<T> delta = it.previous();
delta.restore(result);
delta.restore(target);
}
return result;
}

/**
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp