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.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 As of 6.2.0, moved to {@link
034     *             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                    for (String changedLine : _changedLines) {
099                            sb.append(changedLine);
100                            sb.append("\n");
101                    }
102    
103                    if (!_changedLines.isEmpty()) {
104                            sb.setIndex(sb.index() - 1);
105                    }
106    
107                    return sb.toString();
108            }
109    
110            private List<String> _changedLines;
111            private int _lineNumber;
112    
113    }