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  private String regionServerRegex;
037
038  public QuotaFilter() {
039  }
040
041  /**
042   * Set the user filter regex
043   * @param regex the user filter
044   * @return the quota filter object
045   */
046  public QuotaFilter setUserFilter(final String regex) {
047    this.userRegex = regex;
048    hasFilters |= StringUtils.isNotEmpty(regex);
049    return this;
050  }
051
052  /**
053   * Set the table filter regex
054   * @param regex the table filter
055   * @return the quota filter object
056   */
057  public QuotaFilter setTableFilter(final String regex) {
058    this.tableRegex = regex;
059    hasFilters |= StringUtils.isNotEmpty(regex);
060    return this;
061  }
062
063  /**
064   * Set the namespace filter regex
065   * @param regex the namespace filter
066   * @return the quota filter object
067   */
068  public QuotaFilter setNamespaceFilter(final String regex) {
069    this.namespaceRegex = regex;
070    hasFilters |= StringUtils.isNotEmpty(regex);
071    return this;
072  }
073
074  /**
075   * Set the region server filter regex
076   * @param regex the region server filter
077   * @return the quota filter object
078   */
079  public QuotaFilter setRegionServerFilter(final String regex) {
080    this.regionServerRegex = regex;
081    hasFilters |= StringUtils.isNotEmpty(regex);
082    return this;
083  }
084
085  /**
086   * Add a type to the filter list
087   * @param type the type to filter on
088   * @return the quota filter object
089   */
090  public QuotaFilter addTypeFilter(final QuotaType type) {
091    this.types.add(type);
092    hasFilters |= true;
093    return this;
094  }
095
096  /** @return true if the filter is empty */
097  public boolean isNull() {
098    return !hasFilters;
099  }
100
101  /** @return the QuotaType types that we want to filter one */
102  public Set<QuotaType> getTypeFilters() {
103    return types;
104  }
105
106  /** @return the Namespace filter regex */
107  public String getNamespaceFilter() {
108    return namespaceRegex;
109  }
110
111  /** @return the Table filter regex */
112  public String getTableFilter() {
113    return tableRegex;
114  }
115
116  /** @return the User filter regex */
117  public String getUserFilter() {
118    return userRegex;
119  }
120
121  /** @return the RegionServer filter regex */
122  public String getRegionServerFilter() {
123    return regionServerRegex;
124  }
125}