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