Skip to content

Commit b17bbb1

Browse files
committed
fixes #115
1 parent 57df629 commit b17bbb1

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

java-diff-utils/src/main/java/com/github/difflib/patch/AbstractDelta.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public DeltaType getType() {
5454
* @param target
5555
* @throws PatchFailedException
5656
*/
57-
protected void verifyChunk(List<T> target) throws PatchFailedException {
58-
getSource().verify(target);
57+
protected VerifyChunk verifyChunkToFitTarget(List<T> target) throws PatchFailedException {
58+
return getSource().verifyChunk(target);
5959
}
6060

6161
public abstract void applyTo(List<T> target) throws PatchFailedException;

java-diff-utils/src/main/java/com/github/difflib/patch/Chunk.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,16 @@ public Chunk(int position, T[] lines) {
9292
* @param target the sequence to verify against.
9393
* @throws com.github.difflib.patch.PatchFailedException
9494
*/
95-
public void verify(List<T> target) throws PatchFailedException {
95+
public VerifyChunk verifyChunk(List<T> target) throws PatchFailedException {
9696
if (position > target.size() || last() > target.size()) {
97-
throw new PatchFailedException("Incorrect Chunk: the position of chunk > target size");
97+
return VerifyChunk.POSITION_OUT_OF_TARGET;
9898
}
9999
for (int i = 0; i < size(); i++) {
100100
if (!target.get(position + i).equals(lines.get(i))) {
101-
throw new PatchFailedException(
102-
"Incorrect Chunk: the chunk content doesn't match the target");
101+
return VerifyChunk.CONTENT_DOES_NOT_MATCH_TARGET;
103102
}
104103
}
104+
return VerifyChunk.OK;
105105
}
106106

107107
/**
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2021 java-diff-utils.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.github.difflib.patch;
17+
18+
/**
19+
*
20+
* @author tw
21+
*/
22+
public enum VerifyChunk {
23+
OK,
24+
POSITION_OUT_OF_TARGET,
25+
CONTENT_DOES_NOT_MATCH_TARGET
26+
}

0 commit comments

Comments
 (0)