DiffUtil.java |
1 /** 2 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved. 3 * 4 * The contents of this file are subject to the terms of the Liferay Enterprise 5 * Subscription License ("License"). You may not use this file except in 6 * compliance with the License. You can obtain a copy of the License by 7 * contacting Liferay, Inc. See the License for the specific language governing 8 * permissions and limitations under the License, including but not limited to 9 * distribution rights of the Software. 10 * 11 * 12 * 13 */ 14 15 package com.liferay.portal.kernel.util; 16 17 import java.io.Reader; 18 19 import java.util.List; 20 21 /** 22 * <a href="DiffUtil.java.html"><b><i>View Source</i></b></a> 23 * 24 * <p> 25 * This class can compare two different versions of a text. Source refers to the 26 * earliest version of the text and target refers to a modified version of 27 * source. Changes are considered either as a removal from the source or as an 28 * addition to the target. This class detects changes to an entire line and also 29 * detects changes within lines, such as, removal or addition of characters. 30 * Take a look at <code>DiffTest</code> to see the expected inputs and outputs. 31 * </p> 32 * 33 * @author Bruno Farache 34 * @see com.liferay.portal.kernel.util.DiffUtil 35 */ 36 public class DiffUtil { 37 38 public static List<DiffResult>[] diff(Reader source, Reader target) { 39 return getDiff().diff(source, target); 40 } 41 42 public static List<DiffResult>[] diff( 43 Reader source, Reader target, String addedMarkerStart, 44 String addedMarkerEnd, String deletedMarkerStart, 45 String deletedMarkerEnd, int margin) { 46 47 return getDiff().diff( 48 source, target, addedMarkerStart, addedMarkerEnd, 49 deletedMarkerStart, deletedMarkerEnd, margin); 50 } 51 52 public static Diff getDiff() { 53 return _diff; 54 } 55 56 public void setDiff(Diff diff) { 57 _diff = diff; 58 } 59 60 private static Diff _diff; 61 62 }