class MyersDiff<T> implements DiffAlgorithm<T> {

  /** The equalizer. */
  private final Equalizer<T> equalizer;

  /**
   * Constructs an instance of the Myers differencing algorithm.
   */
  public MyersDiff() {
    /* Default equalizer. */
    equalizer = Object::equals;
  }

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

  /**
   * Computes the minimum diffpath that expresses de differences
   * between the original and revised sequences, according
   * to Gene Myers differencing algorithm.
   *
   * @param orig The original sequence.
   * @param rev The revised sequence.
   * @return A minimum {@link PathNode Path} across the differences graph.
   * @throws IllegalStateException if a diff path could not be found.
   */
  public PathNode buildPath(final List<T> orig, final List<T> rev) {<FILL_FUNCTION_BODY>}

  private boolean equals(T orig, T rev) {
    return equalizer.equals(orig, rev);
  }

  /**
   * Constructs a {@link Patch} from a difference path.
   *
   * @param path The path.
   * @param orig The original sequence.
   * @param rev The revised sequence.
   * @return A {@link Patch} script corresponding to the path.
   */
  public Patch<T> buildRevision(PathNode path, List<T> orig, List<T> rev) {
    checkArgument(path != null, "path is null");
    checkArgument(orig != null, "original sequence is null");
    checkArgument(rev != null, "revised sequence is null");

    Patch<T> patch = new Patch<>();
    if (path.isSnake())
      path = path.prev;
    while (path != null && path.prev != null && path.prev.j >= 0) {
      checkState(!path.isSnake(), "bad diffpath: found snake when looking for diff");
      int i = path.i;
      int j = path.j;

      path = path.prev;
      int ianchor = path.i;
      int janchor = path.j;

      Chunk<T> original = new Chunk<>(ianchor, copyOfRange(orig, ianchor, i));
      Chunk<T> revised = new Chunk<>(janchor, copyOfRange(rev, janchor, j));
      Delta<T> delta;
      if (original.size() == 0 && revised.size() != 0) {
        delta = new InsertDelta<>(original, revised);
      } else if (original.size() > 0 && revised.size() == 0) {
        delta = new DeleteDelta<>(original, revised);
      } else {
        delta = new ChangeDelta<>(original, revised);
      }

      patch.addDelta(delta);
      if (path.isSnake()) path = path.prev;
    }
    return patch;
  }

  /**
   * Creates a new list containing the elements returned by {@link List#subList(int, int)}.
   * @param original The original sequence. Must not be {@code null}.
   * @param fromIndex low endpoint (inclusive) of the subList.
   * @param to high endpoint (exclusive) of the subList.
   * @return A new list of the specified range within the original list.
  
   */
  private List<T> copyOfRange(final List<T> original, final int fromIndex, final int to) {
    return new ArrayList<>(original.subList(fromIndex, to));
  }
}

    checkArgument(orig != null, "original sequence is null");
    checkArgument(rev != null, "revised sequence is null");

    // these are local constants
    final int N = orig.size();
    final int M = rev.size();

    final int MAX = N + M + 1;
    final int size = 1 + 2 * MAX;
    final int middle = size / 2;
    final PathNode[] diagonal = new PathNode[size];

    diagonal[middle + 1] = new Snake(0, -1, null);
    for (int d = 0; d < MAX; d++) {
      for (int k = -d; k <= d; k += 2) {
        final int kmiddle = middle + k;
        final int kplus = kmiddle + 1;
        final int kminus = kmiddle - 1;
        PathNode prev;

        int i;
        if ((k == -d) || (k != d && diagonal[kminus].i < diagonal[kplus].i)) {
          i = diagonal[kplus].i;
          prev = diagonal[kplus];
        } else {
          i = diagonal[kminus].i + 1;
          prev = diagonal[kminus];
        }

        diagonal[kminus] = null; // no longer used

        int j = i - k;

        PathNode node = new DiffNode(i, j, prev);

        // orig and rev are zero-based
        // but the algorithm is one-based
        // that's why there's no +1 when indexing the sequences
        while (i < N && j < M && equals(orig.get(i), rev.get(j))) {
          i++;
          j++;
        }
        if (i > node.i) node = new Snake(i, j, node);

        diagonal[kmiddle] = node;

        if (i >= N && j >= M) return diagonal[kmiddle];
      }
      diagonal[middle + d - 1] = null;
    }

    // According to Myers, this cannot happen
    throw new IllegalStateException("could not find a diff path");
  
<no_super_class>