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 @Override
79 public KeyValue transform(KeyValue v) {
80 return filter.transform(v);
81 }
82
83 public boolean filterRow() {
84 boolean filterRow = this.filter.filterRow();
85 changeFAR(filterRow);
86 return filterRow;
87 }
88
89 public void write(DataOutput out) throws IOException {
90 out.writeUTF(this.filter.getClass().getName());
91 this.filter.write(out);
92 }
93
94 public void readFields(DataInput in) throws IOException {
95 String className = in.readUTF();
96 try {
97 this.filter = (Filter)(Class.forName(className).newInstance());
98 this.filter.readFields(in);
99 } catch (InstantiationException e) {
100 throw new RuntimeException("Failed deserialize.", e);
101 } catch (IllegalAccessException e) {
102 throw new RuntimeException("Failed deserialize.", e);
103 } catch (ClassNotFoundException e) {
104 throw new RuntimeException("Failed deserialize.", e);
105 }
106 }
107
108 public boolean isFamilyEssential(byte[] name) {
109 return FilterBase.isFamilyEssential(this.filter, name);
110 }
111
112 @Override
113 public String toString() {
114 return this.getClass().getSimpleName() + " " + this.filter.toString();
115 }
116 }