View Javadoc

1   /*
2    * Copyright 2010 The Apache Software Foundation
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance                                                                       with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  package org.apache.hadoop.hbase.filter;
21  
22  import org.apache.hadoop.hbase.KeyValue;
23  
24  import java.util.List;
25  
26  /**
27   * Abstract base class to help you implement new Filters.  Common "ignore" or NOOP type
28   * methods can go here, helping to reduce boiler plate in an ever-expanding filter
29   * library.
30   *
31   * If you could instantiate FilterBase, it would end up being a "null" filter -
32   * that is one that never filters anything.
33   *
34   * @inheritDoc
35   */
36  public abstract class FilterBase implements Filter {
37  
38    /**
39     * Filters that are purely stateless and do nothing in their reset() methods can inherit
40     * this null/empty implementation.
41     *
42     * @inheritDoc
43     */
44    @Override
45    public void reset() {
46    }
47  
48    /**
49     * Filters that do not filter by row key can inherit this implementation that
50     * never filters anything. (ie: returns false).
51     *
52     * @inheritDoc
53     */
54    @Override
55    public boolean filterRowKey(byte [] buffer, int offset, int length) {
56      return false;
57    }
58  
59    /**
60     * Filters that never filter all remaining can inherit this implementation that
61     * never stops the filter early.
62     *
63     * @inheritDoc
64     */
65    @Override
66    public boolean filterAllRemaining() {
67      return false;
68    }
69  
70    /**
71     * Filters that dont filter by key value can inherit this implementation that
72     * includes all KeyValues.
73     *
74     * @inheritDoc
75     */
76    @Override
77    public ReturnCode filterKeyValue(KeyValue ignored) {
78      return ReturnCode.INCLUDE;
79    }
80  
81    /**
82     * Filters that never filter by modifying the returned List of KeyValues can
83     * inherit this implementation that does nothing.
84     *
85     * @inheritDoc
86     */
87    @Override
88    public void filterRow(List<KeyValue> ignored) {
89    }
90  
91    /**
92     * Fitlers that never filter by modifying the returned List of KeyValues can
93     * inherit this implementation that does nothing.
94     *
95     * @inheritDoc
96     */
97    @Override
98    public boolean hasFilterRow() {
99      return false;
100   }
101 
102   /**
103    * Filters that never filter by rows based on previously gathered state from
104    * @{link #filterKeyValue(KeyValue)} can inherit this implementation that
105    * never filters a row.
106    *
107    * @inheritDoc
108    */
109   @Override
110   public boolean filterRow() {
111     return false;
112   }
113 
114   /**
115    * Filters that are not sure which key must be next seeked to, can inherit
116    * this implementation that, by default, returns a null KeyValue.
117    *
118    * @inheritDoc
119    */
120   public KeyValue getNextKeyHint(KeyValue currentKV) {
121     return null;
122   }
123 
124 }