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
036 public class DiffResult {
037
038 public static final String SOURCE = "SOURCE";
039
040 public static final String TARGET = "TARGET";
041
042 public DiffResult(int linePos, List<String> changedLines) {
043 _lineNumber = linePos + 1;
044 _changedLines = changedLines;
045 }
046
047 public DiffResult(int linePos, String changedLine) {
048 _lineNumber = linePos + 1;
049 _changedLines = new ArrayList<String>();
050 _changedLines.add(changedLine);
051 }
052
053 @Override
054 public boolean equals(Object obj) {
055 if (this == obj) {
056 return true;
057 }
058
059 if (!(obj instanceof DiffResult)) {
060 return false;
061 }
062
063 DiffResult diffResult = (DiffResult)obj;
064
065 if ((diffResult.getLineNumber() == _lineNumber) &&
066 diffResult.getChangedLines().equals(_changedLines)) {
067
068 return true;
069 }
070
071 return false;
072 }
073
074 public List<String> getChangedLines() {
075 return _changedLines;
076 }
077
078 public int getLineNumber() {
079 return _lineNumber;
080 }
081
082 public void setChangedLines(List<String> changedLines) {
083 _changedLines = changedLines;
084 }
085
086 public void setLineNumber(int lineNumber) {
087 _lineNumber = lineNumber;
088 }
089
090 @Override
091 public String toString() {
092 StringBundler sb = new StringBundler(_changedLines.size() * 2 + 3);
093
094 sb.append("Line: ");
095 sb.append(_lineNumber);
096 sb.append("\n");
097
098 Iterator<String> itr = _changedLines.iterator();
099
100 while (itr.hasNext()) {
101 sb.append(itr.next());
102
103 if (itr.hasNext()) {
104 sb.append("\n");
105 }
106 }
107
108 return sb.toString();
109 }
110
111 private List<String> _changedLines;
112 private int _lineNumber;
113
114 }