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;
022import org.apache.commons.lang3.StringUtils;
023import org.apache.yetus.audience.InterfaceAudience;
024
025/**
026 * Filter to use to filter the QuotaRetriever results.
027 */
028@InterfaceAudience.Public
029public class QuotaFilter {
030  private Set<QuotaType> types = new HashSet<>();
031  private boolean hasFilters = false;
032  private String namespaceRegex;
033  private String tableRegex;
034  private String userRegex;
035  private String regionServerRegex;
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   * Set the region server filter regex
075   * @param regex the region server filter
076   * @return the quota filter object
077   */
078  public QuotaFilter setRegionServerFilter(final String regex) {
079    this.regionServerRegex = regex;
080    hasFilters |= StringUtils.isNotEmpty(regex);
081    return this;
082  }
083
084  /**
085   * Add a type to the filter list
086   * @param type the type to filter on
087   * @return the quota filter object
088   */
089  public QuotaFilter addTypeFilter(final QuotaType type) {
090    this.types.add(type);
091    hasFilters |= true;
092    return this;
093  }
094
095  /** Returns true if the filter is empty */
096  public boolean isNull() {
097    return !hasFilters;
098  }
099
100  /** Returns the QuotaType types that we want to filter one */
101  public Set<QuotaType> getTypeFilters() {
102    return types;
103  }
104
105  /** Returns the Namespace filter regex */
106  public String getNamespaceFilter() {
107    return namespaceRegex;
108  }
109
110  /** Returns the Table filter regex */
111  public String getTableFilter() {
112    return tableRegex;
113  }
114
115  /** Returns the User filter regex */
116  public String getUserFilter() {
117    return userRegex;
118  }
119
120  /** Returns the RegionServer filter regex */
121  public String getRegionServerFilter() {
122    return regionServerRegex;
123  }
124}