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 public abstract class FilterBase implements Filter { 35 36 /** 37 * Filters that are purely stateless and do nothing in their reset() methods can inherit 38 * this null/empty implementation. 39 * 40 * @inheritDoc 41 */ 42 @Override 43 public void reset() { 44 } 45 46 /** 47 * Filters that do not filter by row key can inherit this implementation that 48 * never filters anything. (ie: returns false). 49 * 50 * @inheritDoc 51 */ 52 @Override 53 public boolean filterRowKey(byte [] buffer, int offset, int length) { 54 return false; 55 } 56 57 /** 58 * Filters that never filter all remaining can inherit this implementation that 59 * never stops the filter early. 60 * 61 * @inheritDoc 62 */ 63 @Override 64 public boolean filterAllRemaining() { 65 return false; 66 } 67 68 /** 69 * Filters that dont filter by key value can inherit this implementation that 70 * includes all KeyValues. 71 * 72 * @inheritDoc 73 */ 74 @Override 75 public ReturnCode filterKeyValue(KeyValue ignored) { 76 return ReturnCode.INCLUDE; 77 } 78 79 /** 80 * Filters that never filter by modifying the returned List of KeyValues can 81 * inherit this implementation that does nothing. 82 * 83 * @inheritDoc 84 */ 85 @Override 86 public void filterRow(List<KeyValue> ignored) { 87 } 88 89 /** 90 * Fitlers that never filter by modifying the returned List of KeyValues can 91 * inherit this implementation that does nothing. 92 * 93 * @inheritDoc 94 */ 95 @Override 96 public boolean hasFilterRow() { 97 return false; 98 } 99 100 /** 101 * Filters that never filter by rows based on previously gathered state from 102 * {@link #filterKeyValue(KeyValue)} can inherit this implementation that 103 * never filters a row. 104 * 105 * @inheritDoc 106 */ 107 @Override 108 public boolean filterRow() { 109 return false; 110 } 111 112 /** 113 * Filters that are not sure which key must be next seeked to, can inherit 114 * this implementation that, by default, returns a null KeyValue. 115 * 116 * @inheritDoc 117 */ 118 public KeyValue getNextKeyHint(KeyValue currentKV) { 119 return null; 120 } 121 122 }