difflib.Patch类的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(214)

本文整理了Java中difflib.Patch类的一些代码示例,展示了Patch类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Patch类的具体详情如下:
包路径:difflib.Patch
类名称:Patch

Patch介绍

[英]Describes the patch holding all deltas between the original and revised texts.
[中]描述包含原始文本和修订文本之间所有增量的补丁。

代码示例

代码示例来源:origin: apache/phoenix

/**
 * Do a diff between exported query results and temporary CSV file
 *
 * @param query
 * @param newCSV
 * @return
 */
public boolean doDiff(Query query, String newCSV) {
  List<String> original = fileToLines(getCSVName(query, PherfConstants.EXPORT_DIR, ""));
  List<String> newLines = fileToLines(newCSV);
  Patch patch = DiffUtils.diff(original, newLines);
  if (patch.getDeltas().isEmpty()) {
    logger.info("Match: " + query.getId() + " with " + newCSV);
    return true;
  } else {
    logger.error("DIFF FAILED: " + query.getId() + " with " + newCSV);
    return false;
  }
}

代码示例来源:origin: stackoverflow.com

Patch patch = new Patch();
patch.setPath("/");
patch.setValue(value);
patch.setOp("replace");

代码示例来源:origin: com.custardsource.dybdob/java-diff-utils-copy

/**
 * 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);
}

代码示例来源:origin: com.qulice/qulice-xml

/**
   * Remove unwanted deltas.
   * @param diff Patch to filter.
   * @return Patch with unwanted deltas removed.
   * @todo #469:30min Remove the method below and find a way to format tags
   *  correctly in XML. Attributes should be indented by 4 spaces, just like
   *  XML tags, but in IT xml-violations there is a tag that our Prettifier
   *  want to be indented by 3 spaces which is wrong. Another problem is
   *  that in the parent tag, attributes are indented to match the first
   *  attribute, this is also wrong - all attributes on new line should be
   *  indented by 4 spaces.
   */
  private static Patch filter(final Patch diff) {
    final Patch patch = new Patch();
    for (final Delta delta : diff.getDeltas()) {
      final List<?> prev = delta.getOriginal().getLines();
      if (
        prev.size() != 1 || delta.getRevised().getLines().size() != 1
          || !XmlValidator.ATTRS_PATTERN
            .matcher(prev.get(0).toString()).matches()
        ) {
        patch.addDelta(delta);
      }
    }
    return patch;
  }
}

代码示例来源:origin: com.custardsource.dybdob/java-diff-utils-copy

for (int i = 0; i < patch.getDeltas().size(); i++) {
  Delta delta = patch.getDelta(i);
  Chunk orig = delta.getOriginal();
  Chunk rev = delta.getRevised();

代码示例来源:origin: com.googlecode.java-diff-utils/diffutils

boolean inPrelude = true;
List<String[]> rawChunk = new ArrayList<String[]>();
Patch<String> patch = new Patch<String>();
      patch.addDelta(new ChangeDelta<String>(new Chunk<String>(
          old_ln - 1, oldChunkLines), new Chunk<String>(
          new_ln - 1, newChunkLines)));
  patch.addDelta(new ChangeDelta<String>(new Chunk<String>(
      old_ln - 1, oldChunkLines), new Chunk<String>(new_ln - 1,
      newChunkLines)));

代码示例来源:origin: stackoverflow.com

pArray -> Arrays.parallelSetAll(pArray, i -> new Patch())

代码示例来源:origin: com.custardsource.dybdob/java-diff-utils-copy

boolean inPrelude = true;
List<Object[]> rawChunk = new ArrayList<Object[]>();
Patch patch = new Patch();
      patch.addDelta(new ChangeDelta(new Chunk(old_ln - 1, old_n, oldChunkLines),
          new Chunk(new_ln - 1, new_n, newChunkLines)));
      rawChunk.clear();
  patch.addDelta(new ChangeDelta(new Chunk(old_ln - 1, old_n, oldChunkLines), new Chunk(
      new_ln - 1, new_n, newChunkLines)));
  rawChunk.clear();

代码示例来源:origin: stackoverflow.com

Arrays.stream(patches)
   .forEach(pArray -> Arrays.parallelSetAll(pArray, i -> new Patch()));

代码示例来源:origin: com.quinsoft.zeidon/zeidon-joe

boolean areEqual()
{
  return patch.getDeltas().size() == 0;
}

代码示例来源:origin: com.googlecode.java-diff-utils/diffutils

throw new IllegalArgumentException("revised sequence is null");
Patch<T> patch = new Patch<T>();
if (path.isSnake())
  path = path.prev;
  patch.addDelta(delta);
  if (path.isSnake())
    path = path.prev;

代码示例来源:origin: com.googlecode.java-diff-utils/diffutils

/**
 * {@inheritDoc}
 *
 * Return empty diff if get the error while procession the difference.
 */
public Patch<T> diff(final List<T> original, final List<T> revised) {
  if (original == null) {
    throw new IllegalArgumentException("original list must not be null");
  }
  if (revised == null) {
    throw new IllegalArgumentException("revised list must not be null");
  }
  PathNode path;
  try {
    path = buildPath(original, revised);
    return buildRevision(path, original, revised);
  } catch (DifferentiationFailedException e) {
    e.printStackTrace();
  }
  return new Patch<T>();
}

代码示例来源:origin: com.googlecode.java-diff-utils/diffutils

/**
 * 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 <T> List<T> patch(List<T> original, Patch<T> patch)
    throws PatchFailedException {
  return patch.applyTo(original);
}

代码示例来源:origin: ru.lanwen.diff/uri-differ-lib

@SuppressWarnings("unchecked")
private List<Delta> diffDeltas(List<String> original, List<String> revised) {
  return (List) DiffUtils.diff(original, revised).getDeltas();
}

代码示例来源:origin: com.custardsource.dybdob/java-diff-utils-copy

throw new IllegalArgumentException("revised sequence is null");
Patch patch = new Patch();
if (path.isSnake())
  path = path.prev;
  patch.addDelta(delta);
  if (path.isSnake())
    path = path.prev;

代码示例来源:origin: com.custardsource.dybdob/java-diff-utils-copy

/**
 * {@inheritDoc}
 * 
 * Return empty diff if get the error while procession the difference.
 */
@Override
public Patch diff(Object[] orig, Object[] rev) {
  PathNode path;
  try {
    path = buildPath(orig, rev);
    return buildRevision(path, orig, rev);
  } catch (DifferentiationFailedException e) {
    e.printStackTrace();
  }
  return new Patch();
}

代码示例来源:origin: line/centraldogma

@Test
public void testTextPatches() throws PatchFailedException {
  final String oriStr = "1\n2\n3\n4\n5\n6\n7\n8\n9";
  final String newStr = "1a\n2\n3\n4\n5\n6\n7\n8\n9a";
  final String expectedUnifiedDiff = "--- /text_file.txt\n" +
                    "+++ /text_file.txt\n" +
                    "@@ -1,4 +1,4 @@\n" +
                    "-1\n" +
                    "+1a\n" +
                    " 2\n" +
                    " 3\n" +
                    " 4\n" +
                    "@@ -6,4 +6,4 @@\n" +
                    " 6\n" +
                    " 7\n" +
                    " 8\n" +
                    "-9\n" +
                    "+9a";
  final Change<String> change = Change.ofTextPatch("/text_file.txt", oriStr, newStr);
  assertEquals(expectedUnifiedDiff, change.content());
  final Patch<String> patch = DiffUtils.parseUnifiedDiff(Util.stringToLines(change.content()));
  final String patchedStr = String.join("\n", patch.applyTo(Util.stringToLines(oriStr)));
  assertEquals(newStr, patchedStr);
}

代码示例来源:origin: com.googlecode.java-diff-utils/diffutils

/**
 * Apply this patch to the given target
 * @return the patched text
 * @throws PatchFailedException if can't apply patch
 */
public List<T> applyTo(List<T> target) throws PatchFailedException {
  List<T> result = new LinkedList<T>(target);
  ListIterator<Delta<T>> it = getDeltas().listIterator(deltas.size());
  while (it.hasPrevious()) {
    Delta<T> delta = (Delta<T>) it.previous();
    delta.applyTo(result);
  }
  return result;
}

代码示例来源:origin: stackoverflow.com

import java.util.function.IntFunction;

public class PatchArrayGenerator implements IntFunction<Patch[]>
{
  private final int depth;

  public PatchArrayGenerator(int depth)
  {
    this.depth = depth;
  }

  public Patch[] apply(int value)
  {
    Patch[] patchArray = new Patch[depth];
    Arrays.parallelSetAll(patchArray, value -> new Patch());
    return patchArray;
  }
}

public class PatchMaker
{     
  public static void main(String... args)
  {
    int depth = 5, width = 5;
    Patch[][] patches = new Patch[width][depth];
    Arrays.parallelSetAll(patches, new PatchArrayGenerator(depth));
  }
}

代码示例来源:origin: com.googlecode.java-diff-utils/diffutils

/**
 * Restore the text to original. Opposite to applyTo() method.
 * @param target the given target
 * @return the restored text
 */
public List<T> restore(List<T> target) {
  List<T> result = new LinkedList<T>(target);
  ListIterator<Delta<T>> it = getDeltas().listIterator(deltas.size());
  while (it.hasPrevious()) {
    Delta<T> delta = (Delta<T>) it.previous();
    delta.restore(result);
  }
  return result;
}

相关文章