}
private static DiffFragment[] transformHeadInsert(DiffFragment[] fragments, FragmentSide side) {
// transforms {abc}abcd into a{bca}bcd
if (fragments.length >= 2) {
DiffFragment first = fragments[0];
DiffFragment second = fragments[1];
if (first == null || second == null) {
return fragments;
}
if (side.getText(first) != null) {
return fragments;
}
String rightText = side.getOtherText(first);
String secondText = side.getText(second);
if (!Comparing.equal(side.getOtherText(second), secondText)) {
return fragments;
}
if (secondText.charAt(0) == rightText.charAt(0)) {
List<DiffFragment> result = new ArrayList<DiffFragment>();
result.add(side.createFragment(rightText.substring(0, 1), rightText.substring(0, 1), false));
result.add(side.createFragment(null, rightText.substring(1) + secondText.substring(0, 1), true));
result.add(side.createFragment(secondText.substring(1), secondText.substring(1), second.isModified()));
result.addAll(Arrays.asList(fragments).subList(2, fragments.length));
return result.toArray(new DiffFragment[result.size()]);
}
}
return fragments;