| DiffResult.java |
1 /**
2 * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3 *
4 * The contents of this file are subject to the terms of the Liferay Enterprise
5 * Subscription License ("License"). You may not use this file except in
6 * compliance with the License. You can obtain a copy of the License by
7 * contacting Liferay, Inc. See the License for the specific language governing
8 * permissions and limitations under the License, including but not limited to
9 * distribution rights of the Software.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17 * SOFTWARE.
18 */
19
20 package com.liferay.portal.kernel.util;
21
22 import java.util.ArrayList;
23 import java.util.Iterator;
24 import java.util.List;
25
26 /**
27 * <a href="DiffResult.java.html"><b><i>View Source</i></b></a>
28 *
29 * <p>
30 * Represents a change between one or several lines. <code>changeType</code>
31 * tells if the change happened in source or target. <code>lineNumber</code>
32 * holds the line number of the first modified line. This line number refers to
33 * a line in source or target, depending on the <code>changeType</code> value.
34 * <code>changedLines</code> is a list of strings, each string is a line that
35 * is already highlighted, indicating where the changes are.
36 * </p>
37 *
38 * @author Bruno Farache
39 *
40 */
41 public class DiffResult {
42
43 public static final String SOURCE = "SOURCE";
44
45 public static final String TARGET = "TARGET";
46
47 public DiffResult(int linePos, List<String> changedLines) {
48 _lineNumber = linePos + 1;
49 _changedLines = changedLines;
50 }
51
52 public DiffResult(int linePos, String changedLine) {
53 _lineNumber = linePos + 1;
54 _changedLines = new ArrayList<String>();
55 _changedLines.add(changedLine);
56 }
57
58 public List<String> getChangedLines() {
59 return _changedLines;
60 }
61
62 public void setChangedLines(List<String> changedLines) {
63 _changedLines = changedLines;
64 }
65
66 public int getLineNumber() {
67 return _lineNumber;
68 }
69
70 public void setLineNumber(int lineNumber) {
71 _lineNumber = lineNumber;
72 }
73
74 public boolean equals(Object obj) {
75 DiffResult diffResult = (DiffResult)obj;
76
77 if ((diffResult.getLineNumber() == _lineNumber) &&
78 (diffResult.getChangedLines().equals(_changedLines))) {
79
80 return true;
81 }
82
83 return false;
84 }
85
86 public String toString() {
87 StringBuilder sb = new StringBuilder();
88
89 sb.append("Line: ");
90 sb.append(_lineNumber);
91 sb.append("\n");
92
93 Iterator<String> itr = _changedLines.iterator();
94
95 while (itr.hasNext()) {
96 sb.append(itr.next());
97
98 if (itr.hasNext()) {
99 sb.append("\n");
100 }
101 }
102
103 return sb.toString();
104 }
105
106 private int _lineNumber;
107 private List<String> _changedLines;
108
109 }