1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase.filter;
21
22 import org.apache.hadoop.hbase.KeyValue;
23
24 import java.io.DataInput;
25 import java.io.DataOutput;
26 import java.io.IOException;
27 import java.util.List;
28 import java.util.ArrayList;
29
30 import com.google.common.base.Preconditions;
31
32
33
34
35
36
37
38
39
40
41
42 public class PageFilter extends FilterBase {
43 private long pageSize = Long.MAX_VALUE;
44 private int rowsAccepted = 0;
45
46
47
48
49
50 public PageFilter() {
51 super();
52 }
53
54
55
56
57
58
59 public PageFilter(final long pageSize) {
60 Preconditions.checkArgument(pageSize >= 0, "must be positive %s", pageSize);
61 this.pageSize = pageSize;
62 }
63
64 public long getPageSize() {
65 return pageSize;
66 }
67
68 public boolean filterAllRemaining() {
69 return this.rowsAccepted >= this.pageSize;
70 }
71
72 public boolean filterRow() {
73 this.rowsAccepted++;
74 return this.rowsAccepted > this.pageSize;
75 }
76
77 public static Filter createFilterFromArguments(ArrayList<byte []> filterArguments) {
78 Preconditions.checkArgument(filterArguments.size() == 1,
79 "Expected 1 but got: %s", filterArguments.size());
80 long pageSize = ParseFilter.convertByteArrayToLong(filterArguments.get(0));
81 return new PageFilter(pageSize);
82 }
83
84 public void readFields(final DataInput in) throws IOException {
85 this.pageSize = in.readLong();
86 }
87
88 public void write(final DataOutput out) throws IOException {
89 out.writeLong(pageSize);
90 }
91
92 @Override
93 public String toString() {
94 return this.getClass().getSimpleName() + " " + this.pageSize;
95 }
96 }