kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From guozh...@apache.org
Subject [kafka] branch trunk updated: MINOR: Replace empty string concattenation with String.valueOf() where possible. (#4369)
Date Fri, 26 Jan 2018 19:43:51 GMT
This is an automated email from the ASF dual-hosted git repository.

guozhang pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 1fef10d  MINOR: Replace empty string concattenation with String.valueOf() where possible.
(#4369)
1fef10d is described below

commit 1fef10d47f8b7481b4fed8f5366c6780d9c7d733
Author: Koen De Groote <kdg.private@gmail.com>
AuthorDate: Fri Jan 26 20:43:48 2018 +0100

    MINOR: Replace empty string concattenation with String.valueOf() where possible. (#4369)
    
    This is something I did after my working hours, I would ask people reviewing this do the
same, don't take time for this during your work hours.
    
    I try to keep such a PR as limited as possible, for clarity of reading.
    
    ==========
    
    Using an empty string concat in order to achieve the String representation of the value
you want is bad for 2 reasons, as explained here: (https://stackoverflow.com/questions/1572708/is-conversion-to-string-using-int-value-bad-practice
    
    Readability: it shows what you're trying to do.
    
    Depending on your compiler, it might attempt to create your String by first creating a
StringBuffer, appending your value to it and then doing .toString() on that. Which is inefficient.
    
    Also, the Metrics.java file had an empty string being added for the sole reason that the
page width forced a string to continue on a new line. Removed that.
    
    Reviewers: Guozhang Wang <wangguoz@gmail.com>
---
 clients/src/main/java/org/apache/kafka/common/metrics/Metrics.java    | 2 +-
 clients/src/main/java/org/apache/kafka/common/utils/Utils.java        | 4 ++--
 .../kafka/streams/processor/internals/InternalTopologyBuilder.java    | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/clients/src/main/java/org/apache/kafka/common/metrics/Metrics.java b/clients/src/main/java/org/apache/kafka/common/metrics/Metrics.java
index 8127022..68e1f47 100644
--- a/clients/src/main/java/org/apache/kafka/common/metrics/Metrics.java
+++ b/clients/src/main/java/org/apache/kafka/common/metrics/Metrics.java
@@ -591,7 +591,7 @@ public class Metrics implements Closeable {
         Set<String> templateTagKeys = template.tags();
         
         if (!runtimeTagKeys.equals(templateTagKeys)) {
-            throw new IllegalArgumentException("For '" + template.name() + "', runtime-defined
metric tags do not match the tags in the template. " + ""
+            throw new IllegalArgumentException("For '" + template.name() + "', runtime-defined
metric tags do not match the tags in the template. "
                     + "Runtime = " + runtimeTagKeys.toString() + " Template = " + templateTagKeys.toString());
         }
                 
diff --git a/clients/src/main/java/org/apache/kafka/common/utils/Utils.java b/clients/src/main/java/org/apache/kafka/common/utils/Utils.java
index 9da3822..dff6107 100755
--- a/clients/src/main/java/org/apache/kafka/common/utils/Utils.java
+++ b/clients/src/main/java/org/apache/kafka/common/utils/Utils.java
@@ -433,7 +433,7 @@ public final class Utils {
      */
     public static String formatBytes(long bytes) {
         if (bytes < 0) {
-            return "" + bytes;
+            return String.valueOf(bytes);
         }
         double asDouble = (double) bytes;
         int ordinal = (int) Math.floor(Math.log(asDouble) / Math.log(1024.0));
@@ -444,7 +444,7 @@ public final class Utils {
             return formatted + " " + BYTE_SCALE_SUFFIXES[ordinal];
         } catch (IndexOutOfBoundsException e) {
             //huge number?
-            return "" + asDouble;
+            return String.valueOf(asDouble);
         }
     }
 
diff --git a/streams/src/main/java/org/apache/kafka/streams/processor/internals/InternalTopologyBuilder.java
b/streams/src/main/java/org/apache/kafka/streams/processor/internals/InternalTopologyBuilder.java
index 2f3f7f4..2402d2e 100644
--- a/streams/src/main/java/org/apache/kafka/streams/processor/internals/InternalTopologyBuilder.java
+++ b/streams/src/main/java/org/apache/kafka/streams/processor/internals/InternalTopologyBuilder.java
@@ -296,7 +296,7 @@ public class InternalTopologyBuilder {
             // yet and hence the map from source node to topics is stale, in this case we
put the pattern as a place holder;
             // this should only happen for debugging since during runtime this function should
always be called after the metadata has updated.
             if (subscribedTopics.isEmpty()) {
-                return Collections.singletonList("" + pattern + "");
+                return Collections.singletonList(String.valueOf(pattern));
             }
 
             final List<String> matchedTopics = new ArrayList<>();
@@ -325,7 +325,7 @@ public class InternalTopologyBuilder {
             // yet and hence the map from source node to topics is stale, in this case we
put the pattern as a place holder;
             // this should only happen for debugging since during runtime this function should
always be called after the metadata has updated.
             if (sourceTopics == null) {
-                return new SourceNode<>(name, Collections.singletonList("" + pattern
+ ""), timestampExtractor, keyDeserializer, valDeserializer);
+                return new SourceNode<>(name, Collections.singletonList(String.valueOf(pattern)),
timestampExtractor, keyDeserializer, valDeserializer);
             } else {
                 return new SourceNode<>(name, maybeDecorateInternalSourceTopics(sourceTopics),
timestampExtractor, keyDeserializer, valDeserializer);
             }

-- 
To stop receiving notification emails like this one, please contact
guozhang@apache.org.

Mime
View raw message