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.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 Moved to {@link com.liferay.portal.kernel.util.DiffResult}
035     */
036    public class DiffResult {
037    
038            public static final String SOURCE = "SOURCE";
039    
040            public static final String TARGET = "TARGET";
041    
042            public DiffResult(int linePos, List<String> changedLines) {
043                    _lineNumber = linePos + 1;
044                    _changedLines = changedLines;
045            }
046    
047            public DiffResult(int linePos, String changedLine) {
048                    _lineNumber = linePos + 1;
049                    _changedLines = new ArrayList<String>();
050                    _changedLines.add(changedLine);
051            }
052    
053            public List<String> getChangedLines() {
054                    return _changedLines;
055            }
056    
057            public void setChangedLines(List<String> changedLines) {
058                    _changedLines = changedLines;
059            }
060    
061            public int getLineNumber() {
062                    return _lineNumber;
063            }
064    
065            public void setLineNumber(int lineNumber) {
066                    _lineNumber = lineNumber;
067            }
068    
069            @Override
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            @Override
083            public String toString() {
084                    StringBundler sb = new StringBundler(_changedLines.size() * 2 + 3);
085    
086                    sb.append("Line: ");
087                    sb.append(_lineNumber);
088                    sb.append("\n");
089    
090                    Iterator<String> itr = _changedLines.iterator();
091    
092                    while (itr.hasNext()) {
093                            sb.append(itr.next());
094    
095                            if (itr.hasNext()) {
096                                    sb.append("\n");
097                            }
098                    }
099    
100                    return sb.toString();
101            }
102    
103            private int _lineNumber;
104            private List<String> _changedLines;
105    
106    }