DiffUtil.java |
1 /** 2 * Copyright (c) 2000-2009 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 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 12 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 13 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 14 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 15 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 17 * SOFTWARE. 18 */ 19 20 package com.liferay.portal.kernel.util; 21 22 import java.io.Reader; 23 24 import java.util.List; 25 26 /** 27 * <a href="DiffUtil.java.html"><b><i>View Source</i></b></a> 28 * 29 * <p> 30 * This class can compare two different versions of a text. Source refers to 31 * the earliest version of the text and target refers to a modified version of 32 * source. Changes are considered either as a removal from the source or as an 33 * addition to the target. This class detects changes to an entire line and also 34 * detects changes within lines, such as, removal or addition of characters. 35 * Take a look at <code>DiffTest</code> to see the expected inputs and outputs. 36 * </p> 37 * 38 * @author Bruno Farache 39 * 40 * @see com.liferay.portal.kernel.util.DiffUtil 41 * 42 */ 43 public class DiffUtil { 44 45 public static List<DiffResult>[] diff(Reader source, Reader target) { 46 return getDiff().diff(source, target); 47 } 48 49 public static List<DiffResult>[] diff( 50 Reader source, Reader target, String addedMarkerStart, 51 String addedMarkerEnd, String deletedMarkerStart, 52 String deletedMarkerEnd, int margin) { 53 54 return getDiff().diff( 55 source, target, addedMarkerStart, addedMarkerEnd, 56 deletedMarkerStart, deletedMarkerEnd, margin); 57 } 58 59 public static Diff getDiff() { 60 return _diff; 61 } 62 63 public void setDiff(Diff diff) { 64 _diff = diff; 65 } 66 67 private static Diff _diff; 68 69 }