| DiffResult.java |
1 /**
2 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License as published by the Free
6 * Software Foundation; either version 2.1 of the License, or (at your option)
7 * any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * details.
13 */
14
15 package com.liferay.util.diff;
16
17 import com.liferay.portal.kernel.util.StringBundler;
18
19 import java.util.ArrayList;
20 import java.util.Iterator;
21 import java.util.List;
22
23 /**
24 * <a href="DiffResult.java.html"><b><i>View Source</i></b></a>
25 *
26 * <p>
27 * Represents a change between one or several lines. <code>changeType</code>
28 * tells if the change happened in source or target. <code>lineNumber</code>
29 * holds the line number of the first modified line. This line number refers to
30 * a line in source or target, depending on the <code>changeType</code> value.
31 * <code>changedLines</code> is a list of strings, each string is a line that is
32 * already highlighted, indicating where the changes are.
33 * </p>
34 *
35 * @author Bruno Farache
36 * @deprecated This class has been repackaged at
37 * <code>com.liferay.portal.kernel.util</code>.
38 */
39 public class DiffResult {
40
41 public static final String SOURCE = "SOURCE";
42
43 public static final String TARGET = "TARGET";
44
45 public DiffResult(int linePos, List<String> changedLines) {
46 _lineNumber = linePos + 1;
47 _changedLines = changedLines;
48 }
49
50 public DiffResult(int linePos, String changedLine) {
51 _lineNumber = linePos + 1;
52 _changedLines = new ArrayList<String>();
53 _changedLines.add(changedLine);
54 }
55
56 public List<String> getChangedLines() {
57 return _changedLines;
58 }
59
60 public void setChangedLines(List<String> changedLines) {
61 _changedLines = changedLines;
62 }
63
64 public int getLineNumber() {
65 return _lineNumber;
66 }
67
68 public void setLineNumber(int lineNumber) {
69 _lineNumber = lineNumber;
70 }
71
72 public boolean equals(Object obj) {
73 DiffResult diffResult = (DiffResult)obj;
74
75 if ((diffResult.getLineNumber() == _lineNumber) &&
76 (diffResult.getChangedLines().equals(_changedLines))) {
77
78 return true;
79 }
80
81 return false;
82 }
83
84 public String toString() {
85 StringBundler sb = new StringBundler(_changedLines.size() * 2 + 3);
86
87 sb.append("Line: ");
88 sb.append(_lineNumber);
89 sb.append("\n");
90
91 Iterator<String> itr = _changedLines.iterator();
92
93 while (itr.hasNext()) {
94 sb.append(itr.next());
95
96 if (itr.hasNext()) {
97 sb.append("\n");
98 }
99 }
100
101 return sb.toString();
102 }
103
104 private int _lineNumber;
105 private List<String> _changedLines;
106
107 }