| 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.portal.kernel.util;
16
17 import java.util.ArrayList;
18 import java.util.Iterator;
19 import java.util.List;
20
21 /**
22 * <a href="DiffResult.java.html"><b><i>View Source</i></b></a>
23 *
24 * <p>
25 * Represents a change between one or several lines. <code>changeType</code>
26 * tells if the change happened in source or target. <code>lineNumber</code>
27 * holds the line number of the first modified line. This line number refers to
28 * a line in source or target, depending on the <code>changeType</code> value.
29 * <code>changedLines</code> is a list of strings, each string is a line that is
30 * already highlighted, indicating where the changes are.
31 * </p>
32 *
33 * @author Bruno Farache
34 */
35 public class DiffResult {
36
37 public static final String SOURCE = "SOURCE";
38
39 public static final String TARGET = "TARGET";
40
41 public DiffResult(int linePos, List<String> changedLines) {
42 _lineNumber = linePos + 1;
43 _changedLines = changedLines;
44 }
45
46 public DiffResult(int linePos, String changedLine) {
47 _lineNumber = linePos + 1;
48 _changedLines = new ArrayList<String>();
49 _changedLines.add(changedLine);
50 }
51
52 public List<String> getChangedLines() {
53 return _changedLines;
54 }
55
56 public void setChangedLines(List<String> changedLines) {
57 _changedLines = changedLines;
58 }
59
60 public int getLineNumber() {
61 return _lineNumber;
62 }
63
64 public void setLineNumber(int lineNumber) {
65 _lineNumber = lineNumber;
66 }
67
68 public boolean equals(Object obj) {
69 DiffResult diffResult = (DiffResult)obj;
70
71 if ((diffResult.getLineNumber() == _lineNumber) &&
72 (diffResult.getChangedLines().equals(_changedLines))) {
73
74 return true;
75 }
76
77 return false;
78 }
79
80 public String toString() {
81 StringBundler sb = new StringBundler(2 * _changedLines.size() + 2);
82
83 sb.append("Line: ");
84 sb.append(_lineNumber);
85 sb.append("\n");
86
87 Iterator<String> itr = _changedLines.iterator();
88
89 while (itr.hasNext()) {
90 sb.append(itr.next());
91
92 if (itr.hasNext()) {
93 sb.append("\n");
94 }
95 }
96
97 return sb.toString();
98 }
99
100 private int _lineNumber;
101 private List<String> _changedLines;
102
103 }