You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by zh...@apache.org on 2018/01/03 01:40:34 UTC
[02/34] hbase git commit: HBASE-19683 Remove Superfluous Methods From
String Class (BELUGA BEHR).
HBASE-19683 Remove Superfluous Methods From String Class (BELUGA BEHR).
* Remove isEmpty method
* Remove repeat
Use the Apache Commons implementations instead.
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/4e9f4abb
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/4e9f4abb
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/4e9f4abb
Branch: refs/heads/HBASE-19397
Commit: 4e9f4abb144a92740c212b4c30628d57e5141cf1
Parents: 9c2a355
Author: BELUGA BEHR <da...@gmail.com>
Authored: Tue Jan 2 11:12:38 2018 -0800
Committer: Apekshit Sharma <ap...@apache.org>
Committed: Tue Jan 2 11:12:38 2018 -0800
----------------------------------------------------------------------
.../replication/ReplicationPeerConfigUtil.java | 3 +--
.../apache/hadoop/hbase/quotas/QuotaFilter.java | 8 +++----
.../hadoop/hbase/quotas/QuotaTableUtil.java | 12 +++++-----
.../apache/hadoop/hbase/KeyValueTestUtil.java | 9 +++----
.../org/apache/hadoop/hbase/util/Strings.java | 25 ++------------------
5 files changed, 18 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/4e9f4abb/hbase-client/src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationPeerConfigUtil.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationPeerConfigUtil.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationPeerConfigUtil.java
index 9270fc2..022bf64 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationPeerConfigUtil.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationPeerConfigUtil.java
@@ -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(":");
http://git-wip-us.apache.org/repos/asf/hbase/blob/4e9f4abb/hbase-client/src/main/java/org/apache/hadoop/hbase/quotas/QuotaFilter.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/quotas/QuotaFilter.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/quotas/QuotaFilter.java
index f4bdf27..30cdaf1 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/quotas/QuotaFilter.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/quotas/QuotaFilter.java
@@ -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;
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/4e9f4abb/hbase-client/src/main/java/org/apache/hadoop/hbase/quotas/QuotaTableUtil.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/quotas/QuotaTableUtil.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/quotas/QuotaTableUtil.java
index ded6303..5c28407 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/quotas/QuotaTableUtil.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/quotas/QuotaTableUtil.java
@@ -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)));
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/4e9f4abb/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueTestUtil.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueTestUtil.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueTestUtil.java
index 57b9647..3e82f93 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueTestUtil.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueTestUtil.java
@@ -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);
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/4e9f4abb/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Strings.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Strings.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Strings.java
index f1c530d..033d3ec 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Strings.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Strings.java
@@ -18,6 +18,7 @@
*/
package org.apache.hadoop.hbase.util;
+import org.apache.commons.lang3.StringUtils;
import org.apache.yetus.audience.InterfaceAudience;
/**
@@ -76,15 +77,6 @@ public class Strings {
}
/**
- * 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
* @param padding the character to repeat to the left of the input string
@@ -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;
}
}