1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.revwalk.filter;
11
12 import java.io.IOException;
13
14 import org.eclipse.jgit.errors.IncorrectObjectTypeException;
15 import org.eclipse.jgit.errors.MissingObjectException;
16 import org.eclipse.jgit.errors.StopWalkException;
17 import org.eclipse.jgit.internal.JGitText;
18 import org.eclipse.jgit.revwalk.RevCommit;
19 import org.eclipse.jgit.revwalk.RevWalk;
20
21
22
23
24 public class MaxCountRevFilter extends RevFilter {
25
26 private int maxCount;
27
28 private int count;
29
30
31
32
33
34
35
36
37 public static RevFilter create(int maxCount) {
38 if (maxCount < 0)
39 throw new IllegalArgumentException(
40 JGitText.get().maxCountMustBeNonNegative);
41 return new MaxCountRevFilter(maxCount);
42 }
43
44 private MaxCountRevFilter(int maxCount) {
45 this.count = 0;
46 this.maxCount = maxCount;
47 }
48
49
50 @Override
51 public boolean include(RevWalk walker, RevCommit cmit)
52 throws StopWalkException, MissingObjectException,
53 IncorrectObjectTypeException, IOException {
54 count++;
55 if (count > maxCount)
56 throw StopWalkException.INSTANCE;
57 return true;
58 }
59
60
61 @Override
62 public RevFilter clone() {
63 return new MaxCountRevFilter(maxCount);
64 }
65 }