001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.util.diff;
022:
023: import com.liferay.portal.kernel.util.StringMaker;
024:
025: import java.util.ArrayList;
026: import java.util.Iterator;
027: import java.util.List;
028:
029: /**
030: * <a href="DiffResult.java.html"><b><i>View Source</i></b></a>
031: *
032: * <p>
033: * Represents a change between one or several lines. <code>changeType</code>
034: * tells if the change happened in source or target. <code>lineNumber</code>
035: * holds the line number of the first modified line. This line number refers to
036: * a line in source or target, depending on the <code>changeType</code> value.
037: * <code>changedLines</code> is a list of strings, each string is a line that
038: * is already highlighted, indicating where the changes are.
039: * </p>
040: *
041: * @author Bruno Farache
042: *
043: */
044: public class DiffResult {
045:
046: public static final String SOURCE = "SOURCE";
047:
048: public static final String TARGET = "TARGET";
049:
050: public DiffResult(int linePos, List changedLines) {
051: _lineNumber = linePos + 1;
052: _changedLines = changedLines;
053: }
054:
055: public DiffResult(int linePos, String changedLine) {
056: _lineNumber = linePos + 1;
057: _changedLines = new ArrayList();
058: _changedLines.add(changedLine);
059: }
060:
061: public List getChangedLines() {
062: return _changedLines;
063: }
064:
065: public void setChangedLines(List changedLines) {
066: _changedLines = changedLines;
067: }
068:
069: public int getLineNumber() {
070: return _lineNumber;
071: }
072:
073: public void setLineNumber(int lineNumber) {
074: _lineNumber = lineNumber;
075: }
076:
077: public boolean equals(Object obj) {
078: DiffResult diffResult = (DiffResult) obj;
079:
080: if ((diffResult.getLineNumber() == _lineNumber)
081: && (diffResult.getChangedLines().equals(_changedLines))) {
082:
083: return true;
084: }
085:
086: return false;
087: }
088:
089: public String toString() {
090: StringMaker sm = new StringMaker();
091:
092: sm.append("Line: ");
093: sm.append(_lineNumber);
094: sm.append("\n");
095:
096: Iterator itr = _changedLines.iterator();
097:
098: while (itr.hasNext()) {
099: sm.append(itr.next());
100:
101: if (itr.hasNext()) {
102: sm.append("\n");
103: }
104: }
105:
106: return sm.toString();
107: }
108:
109: private int _lineNumber;
110: private List _changedLines;
111:
112: }
|