001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.quotas; 019 020import java.util.HashSet; 021import java.util.Set; 022 023import org.apache.commons.lang3.StringUtils; 024import org.apache.yetus.audience.InterfaceAudience; 025 026/** 027 * Filter to use to filter the QuotaRetriever results. 028 */ 029@InterfaceAudience.Public 030public class QuotaFilter { 031 private Set<QuotaType> types = new HashSet<>(); 032 private boolean hasFilters = false; 033 private String namespaceRegex; 034 private String tableRegex; 035 private String userRegex; 036 037 public QuotaFilter() { 038 } 039 040 /** 041 * Set the user filter regex 042 * @param regex the user filter 043 * @return the quota filter object 044 */ 045 public QuotaFilter setUserFilter(final String regex) { 046 this.userRegex = regex; 047 hasFilters |= StringUtils.isNotEmpty(regex); 048 return this; 049 } 050 051 /** 052 * Set the table filter regex 053 * @param regex the table filter 054 * @return the quota filter object 055 */ 056 public QuotaFilter setTableFilter(final String regex) { 057 this.tableRegex = regex; 058 hasFilters |= StringUtils.isNotEmpty(regex); 059 return this; 060 } 061 062 /** 063 * Set the namespace filter regex 064 * @param regex the namespace filter 065 * @return the quota filter object 066 */ 067 public QuotaFilter setNamespaceFilter(final String regex) { 068 this.namespaceRegex = regex; 069 hasFilters |= StringUtils.isNotEmpty(regex); 070 return this; 071 } 072 073 /** 074 * Add a type to the filter list 075 * @param type the type to filter on 076 * @return the quota filter object 077 */ 078 public QuotaFilter addTypeFilter(final QuotaType type) { 079 this.types.add(type); 080 hasFilters |= true; 081 return this; 082 } 083 084 /** @return true if the filter is empty */ 085 public boolean isNull() { 086 return !hasFilters; 087 } 088 089 /** @return the QuotaType types that we want to filter one */ 090 public Set<QuotaType> getTypeFilters() { 091 return types; 092 } 093 094 /** @return the Namespace filter regex */ 095 public String getNamespaceFilter() { 096 return namespaceRegex; 097 } 098 099 /** @return the Table filter regex */ 100 public String getTableFilter() { 101 return tableRegex; 102 } 103 104 /** @return the User filter regex */ 105 public String getUserFilter() { 106 return userRegex; 107 } 108}