LowLevelDiffAlgorithm.java

  1. /*
  2.  * Copyright (C) 2010, Google Inc. and others
  3.  *
  4.  * This program and the accompanying materials are made available under the
  5.  * terms of the Eclipse Distribution License v. 1.0 which is available at
  6.  * https://www.eclipse.org/org/documents/edl-v10.php.
  7.  *
  8.  * SPDX-License-Identifier: BSD-3-Clause
  9.  */

  10. package org.eclipse.jgit.diff;

  11. /**
  12.  * Compares two sequences primarily based upon hash codes.
  13.  */
  14. public abstract class LowLevelDiffAlgorithm extends DiffAlgorithm {
  15.     /** {@inheritDoc} */
  16.     @Override
  17.     public <S extends Sequence> EditList diffNonCommon(
  18.             SequenceComparator<? super S> cmp, S a, S b) {
  19.         HashedSequencePair<S> p = new HashedSequencePair<>(cmp, a, b);
  20.         HashedSequenceComparator<S> hc = p.getComparator();
  21.         HashedSequence<S> ha = p.getA();
  22.         HashedSequence<S> hb = p.getB();
  23.         p = null;

  24.         EditList res = new EditList();
  25.         Edit region = new Edit(0, a.size(), 0, b.size());
  26.         diffNonCommon(res, hc, ha, hb, region);
  27.         return res;
  28.     }

  29.     /**
  30.      * Compare two sequences and identify a list of edits between them.
  31.      *
  32.      * This method should be invoked only after the two sequences have been
  33.      * proven to have no common starting or ending elements. The expected
  34.      * elimination of common starting and ending elements is automatically
  35.      * performed by the {@link #diff(SequenceComparator, Sequence, Sequence)}
  36.      * method, which invokes this method using
  37.      * {@link org.eclipse.jgit.diff.Subsequence}s.
  38.      *
  39.      * @param edits
  40.      *            result list to append the region's edits onto.
  41.      * @param cmp
  42.      *            the comparator supplying the element equivalence function.
  43.      * @param a
  44.      *            the first (also known as old or pre-image) sequence. Edits
  45.      *            returned by this algorithm will reference indexes using the
  46.      *            'A' side: {@link org.eclipse.jgit.diff.Edit#getBeginA()},
  47.      *            {@link org.eclipse.jgit.diff.Edit#getEndA()}.
  48.      * @param b
  49.      *            the second (also known as new or post-image) sequence. Edits
  50.      *            returned by this algorithm will reference indexes using the
  51.      *            'B' side: {@link org.eclipse.jgit.diff.Edit#getBeginB()},
  52.      *            {@link org.eclipse.jgit.diff.Edit#getEndB()}.
  53.      * @param region
  54.      *            the region being compared within the two sequences.
  55.      */
  56.     public abstract <S extends Sequence> void diffNonCommon(EditList edits,
  57.             HashedSequenceComparator<S> cmp, HashedSequence<S> a,
  58.             HashedSequence<S> b, Edit region);
  59. }