001    /**
002     * Copyright (c) 2000-2010 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.util.diff;
016    
017    import com.liferay.portal.kernel.util.StringBundler;
018    
019    import java.util.ArrayList;
020    import java.util.Iterator;
021    import java.util.List;
022    
023    /**
024     * <p>
025     * Represents a change between one or several lines. <code>changeType</code>
026     * tells if the change happened in source or target. <code>lineNumber</code>
027     * holds the line number of the first modified line. This line number refers to
028     * a line in source or target, depending on the <code>changeType</code> value.
029     * <code>changedLines</code> is a list of strings, each string is a line that is
030     * already highlighted, indicating where the changes are.
031     * </p>
032     *
033     * @author         Bruno Farache
034     * @deprecated This class has been repackaged at
035     *                         <code>com.liferay.portal.kernel.util</code>.
036     */
037    public class DiffResult {
038    
039            public static final String SOURCE = "SOURCE";
040    
041            public static final String TARGET = "TARGET";
042    
043            public DiffResult(int linePos, List<String> changedLines) {
044                    _lineNumber = linePos + 1;
045                    _changedLines = changedLines;
046            }
047    
048            public DiffResult(int linePos, String changedLine) {
049                    _lineNumber = linePos + 1;
050                    _changedLines = new ArrayList<String>();
051                    _changedLines.add(changedLine);
052            }
053    
054            public List<String> getChangedLines() {
055                    return _changedLines;
056            }
057    
058            public void setChangedLines(List<String> changedLines) {
059                    _changedLines = changedLines;
060            }
061    
062            public int getLineNumber() {
063                    return _lineNumber;
064            }
065    
066            public void setLineNumber(int lineNumber) {
067                    _lineNumber = lineNumber;
068            }
069    
070            public boolean equals(Object obj) {
071                    DiffResult diffResult = (DiffResult)obj;
072    
073                    if ((diffResult.getLineNumber() == _lineNumber) &&
074                            (diffResult.getChangedLines().equals(_changedLines))) {
075    
076                            return true;
077                    }
078    
079                    return false;
080            }
081    
082            public String toString() {
083                    StringBundler sb = new StringBundler(_changedLines.size() * 2 + 3);
084    
085                    sb.append("Line: ");
086                    sb.append(_lineNumber);
087                    sb.append("\n");
088    
089                    Iterator<String> itr = _changedLines.iterator();
090    
091                    while (itr.hasNext()) {
092                            sb.append(itr.next());
093    
094                            if (itr.hasNext()) {
095                                    sb.append("\n");
096                            }
097                    }
098    
099                    return sb.toString();
100            }
101    
102            private int _lineNumber;
103            private List<String> _changedLines;
104    
105    }