15
15
*/
16
16
package difflib ;
17
17
18
+ import static com .google .common .base .Preconditions .checkArgument ;
19
+
18
20
import java .util .Arrays ;
19
21
import java .util .List ;
20
22
23
+ import javax .annotation .Nonnegative ;
24
+
21
25
/**
22
26
* Holds the information about the part of text involved in the diff process
23
27
*
33
37
* @param T The type of the compared elements in the 'lines'.
34
38
*/
35
39
public class Chunk <T > {
36
-
40
+ @ Nonnegative
37
41
private final int position ;
38
42
private List <T > lines ;
39
43
@@ -45,7 +49,8 @@ public class Chunk<T> {
45
49
* @param lines
46
50
* the affected lines
47
51
*/
48
- public Chunk (int position , List <T > lines ) {
52
+ public Chunk (@ Nonnegative int position , List <T > lines ) {
53
+ checkArgument (position >= 0 );
49
54
this .position = position ;
50
55
this .lines = lines ;
51
56
}
@@ -54,11 +59,12 @@ public Chunk(int position, List<T> lines) {
54
59
* Creates a chunk and saves a copy of affected lines
55
60
*
56
61
* @param position
57
- * the start position
62
+ * the start position (zero-based numbering)
58
63
* @param lines
59
64
* the affected lines
60
65
*/
61
- public Chunk (int position , T [] lines ) {
66
+ public Chunk (@ Nonnegative int position , T [] lines ) {
67
+ checkArgument (position >= 0 );
62
68
this .position = position ;
63
69
this .lines = Arrays .asList (lines );
64
70
}
@@ -83,8 +89,9 @@ public void verify(List<T> target) throws PatchFailedException {
83
89
}
84
90
85
91
/**
86
- * @return the start position of chunk in the text
92
+ * @return the start position of chunk in the text (zero-based numbering)
87
93
*/
94
+ @ Nonnegative
88
95
public int getPosition () {
89
96
return position ;
90
97
}
@@ -100,13 +107,15 @@ public List<T> getLines() {
100
107
return lines ;
101
108
}
102
109
110
+ @ Nonnegative
103
111
public int size () {
104
112
return lines .size ();
105
113
}
106
114
107
115
/**
108
- * Returns the index of the last line of the chunk.
116
+ * Returns the index of the last line of the chunk. (zero-based numbering)
109
117
*/
118
+ @ Nonnegative
110
119
public int last () {
111
120
return getPosition () + size () - 1 ;
112
121
}
0 commit comments