private static List<String> processDeltas(List<String> origLines,
			List<Delta<String>> deltas, int contextSize) {
		List<String> buffer = new ArrayList<String>();
		int origTotal = 0; // counter for total lines output from Original
		int revTotal = 0; // counter for total lines output from Original
		int line;

		Delta<String> curDelta = deltas.get(0);

		// NOTE: +1 to overcome the 0-offset Position
		int origStart = curDelta.getOriginal().getPosition() + 1 - contextSize;
		if (origStart < 1) {
			origStart = 1;
		}

		int revStart = curDelta.getRevised().getPosition() + 1 - contextSize;
		if (revStart < 1) {
			revStart = 1;
		}

		// find the start of the wrapper context code
		int contextStart = curDelta.getOriginal().getPosition() - contextSize;
		if (contextStart < 0) {
			contextStart = 0; // clamp to the start of the file
		}

		// output the context before the first Delta
		for (line = contextStart; line < curDelta.getOriginal().getPosition(); line++) { //
			buffer.add(" " + origLines.get(line));
			origTotal++;
			revTotal++;
		}

		// output the first Delta
		buffer.addAll(getDeltaText(curDelta));
		origTotal += curDelta.getOriginal().getLines().size();
		revTotal += curDelta.getRevised().getLines().size();

		int deltaIndex = 1;
		while (deltaIndex < deltas.size()) { // for each of the other Deltas
			Delta<String> nextDelta = deltas.get(deltaIndex);
			int intermediateStart = curDelta.getOriginal().getPosition()
					+ curDelta.getOriginal().getLines().size();
			for (line = intermediateStart; line < nextDelta.getOriginal()
					.getPosition(); line++) {
				// output the code between the last Delta and this one
				buffer.add(" " + origLines.get(line));
				origTotal++;
				revTotal++;
			}
			buffer.addAll(getDeltaText(nextDelta)); // output the Delta
			origTotal += nextDelta.getOriginal().getLines().size();
			revTotal += nextDelta.getRevised().getLines().size();
			curDelta = nextDelta;
			deltaIndex++;
		}

		// Now output the post-Delta context code, clamping the end of the file
		contextStart = curDelta.getOriginal().getPosition()
				+ curDelta.getOriginal().getLines().size();
		for (line = contextStart; (line < (contextStart + contextSize))
				&& (line < origLines.size()); line++) {
			buffer.add(" " + origLines.get(line));
			origTotal++;
			revTotal++;
		}

		// Create and insert the block header, conforming to the Unified Diff
		// standard
		StringBuffer header = new StringBuffer();
		header.append("@@ -");
		header.append(origStart);
		header.append(",");
		header.append(origTotal);
		header.append(" +");
		header.append(revStart);
		header.append(",");
		header.append(revTotal);
		header.append(" @@");
		buffer.add(0, header.toString());

		return buffer;
	}