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