001    /**
002     * Copyright (c) 2000-2013 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            @Override
054            public boolean equals(Object obj) {
055                    if (this == obj) {
056                            return true;
057                    }
058    
059                    if (!(obj instanceof DiffResult)) {
060                            return false;
061                    }
062    
063                    DiffResult diffResult = (DiffResult)obj;
064    
065                    if ((diffResult.getLineNumber() == _lineNumber) &&
066                            diffResult.getChangedLines().equals(_changedLines)) {
067    
068                            return true;
069                    }
070    
071                    return false;
072            }
073    
074            public List<String> getChangedLines() {
075                    return _changedLines;
076            }
077    
078            public int getLineNumber() {
079                    return _lineNumber;
080            }
081    
082            public void setChangedLines(List<String> changedLines) {
083                    _changedLines = changedLines;
084            }
085    
086            public void setLineNumber(int lineNumber) {
087                    _lineNumber = lineNumber;
088            }
089    
090            @Override
091            public String toString() {
092                    StringBundler sb = new StringBundler(_changedLines.size() * 2 + 3);
093    
094                    sb.append("Line: ");
095                    sb.append(_lineNumber);
096                    sb.append("\n");
097    
098                    Iterator<String> itr = _changedLines.iterator();
099    
100                    while (itr.hasNext()) {
101                            sb.append(itr.next());
102    
103                            if (itr.hasNext()) {
104                                    sb.append("\n");
105                            }
106                    }
107    
108                    return sb.toString();
109            }
110    
111            private List<String> _changedLines;
112            private int _lineNumber;
113    
114    }