HBASE-19683 Remove Superfluous Methods From String Class (BELUGA BEHR).

* Remove isEmpty method
* Remove repeat
Use the Apache Commons implementations instead.
This commit is contained in:
BELUGA BEHR 2018-01-02 11:12:38 -08:00 committed by Apekshit Sharma
parent 9c2a35542f
commit 4e9f4abb14
5 changed files with 18 additions and 39 deletions

View File

@ -39,7 +39,6 @@ import org.apache.hadoop.hbase.replication.ReplicationPeerConfig;
import org.apache.hadoop.hbase.replication.ReplicationPeerConfigBuilder;
import org.apache.hadoop.hbase.replication.ReplicationPeerDescription;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Strings;
import org.apache.yetus.audience.InterfaceAudience;
import org.apache.yetus.audience.InterfaceStability;
import org.slf4j.Logger;
@ -164,7 +163,7 @@ public final class ReplicationPeerConfigUtil {
for (int i = 0, n = tableCFs.length; i < n; i++) {
ReplicationProtos.TableCF tableCF = tableCFs[i];
String namespace = tableCF.getTableName().getNamespace().toStringUtf8();
if (!Strings.isEmpty(namespace)) {
if (StringUtils.isNotEmpty(namespace)) {
sb.append(namespace).append(".").
append(tableCF.getTableName().getQualifier().toStringUtf8())
.append(":");

View File

@ -20,8 +20,8 @@ package org.apache.hadoop.hbase.quotas;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.apache.yetus.audience.InterfaceAudience;
import org.apache.hadoop.hbase.util.Strings;
/**
* Filter to use to filter the QuotaRetriever results.
@ -44,7 +44,7 @@ public class QuotaFilter {
*/
public QuotaFilter setUserFilter(final String regex) {
this.userRegex = regex;
hasFilters |= !Strings.isEmpty(regex);
hasFilters |= StringUtils.isNotEmpty(regex);
return this;
}
@ -55,7 +55,7 @@ public class QuotaFilter {
*/
public QuotaFilter setTableFilter(final String regex) {
this.tableRegex = regex;
hasFilters |= !Strings.isEmpty(regex);
hasFilters |= StringUtils.isNotEmpty(regex);
return this;
}
@ -66,7 +66,7 @@ public class QuotaFilter {
*/
public QuotaFilter setNamespaceFilter(final String regex) {
this.namespaceRegex = regex;
hasFilters |= !Strings.isEmpty(regex);
hasFilters |= StringUtils.isNotEmpty(regex);
return this;
}

View File

@ -28,6 +28,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellScanner;
import org.apache.hadoop.hbase.CompareOperator;
@ -69,7 +70,6 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.GetSpaceQuo
import org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Quotas;
import org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Strings;
/**
* Helper class to interact with the quota table.
@ -191,11 +191,11 @@ public class QuotaTableUtil {
*/
public static Filter makeFilter(final QuotaFilter filter) {
FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL);
if (!Strings.isEmpty(filter.getUserFilter())) {
if (StringUtils.isNotEmpty(filter.getUserFilter())) {
FilterList userFilters = new FilterList(FilterList.Operator.MUST_PASS_ONE);
boolean hasFilter = false;
if (!Strings.isEmpty(filter.getNamespaceFilter())) {
if (StringUtils.isNotEmpty(filter.getNamespaceFilter())) {
FilterList nsFilters = new FilterList(FilterList.Operator.MUST_PASS_ALL);
nsFilters.addFilter(new RowFilter(CompareOperator.EQUAL,
new RegexStringComparator(getUserRowKeyRegex(filter.getUserFilter()), 0)));
@ -205,7 +205,7 @@ public class QuotaTableUtil {
userFilters.addFilter(nsFilters);
hasFilter = true;
}
if (!Strings.isEmpty(filter.getTableFilter())) {
if (StringUtils.isNotEmpty(filter.getTableFilter())) {
FilterList tableFilters = new FilterList(FilterList.Operator.MUST_PASS_ALL);
tableFilters.addFilter(new RowFilter(CompareOperator.EQUAL,
new RegexStringComparator(getUserRowKeyRegex(filter.getUserFilter()), 0)));
@ -221,10 +221,10 @@ public class QuotaTableUtil {
}
filterList.addFilter(userFilters);
} else if (!Strings.isEmpty(filter.getTableFilter())) {
} else if (StringUtils.isNotEmpty(filter.getTableFilter())) {
filterList.addFilter(new RowFilter(CompareOperator.EQUAL,
new RegexStringComparator(getTableRowKeyRegex(filter.getTableFilter()), 0)));
} else if (!Strings.isEmpty(filter.getNamespaceFilter())) {
} else if (StringUtils.isNotEmpty(filter.getNamespaceFilter())) {
filterList.addFilter(new RowFilter(CompareOperator.EQUAL,
new RegexStringComparator(getNamespaceRowKeyRegex(filter.getNamespaceFilter()), 0)));
}

View File

@ -23,6 +23,7 @@ import java.util.Collection;
import java.util.List;
import org.apache.commons.collections4.IterableUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Strings;
import org.apache.yetus.audience.InterfaceAudience;
@ -152,10 +153,10 @@ public class KeyValueTestUtil {
int spacesAfterQualifier = maxQualifierLength - getQualifierString(kv).length() + 1;
int spacesAfterTimestamp = maxTimestampLength
- Long.valueOf(kv.getTimestamp()).toString().length() + 1;
return leadingLengths + getRowString(kv) + Strings.repeat(' ', spacesAfterRow)
+ familyLength + getFamilyString(kv) + Strings.repeat(' ', spacesAfterFamily)
+ getQualifierString(kv) + Strings.repeat(' ', spacesAfterQualifier)
+ getTimestampString(kv) + Strings.repeat(' ', spacesAfterTimestamp)
return leadingLengths + getRowString(kv) + StringUtils.repeat(' ', spacesAfterRow)
+ familyLength + getFamilyString(kv) + StringUtils.repeat(' ', spacesAfterFamily)
+ getQualifierString(kv) + StringUtils.repeat(' ', spacesAfterQualifier)
+ getTimestampString(kv) + StringUtils.repeat(' ', spacesAfterTimestamp)
+ getTypeString(kv) + " " + getValueString(kv);
}

View File

@ -18,6 +18,7 @@
*/
package org.apache.hadoop.hbase.util;
import org.apache.commons.lang3.StringUtils;
import org.apache.yetus.audience.InterfaceAudience;
/**
@ -75,15 +76,6 @@ public class Strings {
return dnPtr.endsWith(".") ? dnPtr.substring(0, dnPtr.length()-1) : dnPtr;
}
/**
* Null-safe length check.
* @param input
* @return true if null or length==0
*/
public static boolean isEmpty(String input) {
return input == null || input.length() == 0;
}
/**
* Push the input string to the right by appending a character before it, usually a space.
* @param input the string to pad
@ -96,19 +88,6 @@ public class Strings {
throw new IllegalArgumentException("input \"" + input + "\" longer than maxLength=" + length);
}
int numPaddingCharacters = length - input.length();
return repeat(padding, numPaddingCharacters) + input;
}
/**
* @param c repeat this character
* @param reapeatFor the length of the output String
* @return c, repeated repeatFor times
*/
public static String repeat(char c, int reapeatFor) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < reapeatFor; ++i) {
sb.append(c);
}
return sb.toString();
return StringUtils.repeat(padding, numPaddingCharacters) + input;
}
}