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.client; 019 020import java.util.List; 021import org.apache.hadoop.hbase.TableName; 022import org.apache.yetus.audience.InterfaceAudience; 023 024/** 025 * A collection of criteria used for table selection. The logic of table selection is as follows: 026 * <ul> 027 * <li>When no parameter values are provided, an unfiltered list of all user tables is returned. 028 * </li> 029 * <li>When a list of {@link TableName TableNames} are provided, the filter starts with any of these 030 * tables that exist.</li> 031 * <li>When a {@code namespace} name is provided, the filter starts with all the tables present in 032 * that namespace.</li> 033 * <li>If both a list of {@link TableName TableNames} and a {@code namespace} name are provided, the 034 * {@link TableName} list is honored and the {@code namespace} name is ignored.</li> 035 * <li>If a {@code regex} is provided, this subset of {@link TableName TableNames} is further 036 * reduced to those that match the provided regular expression.</li> 037 * </ul> 038 */ 039@InterfaceAudience.Public 040public final class NormalizeTableFilterParams { 041 private final List<TableName> tableNames; 042 private final String regex; 043 private final String namespace; 044 045 private NormalizeTableFilterParams(final List<TableName> tableNames, final String regex, 046 final String namespace) { 047 this.tableNames = tableNames; 048 this.regex = regex; 049 this.namespace = namespace; 050 } 051 052 public List<TableName> getTableNames() { 053 return tableNames; 054 } 055 056 public String getRegex() { 057 return regex; 058 } 059 060 public String getNamespace() { 061 return namespace; 062 } 063 064 /** 065 * Used to instantiate an instance of {@link NormalizeTableFilterParams}. 066 */ 067 public static class Builder { 068 private List<TableName> tableNames; 069 private String regex; 070 private String namespace; 071 072 public Builder tableFilterParams(final NormalizeTableFilterParams ntfp) { 073 this.tableNames = ntfp.getTableNames(); 074 this.regex = ntfp.getRegex(); 075 this.namespace = ntfp.getNamespace(); 076 return this; 077 } 078 079 public Builder tableNames(final List<TableName> tableNames) { 080 this.tableNames = tableNames; 081 return this; 082 } 083 084 public Builder regex(final String regex) { 085 this.regex = regex; 086 return this; 087 } 088 089 public Builder namespace(final String namespace) { 090 this.namespace = namespace; 091 return this; 092 } 093 094 public NormalizeTableFilterParams build() { 095 return new NormalizeTableFilterParams(tableNames, regex, namespace); 096 } 097 } 098}