Skip to content
This repository was archived by the owner on Nov 12, 2019. It is now read-only.

Commit 06a4581

Browse files
committed
explain that position and last start from zero
1 parent 06eeedc commit 06a4581

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

Diff for: src/main/java/difflib/Chunk.java

+15-6
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@
1515
*/
1616
package difflib;
1717

18+
import static com.google.common.base.Preconditions.checkArgument;
19+
1820
import java.util.Arrays;
1921
import java.util.List;
2022

23+
import javax.annotation.Nonnegative;
24+
2125
/**
2226
* Holds the information about the part of text involved in the diff process
2327
*
@@ -33,7 +37,7 @@
3337
* @param T The type of the compared elements in the 'lines'.
3438
*/
3539
public class Chunk<T> {
36-
40+
@Nonnegative
3741
private final int position;
3842
private List<T> lines;
3943

@@ -45,7 +49,8 @@ public class Chunk<T> {
4549
* @param lines
4650
* the affected lines
4751
*/
48-
public Chunk(int position, List<T> lines) {
52+
public Chunk(@Nonnegative int position, List<T> lines) {
53+
checkArgument(position >= 0);
4954
this.position = position;
5055
this.lines = lines;
5156
}
@@ -54,11 +59,12 @@ public Chunk(int position, List<T> lines) {
5459
* Creates a chunk and saves a copy of affected lines
5560
*
5661
* @param position
57-
* the start position
62+
* the start position (zero-based numbering)
5863
* @param lines
5964
* the affected lines
6065
*/
61-
public Chunk(int position, T[] lines) {
66+
public Chunk(@Nonnegative int position, T[] lines) {
67+
checkArgument(position >= 0);
6268
this.position = position;
6369
this.lines = Arrays.asList(lines);
6470
}
@@ -83,8 +89,9 @@ public void verify(List<T> target) throws PatchFailedException {
8389
}
8490

8591
/**
86-
* @return the start position of chunk in the text
92+
* @return the start position of chunk in the text (zero-based numbering)
8793
*/
94+
@Nonnegative
8895
public int getPosition() {
8996
return position;
9097
}
@@ -100,13 +107,15 @@ public List<T> getLines() {
100107
return lines;
101108
}
102109

110+
@Nonnegative
103111
public int size() {
104112
return lines.size();
105113
}
106114

107115
/**
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)
109117
*/
118+
@Nonnegative
110119
public int last() {
111120
return getPosition() + size() - 1;
112121
}

0 commit comments

Comments
 (0)