difflib.Patch.getDeltas()方法的使用及代码示例

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

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

Patch.getDeltas介绍

[英]Get the list of computed deltas
[中]获取计算的增量列表

代码示例

代码示例来源: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: com.quinsoft.zeidon/zeidon-joe

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

代码示例来源: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.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: 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;
}

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

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

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

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

代码示例来源:origin: dkpro/dkpro-jwpl

/**
 * Returns the deltas between beforeText and afterText as a line separated String
 * using delta.toString()
 * For more detailed diffs, use getPatch() or getUnifiedDiffStrings()
 *
 * @return diffs as line-separated String using delta.toString()
 */
public String getSimpleDiffString() {
  StringBuilder deltas = new StringBuilder();
  for(Delta delta:getPatch().getDeltas()){
    deltas.append(delta.toString());
    deltas.append(System.getProperty("line.separator"));
  }
  return deltas.toString();
}

代码示例来源:origin: org.opendaylight.mdsal/mdsal-binding-test-utils

public static String diff(String expectedText, String actualText) {
  List<String> originalLines = SPLITTER.splitToList(expectedText);
  List<String> revisedLines = SPLITTER.splitToList(actualText);
  Patch<String> patch = DiffUtils.diff(originalLines, revisedLines);
  List<String> diff = DiffUtils.generateUnifiedDiff("expected", "actual", originalLines, patch, CONTEXT_LINES);
  String header = "";
  int deltas = patch.getDeltas().size();
  if (deltas > MAX_DIFFS) {
    header = String.format("(Too many differences (%d); only showing first %d)%n", deltas, MAX_DIFFS);
    diff = diff.subList(0, MAX_DIFFS);
  }
  return header + JOINER.join(diff);
}

代码示例来源:origin: hadooparchitecturebook/fraud-detection-tutorial

public static void main(String args[]) {
  List<String> original = new ArrayList<String>();
  List<String> revised  = new ArrayList<String>();

  original.add("foobar1");
  original.add("foobar2");
  original.add("foobar3");
  original.add("foobar4");
  original.add("foobar5");

  revised.add("foobar1");
  revised.add("foobar2");
  revised.add("foobar3");
  revised.add("foobar3.1");
  revised.add("foobar4");
  revised.add("foobar5.1");

  // Compute diff. Get the Patch object. Patch is the container for computed deltas.
  Patch<String> patch = DiffUtils.diff(original, revised);

  final List<Delta<String>> deltas = patch.getDeltas();

  for (Delta<String> delta: deltas) {
   System.out.println(delta);
  }
 }
}

代码示例来源:origin: dkpro/dkpro-jwpl

/**
 * Returns the deltas between beforeText and afterText as a line separated String
 * using delta.toString()
 * For more detailed diffs, use getPatch() or getUnifiedDiffStrings()
 *
 * @param difftype defines the type of diffs to include in the String
 * @return diffs as line-separated String using delta.toString()
 */
public String getSimpleDiffString(TYPE difftype) {
  StringBuilder deltas = new StringBuilder();
  for(Delta delta:getPatch().getDeltas()){
    if(delta.getType()==difftype){
      deltas.append(delta.toString());
      deltas.append(System.getProperty("line.separator"));
    }
  }
  return deltas.toString();
}

代码示例来源:origin: com.cognifide.aet/jobs

/**
 * Generates deltas of changes using DiffUtils library. If {trimmed} all source lines are trimmed
 * before comparison in order to remove white spaces differences between html tags.
 *
 * @param pattern - pattern to compare
 * @param source - source to compare
 * @param trimmedLines - flag if lines should be trimmed
 * @return List of Delta changes
 */
public List<ResultDelta> generateDiffs(String pattern, String source, boolean trimmedLines) {
 List<String> patternList = Arrays.asList(StringUtils.split(pattern, NEW_LINE));
 List<String> sourceList = Arrays.asList(StringUtils.split(source, NEW_LINE));
 if (trimmedLines) {
  patternList = Lists.transform(patternList, TRIM_FUNCTION);
  sourceList = Lists.transform(sourceList, TRIM_FUNCTION);
 }
 Patch patch = DiffUtils.diff(patternList, sourceList);
 List<Delta> deltas = patch.getDeltas();
 return addFullSource(deltas, patternList, sourceList);
}

代码示例来源:origin: org.fitnesse/fitnesse

private Delta<Character> getDeltaByIndex(final int i,
  final Patch<Character> patch) {
 for (Delta<Character> delta : patch.getDeltas()) {
  if (isInChunk(getChunk(delta), i)) {
   return delta;
  }
 }
 return null;
}

代码示例来源:origin: Cognifide/aet

/**
 * Generates deltas of changes using DiffUtils library. If {trimmed} all source lines are trimmed
 * before comparison in order to remove white spaces differences between html tags.
 *
 * @param pattern - pattern to compare
 * @param source - source to compare
 * @param trimmedLines - flag if lines should be trimmed
 * @return List of Delta changes
 */
public List<ResultDelta> generateDiffs(String pattern, String source, boolean trimmedLines) {
 List<String> patternList = Arrays.asList(StringUtils.split(pattern, NEW_LINE));
 List<String> sourceList = Arrays.asList(StringUtils.split(source, NEW_LINE));
 if (trimmedLines) {
  patternList = Lists.transform(patternList, TRIM_FUNCTION);
  sourceList = Lists.transform(sourceList, TRIM_FUNCTION);
 }
 Patch patch = DiffUtils.diff(patternList, sourceList);
 List<Delta> deltas = patch.getDeltas();
 return addFullSource(deltas, patternList, sourceList);
}

代码示例来源:origin: com.github.tcnh/fitnesse

private Delta<Character> getDeltaByIndex(final int i,
  final Patch<Character> patch) {
 for (Delta<Character> delta : patch.getDeltas()) {
  if (isInChunk(getChunk(delta), i)) {
   return delta;
  }
 }
 return null;
}

代码示例来源:origin: ferstl/pedantic-pom-enforcers

public SideBySideContext(Collection<String> original, Collection<String> revised, String leftTitle, String rightTitle) {
 this.leftTitle = leftTitle;
 this.rightTitle = rightTitle;
 List<String> originalList = original instanceof List ? (List<String>) original : new ArrayList<>(original);
 List<String> revisedList = revised instanceof List ? (List<String>) revised : new ArrayList<>(revised);
 this.deltas = DiffUtils.diff(originalList, revisedList).getDeltas();
 this.leftWidth = Math.max(getMaxWidth(original) + 2, leftTitle.length()); // +2: include the markers
 this.rightWidth = Math.max(getMaxWidth(revised) + 2, rightTitle.length()); // +2: include the markers
 int length = Math.max(original.size(), revised.size());
 length += getExpansionLength(this.deltas);
 this.left = new ArrayList<>(length);
 this.right = new ArrayList<>(length);
 for (String string : original) {
  String line = formatLine(EMPTY_MARKER, string);
  this.left.add(line);
  this.right.add(line);
 }
}

代码示例来源:origin: dkpro/dkpro-jwpl

/**
 * Returns the deltas between beforeText and afterText as a line separated String.
 * For more detailed diffs, use getPatch() or getUnifiedDiffStrings()
 *
 * @return diffs as line-separated String
 */
public String getLongDiffString() {
  StringBuilder deltas = new StringBuilder();
  for(Delta delta:getPatch().getDeltas()){
    deltas.append("DeltaType: "+delta.getType().toString());
    deltas.append(System.getProperty("line.separator"));
    deltas.append("Original (Non-Neutral):");
    deltas.append(System.getProperty("line.separator"));
    deltas.append(delta.getOriginal());
    deltas.append(System.getProperty("line.separator"));
    deltas.append(System.getProperty("line.separator"));
    deltas.append("Revised (Neutral):");
    deltas.append(System.getProperty("line.separator"));
    deltas.append(delta.getRevised());
    deltas.append(System.getProperty("line.separator"));
  }
  return deltas.toString();
}

代码示例来源:origin: org.rhq/rhq-enterprise-server

@Override
public FileDiffReport generateUnifiedDiff(Subject subject, Drift<?, ?> drift) {
  log.debug("Generating diff for " + drift);
  String oldContent = getDriftFileBits(subject, drift.getOldDriftFile().getHashId());
  List<String> oldList = asList(oldContent.split("\\n"));
  String newContent = getDriftFileBits(subject, drift.getNewDriftFile().getHashId());
  List<String> newList = asList(newContent.split("\\n"));
  Patch patch = DiffUtils.diff(oldList, newList);
  List<String> deltas = DiffUtils.generateUnifiedDiff(drift.getPath(), drift.getPath(), oldList, patch, 10);
  return new FileDiffReport(patch.getDeltas().size(), deltas);
}

代码示例来源:origin: org.rhq/rhq-enterprise-server

@Override
public FileDiffReport generateUnifiedDiff(Subject subject, Drift<?, ?> drift1, Drift<?, ?> drift2) {
  DriftFile drift1File = drift1.getNewDriftFile();
  String content1 = (null == drift1File) ? "" : getDriftFileBits(subject, drift1File.getHashId());
  List<String> content1List = asList(content1.split("\\n"));
  DriftFile drift2File = drift2.getNewDriftFile();
  String content2 = (null == drift2File) ? "" : getDriftFileBits(subject, drift2File.getHashId());
  List<String> content2List = asList(content2.split("\\n"));
  Patch patch = DiffUtils.diff(content1List, content2List);
  List<String> deltas = DiffUtils
    .generateUnifiedDiff(drift1.getPath(), drift2.getPath(), content1List, patch, 10);
  return new FileDiffReport(patch.getDeltas().size(), deltas);
}

代码示例来源:origin: jenkinsci/jobConfigHistory-plugin

/**
 * Returns a list of {@link SideBySideView} lines.
 *
 * @return list of {@link SideBySideView} lines.
 */
public List<SideBySideView.Line> get() {
  final Patch diff = DiffUtils.parseUnifiedDiff(diffLines);
  int previousLeftPos = 0;
  for (final Delta delta : diff.getDeltas()) {
    previousLeftPos = deltaLoop(delta, previousLeftPos);
  }
  view.clearDuplicateLines();
  return view.getLines();
}

相关文章