1 package org.incava.util.diff;
2
3
4
5
6
7
8
9
10
11
12 public class Difference
13 {
14 public static final int NONE = -1;
15
16
17
18
19 private int delStart = NONE;
20
21
22
23
24 private int delEnd = NONE;
25
26
27
28
29 private int addStart = NONE;
30
31
32
33
34 private int addEnd = NONE;
35
36
37
38
39
40 public Difference(int delStart, int delEnd, int addStart, int addEnd)
41 {
42 this.delStart = delStart;
43 this.delEnd = delEnd;
44 this.addStart = addStart;
45 this.addEnd = addEnd;
46 }
47
48
49
50
51
52 public int getDeletedStart()
53 {
54 return delStart;
55 }
56
57
58
59
60
61 public int getDeletedEnd()
62 {
63 return delEnd;
64 }
65
66
67
68
69
70 public int getAddedStart()
71 {
72 return addStart;
73 }
74
75
76
77
78
79 public int getAddedEnd()
80 {
81 return addEnd;
82 }
83
84
85
86
87
88 public void setDeleted(int line)
89 {
90 delStart = Math.min(line, delStart);
91 delEnd = Math.max(line, delEnd);
92 }
93
94
95
96
97
98 public void setAdded(int line)
99 {
100 addStart = Math.min(line, addStart);
101 addEnd = Math.max(line, addEnd);
102 }
103
104
105
106
107
108 public boolean equals(Object obj)
109 {
110 if (obj instanceof Difference) {
111 Difference other = (Difference)obj;
112
113 return (delStart == other.delStart &&
114 delEnd == other.delEnd &&
115 addStart == other.addStart &&
116 addEnd == other.addEnd);
117 }
118 else {
119 return false;
120 }
121 }
122
123
124
125
126 public String toString()
127 {
128 StringBuffer buf = new StringBuffer();
129 buf.append("del: [" + delStart + ", " + delEnd + "]");
130 buf.append(" ");
131 buf.append("add: [" + addStart + ", " + addEnd + "]");
132 return buf.toString();
133 }
134
135 }