use of suite.lcs.Lccs in project suite by stupidsing.
the class TextUtil method diff.
public List<Pair<Bytes, Bytes>> diff(Bytes bytesx, Bytes bytesy) {
Lccs lccs = new Lccs();
Pair<Segment, Segment> diff = lccs.lccs(bytesx, bytesy);
Segment sx = diff.t0, sy = diff.t1;
int x0 = 0, x1 = sx.start, x2 = sx.end, xx = bytesx.size();
int y0 = 0, y1 = sy.start, y2 = sy.end, yx = bytesy.size();
Bytes common = bytesx.range(x1, x2);
if (!sx.isEmpty() && !sy.isEmpty()) {
List<Pair<Bytes, Bytes>> patch = new ArrayList<>();
patch.addAll(diff(bytesx.range(x0, x1), bytesy.range(y0, y1)));
patch.add(Pair.of(common, common));
patch.addAll(diff(bytesx.range(x2, xx), bytesy.range(y2, yx)));
return patch;
} else if (!bytesx.isEmpty() || !bytesy.isEmpty())
return List.of(Pair.of(bytesx, bytesy));
else
return List.of();
}