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