Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
Copyright 2010 Dmitry Naumenko ([email protected])
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package difflib;
import difflib.myers.MyersDiff;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Implements the difference and patching engine
*
* @author Dmitry Naumenko
* @version 0.4.1
*/
public class DiffUtils {
private static DiffAlgorithm defaultDiffAlgorithm = new MyersDiff();
private static Pattern unifiedDiffChunkRe =
Pattern.compile("^@@\\s+-(?:(\\d+)(?:,(\\d+))?)\\s+\\+(?:(\\d+)(?:,(\\d+))?)\\s+@@$");
/**
* Compute the difference between the original and revised texts with default diff algorithm
*
* @param original the original text
* @param revised the revised text
* @return the patch describing the difference between the original and revised texts
*/
public static Patch diff(List> original, List> revised) {
return DiffUtils.diff(original, revised, defaultDiffAlgorithm);
}
/**
* Compute the difference between the original and revised texts with given diff algorithm
*
* @param original the original text
* @param revised the revised text
* @param algorithm the given algorithm
* @return the patch describing the difference between the original and revised texts
*/
public static Patch diff(List> original, List> revised, DiffAlgorithm algorithm) {
return algorithm.diff(original, revised);
}
/**
* Patch the original text with given patch
*
* @param original the original text
* @param patch the given patch
* @return the revised text
* @throws PatchFailedException if can't apply patch
*/
public static List> patch(List> original, Patch patch) throws PatchFailedException {
return patch.applyTo(original);
}
/**
* Unpatch the revised text for a given patch
*
* @param revised the revised text
* @param patch the given patch
* @return the original text
*/
public static List> unpatch(List> revised, Patch patch) {
return patch.restore(revised);
}
/**
* Parse the given text in unified format and creates the list of deltas for it.
*
* @param diff the text in unified format
* @return the patch with deltas.
*/
public static Patch parseUnifiedDiff(List diff) {
boolean inPrelude = true;
List