001
014
015 package com.liferay.util.diff;
016
017 import com.liferay.portal.kernel.util.StringBundler;
018
019 import java.util.ArrayList;
020 import java.util.Iterator;
021 import java.util.List;
022
023
037 public class DiffResult {
038
039 public static final String SOURCE = "SOURCE";
040
041 public static final String TARGET = "TARGET";
042
043 public DiffResult(int linePos, List<String> changedLines) {
044 _lineNumber = linePos + 1;
045 _changedLines = changedLines;
046 }
047
048 public DiffResult(int linePos, String changedLine) {
049 _lineNumber = linePos + 1;
050 _changedLines = new ArrayList<String>();
051 _changedLines.add(changedLine);
052 }
053
054 public List<String> getChangedLines() {
055 return _changedLines;
056 }
057
058 public void setChangedLines(List<String> changedLines) {
059 _changedLines = changedLines;
060 }
061
062 public int getLineNumber() {
063 return _lineNumber;
064 }
065
066 public void setLineNumber(int lineNumber) {
067 _lineNumber = lineNumber;
068 }
069
070 public boolean equals(Object obj) {
071 DiffResult diffResult = (DiffResult)obj;
072
073 if ((diffResult.getLineNumber() == _lineNumber) &&
074 (diffResult.getChangedLines().equals(_changedLines))) {
075
076 return true;
077 }
078
079 return false;
080 }
081
082 public String toString() {
083 StringBundler sb = new StringBundler(_changedLines.size() * 2 + 3);
084
085 sb.append("Line: ");
086 sb.append(_lineNumber);
087 sb.append("\n");
088
089 Iterator<String> itr = _changedLines.iterator();
090
091 while (itr.hasNext()) {
092 sb.append(itr.next());
093
094 if (itr.hasNext()) {
095 sb.append("\n");
096 }
097 }
098
099 return sb.toString();
100 }
101
102 private int _lineNumber;
103 private List<String> _changedLines;
104
105 }