DiffResult.java |
1 /** 2 * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved. 3 * 4 * 5 * 6 * 7 * The contents of this file are subject to the terms of the Liferay Enterprise 8 * Subscription License ("License"). You may not use this file except in 9 * compliance with the License. You can obtain a copy of the License by 10 * contacting Liferay, Inc. See the License for the specific language governing 11 * permissions and limitations under the License, including but not limited to 12 * distribution rights 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.util.diff; 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 is 38 * already highlighted, indicating where the changes are. 39 * </p> 40 * 41 * @author Bruno Farache 42 * @deprecated This class has been repackaged at 43 * <code>com.liferay.portal.kernel.util</code>. 44 */ 45 public class DiffResult { 46 47 public static final String SOURCE = "SOURCE"; 48 49 public static final String TARGET = "TARGET"; 50 51 public DiffResult(int linePos, List<String> changedLines) { 52 _lineNumber = linePos + 1; 53 _changedLines = changedLines; 54 } 55 56 public DiffResult(int linePos, String changedLine) { 57 _lineNumber = linePos + 1; 58 _changedLines = new ArrayList<String>(); 59 _changedLines.add(changedLine); 60 } 61 62 public List<String> getChangedLines() { 63 return _changedLines; 64 } 65 66 public void setChangedLines(List<String> changedLines) { 67 _changedLines = changedLines; 68 } 69 70 public int getLineNumber() { 71 return _lineNumber; 72 } 73 74 public void setLineNumber(int lineNumber) { 75 _lineNumber = lineNumber; 76 } 77 78 public boolean equals(Object obj) { 79 DiffResult diffResult = (DiffResult)obj; 80 81 if ((diffResult.getLineNumber() == _lineNumber) && 82 (diffResult.getChangedLines().equals(_changedLines))) { 83 84 return true; 85 } 86 87 return false; 88 } 89 90 public String toString() { 91 StringBuilder sb = new StringBuilder(); 92 93 sb.append("Line: "); 94 sb.append(_lineNumber); 95 sb.append("\n"); 96 97 Iterator<String> itr = _changedLines.iterator(); 98 99 while (itr.hasNext()) { 100 sb.append(itr.next()); 101 102 if (itr.hasNext()) { 103 sb.append("\n"); 104 } 105 } 106 107 return sb.toString(); 108 } 109 110 private int _lineNumber; 111 private List<String> _changedLines; 112 113 }