001 /** 002 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved. 003 * 004 * This library is free software; you can redistribute it and/or modify it under 005 * the terms of the GNU Lesser General Public License as published by the Free 006 * Software Foundation; either version 2.1 of the License, or (at your option) 007 * any later version. 008 * 009 * This library is distributed in the hope that it will be useful, but WITHOUT 010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 011 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 012 * details. 013 */ 014 015 package com.liferay.portal.kernel.util; 016 017 import java.io.Reader; 018 019 import java.util.List; 020 021 /** 022 * <p> 023 * This class can compare two different versions of a text. Source refers to the 024 * earliest version of the text and target refers to a modified version of 025 * source. Changes are considered either as a removal from the source or as an 026 * addition to the target. This class detects changes to an entire line and also 027 * detects changes within lines, such as, removal or addition of characters. 028 * Take a look at <code>DiffTest</code> to see the expected inputs and outputs. 029 * </p> 030 * 031 * @author Bruno Farache 032 * @see com.liferay.portal.kernel.util.DiffUtil 033 */ 034 public class DiffUtil { 035 036 public static List<DiffResult>[] diff(Reader source, Reader target) { 037 return getDiff().diff(source, target); 038 } 039 040 public static List<DiffResult>[] diff( 041 Reader source, Reader target, String addedMarkerStart, 042 String addedMarkerEnd, String deletedMarkerStart, 043 String deletedMarkerEnd, int margin) { 044 045 return getDiff().diff( 046 source, target, addedMarkerStart, addedMarkerEnd, 047 deletedMarkerStart, deletedMarkerEnd, margin); 048 } 049 050 public static Diff getDiff() { 051 return _diff; 052 } 053 054 public void setDiff(Diff diff) { 055 _diff = diff; 056 } 057 058 private static Diff _diff; 059 060 }