difflib.Delta.getRevised()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(13.3k)|赞(0)|评价(0)|浏览(136)

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

Delta.getRevised介绍

暂无

代码示例

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

@Override
protected Chunk<Character> getChunk(final Delta<Character> d) {
 return d.getRevised();
}

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

@Override
protected Chunk<Character> getChunk(final Delta<Character> d) {
 return d.getRevised();
}

代码示例来源:origin: com.sqlapp/sqlapp-core

private static StringBuilder getBuilder(Delta<?> delta) {
  StringBuilder builder = new StringBuilder(256);
  builder.append("@@ -");
  builder.append(delta.getOriginal().getPosition());
  builder.append(",");
  builder.append(delta.getOriginal().last());
  builder.append(" +");
  builder.append(delta.getRevised().getPosition());
  builder.append(",");
  builder.append(delta.getRevised().last());
  builder.append(" @@");
  return builder;
}

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

/**
 * Returns the deltas between beforeText and afterText as a line separated String.
 * 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
 */
public String getLongDiffString(TYPE diffType) {
  StringBuilder deltas = new StringBuilder();
  for(Delta delta:getPatch().getDeltas()){
    if(delta.getType()==diffType){
      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"));
      deltas.append("*********************************************");
      deltas.append(System.getProperty("line.separator"));
    }
  }
  return deltas.toString();
}

代码示例来源: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: com.custardsource.dybdob/java-diff-utils-copy

/**
 * getDeltaText returns the lines to be added to the Unified Diff text from the Delta parameter
 * @author Bill James (tankerbay@gmail.com)
 * 
 * @param delta - the Delta to output
 * @return list of String lines of code.
 */
private static List<String> getDeltaText(Delta delta) {
  List<String> buffer = new ArrayList<String>();
  for (Object line : delta.getOriginal().getLines()) {
    buffer.add("-" + line);
  }
  for (Object line : delta.getRevised().getLines()) {
    buffer.add("+" + line);
  }
  return buffer;
}

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

/**
 * getDeltaText returns the lines to be added to the Unified Diff text from
 * the Delta parameter
 * 
 * @param delta
 *            - the Delta to output
 * @return list of String lines of code.
 * @author Bill James (tankerbay@gmail.com)
 */
private static List<String> getDeltaText(Delta<String> delta) {
  List<String> buffer = new ArrayList<String>();
  for (String line : delta.getOriginal().getLines()) {
    buffer.add("-" + line);
  }
  for (String line : delta.getRevised().getLines()) {
    buffer.add("+" + line);
  }
  return buffer;
}

代码示例来源:origin: com.sqlapp/sqlapp-core

/**
 * 差分をユニファイド形式の文字列にします。
 * 
 * @param delta
 *            差分
 * @return ユニファイド形式の文字列
 */
public static String toString(Delta<?> delta) {
  if (delta == null) {
    return "";
  }
  StringBuilder builder = getBuilder(delta);
  if ((delta instanceof DeleteDelta) || (delta instanceof ChangeDelta)) {
    for (Object obj : delta.getOriginal().getLines()) {
      builder.append("\n");
      builder.append("-");
      builder.append(obj);
    }
  }
  if ((delta instanceof InsertDelta) || (delta instanceof ChangeDelta)) {
    for (Object obj : delta.getRevised().getLines()) {
      builder.append("\n");
      builder.append("+");
      builder.append(obj);
    }
  }
  return builder.toString();
}

代码示例来源: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.cognifide.aet/jobs

private List<ResultDelta> addFullSource(List<Delta> deltaList, List<String> originalList,
  List<String> revisedList) {
 List<ResultDelta> deltaListWithSource = new ArrayList<>();
 int lastPositionOriginal = 0;
 int lastPositionRevised = 0;
 for (Delta delta : deltaList) {
  // original
  int sizeOriginal = delta.getOriginal().getLines().size();
  int positionOriginal = delta.getOriginal().getPosition();
  List<String> originalSubList = originalList.subList(lastPositionOriginal, positionOriginal);
  ResultChunk originalChunk = getNoChangesResultChunk(originalSubList, lastPositionOriginal);
  lastPositionOriginal = sizeOriginal + positionOriginal;
  // revised
  int sizeRevised = delta.getRevised().getLines().size();
  int positionRevised = delta.getRevised().getPosition();
  List<String> revisedSubList = revisedList.subList(lastPositionRevised, positionRevised);
  ResultChunk revisedChunk = getNoChangesResultChunk(revisedSubList, lastPositionRevised);
  lastPositionRevised = sizeRevised + positionRevised;
  ResultDelta resultDelta = new ResultDelta(TYPE.NO_CHANGE, originalChunk, revisedChunk);
  deltaListWithSource.add(resultDelta);
  deltaListWithSource.add(processDelta(delta));
 }
 if ((originalList.size() > lastPositionOriginal || revisedList.size() > lastPositionRevised)
   && !deltaList.isEmpty()) {
  ResultDelta resultDelta = prepareNoChangeResultDelta(originalList, revisedList,
    lastPositionOriginal, lastPositionRevised);
  deltaListWithSource.add(resultDelta);
 }
 return deltaListWithSource;
}

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

private List<ResultDelta> addFullSource(List<Delta> deltaList, List<String> originalList,
  List<String> revisedList) {
 List<ResultDelta> deltaListWithSource = new ArrayList<>();
 int lastPositionOriginal = 0;
 int lastPositionRevised = 0;
 for (Delta delta : deltaList) {
  // original
  int sizeOriginal = delta.getOriginal().getLines().size();
  int positionOriginal = delta.getOriginal().getPosition();
  List<String> originalSubList = originalList.subList(lastPositionOriginal, positionOriginal);
  ResultChunk originalChunk = getNoChangesResultChunk(originalSubList, lastPositionOriginal);
  lastPositionOriginal = sizeOriginal + positionOriginal;
  // revised
  int sizeRevised = delta.getRevised().getLines().size();
  int positionRevised = delta.getRevised().getPosition();
  List<String> revisedSubList = revisedList.subList(lastPositionRevised, positionRevised);
  ResultChunk revisedChunk = getNoChangesResultChunk(revisedSubList, lastPositionRevised);
  lastPositionRevised = sizeRevised + positionRevised;
  ResultDelta resultDelta = new ResultDelta(TYPE.NO_CHANGE, originalChunk, revisedChunk);
  deltaListWithSource.add(resultDelta);
  deltaListWithSource.add(processDelta(delta));
 }
 if ((originalList.size() > lastPositionOriginal || revisedList.size() > lastPositionRevised)
   && !deltaList.isEmpty()) {
  ResultDelta resultDelta = prepareNoChangeResultDelta(originalList, revisedList,
    lastPositionOriginal, lastPositionRevised);
  deltaListWithSource.add(resultDelta);
 }
 return deltaListWithSource;
}

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

protected ResultDelta processDelta(Delta delta) {
 String originalLines = StringUtils.join(delta.getOriginal().getLines(), NEW_LINE);
 String revisedLines = StringUtils.join(delta.getRevised().getLines(), NEW_LINE);
 String originalChunkHtml;
 String revisedChunkHtml;

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

protected ResultDelta processDelta(Delta delta) {
 String originalLines = StringUtils.join(delta.getOriginal().getLines(), NEW_LINE);
 String revisedLines = StringUtils.join(delta.getRevised().getLines(), NEW_LINE);
 String originalChunkHtml;
 String revisedChunkHtml;

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

private static int getExpansionLength(Collection<Delta<String>> deltas) {
 int length = 0;
 for(Delta<?> delta : deltas) {
  switch(delta.getType()) {
   case INSERT:
   case CHANGE:
    int expansion = delta.getRevised().size() - delta.getOriginal().size();
    length += (expansion > 0) ? expansion : 0;
    break;
   default: // NOP
  }
 }
 return length;
}

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

private ResultDelta buildDelta(String originalChunkHtml, String revisedChunkHtml, Delta delta) {
 String localOriginalChunkHtml = originalChunkHtml;
 String localRevisedChunkHtml = revisedChunkHtml;
 int originalLinesNo = delta.getOriginal().getLines().size();
 int revisedLinesNo = delta.getRevised().getLines().size();
 int sizeDiff = Math.abs(originalLinesNo - revisedLinesNo);
 if (sizeDiff > 0) {
  if (delta.getType().equals(Delta.TYPE.CHANGE)) {
   // I don't know why, but it have to be like that.
   sizeDiff++;
  }
  String alignment = StringUtils.repeat(BR_TAG, sizeDiff);
  if (originalLinesNo > revisedLinesNo) {
   localRevisedChunkHtml += alignment;
  } else if (originalLinesNo < revisedLinesNo) {
   localOriginalChunkHtml += alignment;
  }
 }
 int originalPosition = delta.getOriginal().getPosition();
 ResultChunk original = new ResultChunk(originalPosition, localOriginalChunkHtml);
 int revisedPosition = delta.getRevised().getPosition();
 ResultChunk revised = new ResultChunk(revisedPosition, localRevisedChunkHtml);
 return new ResultDelta(TYPE.valueOf(delta.getType().name()), original, revised);
}

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

private ResultDelta buildDelta(String originalChunkHtml, String revisedChunkHtml, Delta delta) {
 String localOriginalChunkHtml = originalChunkHtml;
 String localRevisedChunkHtml = revisedChunkHtml;
 int originalLinesNo = delta.getOriginal().getLines().size();
 int revisedLinesNo = delta.getRevised().getLines().size();
 int sizeDiff = Math.abs(originalLinesNo - revisedLinesNo);
 if (sizeDiff > 0) {
  if (delta.getType().equals(Delta.TYPE.CHANGE)) {
   // I don't know why, but it have to be like that.
   sizeDiff++;
  }
  String alignment = StringUtils.repeat(BR_TAG, sizeDiff);
  if (originalLinesNo > revisedLinesNo) {
   localRevisedChunkHtml += alignment;
  } else if (originalLinesNo < revisedLinesNo) {
   localOriginalChunkHtml += alignment;
  }
 }
 int originalPosition = delta.getOriginal().getPosition();
 ResultChunk original = new ResultChunk(originalPosition, localOriginalChunkHtml);
 int revisedPosition = delta.getRevised().getPosition();
 ResultChunk revised = new ResultChunk(revisedPosition, localRevisedChunkHtml);
 return new ResultDelta(TYPE.valueOf(delta.getType().name()), original, revised);
}

代码示例来源:origin: org.apache.jackrabbit.vault/vault-diff

/**
 * Compute the difference between the 2 arrays.
 * @param reverse Indicates reverse diff
 * @return the change
 */
public Change diff_2(final boolean reverse) {
  Change prev = new Change(0,0,0,0, null);
  Change ret = prev;
  Patch p = DiffUtils.diff(left, right);
  // recompute the changes based on the deltas.
  // todo: use the deltas directly in the DocumentDiff.
  for (Delta d: p.getDeltas()) {
    Chunk c0 = d.getOriginal();
    Chunk c1 = d.getRevised();
    Change next = new Change(
        c0.getPosition(), c1.getPosition(),
        c0.getLines().size(), c1.getLines().size(),
        null);
    if (reverse) {
      next.nextChange = ret;
      ret = next;
    } else {
      prev.nextChange = next;
      prev = next;
    }
  }
  return reverse ? ret : ret.nextChange;
}

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

/**
 * Loop through Delta.
 *
 * @param previousLeftPos
 *            previous indentation
 * @return current indentation
 */
int loop(int previousLeftPos) {
  final Chunk original = delta.getOriginal();
  final Chunk revised = delta.getRevised();
  @SuppressWarnings("unchecked")
  final List<DiffRow> diffRows = dfg.generateDiffRows(
      (List<String>) original.getLines(),
      (List<String>) revised.getLines());
  // Chunk#getPosition() returns 0-origin line numbers, but we need
  // 1-origin line numbers
  leftPos = original.getPosition() + 1;
  rightPos = revised.getPosition() + 1;
  if (previousLeftPos > 0 && leftPos - previousLeftPos > 1) {
    final SideBySideView.Line skippingLine = new SideBySideView.Line();
    skippingLine.setSkipping(true);
    view.addLine(skippingLine);
  }
  for (final DiffRow row : diffRows) {
    previousLeftPos = processDiffRow(row);
  }
  return previousLeftPos;
}

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

@Override
public FormattedDelta apply(Delta from) {
  String original = on(delimiter).join(from.getOriginal().getLines());
  String revised = on(delimiter).join(from.getRevised().getLines());
  return new FormattedDelta(
      wrap(from.getType(), original, revised),
      from.getOriginal().getPosition(),
      from.getOriginal().size(),
      from.getType()
  );
}

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

Chunk<String> revised = delta.getRevised();
int currentPosition = original.getPosition() + offset;

相关文章