package utils;

import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import difflib.DiffUtils;
import difflib.Patch;
import difflib.PatchFailedException;

public class DiffHelper {

	public static String getDiff(String source, String destination) {
		
		Patch<String> diff = getPatch(source, destination);

		List<String> unifiedDiff = DiffUtils.generateUnifiedDiff("", "", Arrays.asList(StringUtils.split(source, "\n")), diff, 0);

		return StringUtils.join(unifiedDiff, "\n");
	}

	public static Patch<String> getPatch(String source, String destination) {
		if(source == null)
		{
			source = "";
		}
		
		if(destination == null)
		{
			destination = "";
		}
		
		String[] src = StringUtils.split(source, "\n");
		String[] dest = StringUtils.split(destination, "\n");
		Patch<String> diff = DiffUtils.diff(Arrays.asList(src),
				Arrays.asList(dest));
		
		return diff;
	}

	public static String patch(String source, String patch) throws PatchFailedException {

		List<String> patchs = Arrays.asList(StringUtils.split(patch, "\n"));

		Patch<String> diff = DiffUtils.parseUnifiedDiff(patchs); 
		
		String[] split = StringUtils.split(source, "\n");
		List<String> applyTo = diff.applyTo(Arrays.asList(split));
		String join = StringUtils.join(applyTo, "\n");
		
		return join;	
	}
}

@@ -444,38 +444,29 @@
 ist(
-StringUtils.split(source, %22%5Cn%22
+source.split(%22%5Cn%22, -1
 )), 
@@ -744,95 +744,77 @@
 c = 
-StringUtils.split(source, %22%5Cn%22);%0D%0A%09%09String%5B%5D dest = StringUtils.split(destination, %22%5Cn%22
+source.split(%22%5Cn%22, -1);%0D%0A%09%09String%5B%5D dest = destination.split(%22%5Cn%22, -1
 );%0D%0A
@@ -1057,37 +1057,27 @@
 ist(
-StringUtils.split(patch, 
+patch.split(
 %22%5Cn%22
+,-1
 ));%0D
@@ -1167,38 +1167,29 @@
 t = 
-StringUtils.split(source, %22%5Cn%22
+source.split(%22%5Cn%22, -1
 );%0D%0A

Use String.split to form diff lines