1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.hadoop.hbase.filter;
22
23 import org.apache.hadoop.hbase.KeyValue;
24
25 import java.io.DataInput;
26 import java.io.DataOutput;
27 import java.io.IOException;
28 import java.util.List;
29
30
31
32
33
34
35
36
37
38 public class WhileMatchFilter extends FilterBase {
39 private boolean filterAllRemaining = false;
40 private Filter filter;
41
42 public WhileMatchFilter() {
43 super();
44 }
45
46 public WhileMatchFilter(Filter filter) {
47 this.filter = filter;
48 }
49
50 public Filter getFilter() {
51 return filter;
52 }
53
54 public void reset() {
55 this.filter.reset();
56 }
57
58 private void changeFAR(boolean value) {
59 filterAllRemaining = filterAllRemaining || value;
60 }
61
62 public boolean filterAllRemaining() {
63 return this.filterAllRemaining || this.filter.filterAllRemaining();
64 }
65
66 public boolean filterRowKey(byte[] buffer, int offset, int length) {
67 boolean value = filter.filterRowKey(buffer, offset, length);
68 changeFAR(value);
69 return value;
70 }
71
72 public ReturnCode filterKeyValue(KeyValue v) {
73 ReturnCode c = filter.filterKeyValue(v);
74 changeFAR(c != ReturnCode.INCLUDE);
75 return c;
76 }
77
78 public boolean filterRow() {
79 boolean filterRow = this.filter.filterRow();
80 changeFAR(filterRow);
81 return filterRow;
82 }
83
84 public void write(DataOutput out) throws IOException {
85 out.writeUTF(this.filter.getClass().getName());
86 this.filter.write(out);
87 }
88
89 public void readFields(DataInput in) throws IOException {
90 String className = in.readUTF();
91 try {
92 this.filter = (Filter)(Class.forName(className).newInstance());
93 this.filter.readFields(in);
94 } catch (InstantiationException e) {
95 throw new RuntimeException("Failed deserialize.", e);
96 } catch (IllegalAccessException e) {
97 throw new RuntimeException("Failed deserialize.", e);
98 } catch (ClassNotFoundException e) {
99 throw new RuntimeException("Failed deserialize.", e);
100 }
101 }
102 }