beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From k...@apache.org
Subject [30/50] incubator-beam git commit: [BEAM-401] Use StringBuilder in StandardCoder.toString()
Date Thu, 25 Aug 2016 18:55:44 GMT
[BEAM-401] Use StringBuilder in StandardCoder.toString()


Project: http://git-wip-us.apache.org/repos/asf/incubator-beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-beam/commit/743923b1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-beam/tree/743923b1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-beam/diff/743923b1

Branch: refs/heads/gearpump-runner
Commit: 743923b1788eea0672db750362daf38a71ed7657
Parents: 388816a
Author: Chandni Singh <chandni.singh@capitalone.com>
Authored: Thu Aug 4 12:00:41 2016 -0700
Committer: Kenneth Knowles <klk@google.com>
Committed: Wed Aug 10 09:43:40 2016 -0700

----------------------------------------------------------------------
 .../src/main/resources/beam/findbugs-filter.xml |  6 -----
 .../apache/beam/sdk/coders/StandardCoder.java   | 14 ++++++-----
 .../beam/sdk/coders/StandardCoderTest.java      | 25 ++++++++++++++++++++
 3 files changed, 33 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/743923b1/sdks/java/build-tools/src/main/resources/beam/findbugs-filter.xml
----------------------------------------------------------------------
diff --git a/sdks/java/build-tools/src/main/resources/beam/findbugs-filter.xml b/sdks/java/build-tools/src/main/resources/beam/findbugs-filter.xml
index 28fd0df..7d8f110 100644
--- a/sdks/java/build-tools/src/main/resources/beam/findbugs-filter.xml
+++ b/sdks/java/build-tools/src/main/resources/beam/findbugs-filter.xml
@@ -42,12 +42,6 @@
     <!--[BEAM-398] Inconsistent synchronization-->
   </Match>
   <Match>
-    <Class name="org.apache.beam.sdk.coders.StandardCoder"/>
-    <Method name="toString"/>
-    <Bug pattern="SBSC_USE_STRINGBUFFER_CONCATENATION"/>
-    <!--[BEAM-401] Method invokes inefficient new String(String) constructor-->
-  </Match>
-  <Match>
     <Class name="org.apache.beam.sdk.io.range.OffsetRangeTracker"/>
     <Field name="done"/>
     <Bug pattern="IS2_INCONSISTENT_SYNC"/>

http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/743923b1/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/StandardCoder.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/StandardCoder.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/StandardCoder.java
index 423d482..8b7b788 100644
--- a/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/StandardCoder.java
+++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/StandardCoder.java
@@ -102,23 +102,25 @@ public abstract class StandardCoder<T> implements Coder<T>
{
 
   @Override
   public String toString() {
+    StringBuilder builder = new StringBuilder();
     String s = getClass().getName();
-    s = s.substring(s.lastIndexOf('.') + 1);
+    builder.append(s.substring(s.lastIndexOf('.') + 1));
+
     List<? extends Coder<?>> componentCoders = getComponents();
     if (!componentCoders.isEmpty()) {
-      s += "(";
+      builder.append('(');
       boolean first = true;
       for (Coder<?> componentCoder : componentCoders) {
         if (first) {
           first = false;
         } else {
-          s += ", ";
+          builder.append(',');
         }
-        s += componentCoder.toString();
+        builder.append(componentCoder.toString());
       }
-      s += ")";
+      builder.append(')');
     }
-    return s;
+    return builder.toString();
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/743923b1/sdks/java/core/src/test/java/org/apache/beam/sdk/coders/StandardCoderTest.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/test/java/org/apache/beam/sdk/coders/StandardCoderTest.java
b/sdks/java/core/src/test/java/org/apache/beam/sdk/coders/StandardCoderTest.java
index a3a0f45..1dc2210 100644
--- a/sdks/java/core/src/test/java/org/apache/beam/sdk/coders/StandardCoderTest.java
+++ b/sdks/java/core/src/test/java/org/apache/beam/sdk/coders/StandardCoderTest.java
@@ -19,6 +19,10 @@ package org.apache.beam.sdk.coders;
 
 import org.apache.beam.sdk.testing.CoderProperties;
 
+import com.google.common.collect.ImmutableList;
+
+import org.hamcrest.CoreMatchers;
+import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.JUnit4;
@@ -174,4 +178,25 @@ public class StandardCoderTest {
       }
     }
   }
+
+  /**
+   * Test for verifying {@link StandardCoder#toString()}.
+   */
+  @Test
+  public void testToString() {
+    Assert.assertThat(new ObjectIdentityBooleanCoder().toString(),
+        CoreMatchers.equalTo("StandardCoderTest$ObjectIdentityBooleanCoder"));
+
+    ObjectIdentityBooleanCoder coderWithArgs = new ObjectIdentityBooleanCoder() {
+      @Override
+      public List<? extends Coder<?>> getCoderArguments() {
+        return ImmutableList.<Coder<?>>builder()
+            .add(BigDecimalCoder.of(), BigIntegerCoder.of())
+            .build();
+      }
+    };
+
+    Assert.assertThat(coderWithArgs.toString(),
+        CoreMatchers.equalTo("StandardCoderTest$1(BigDecimalCoder,BigIntegerCoder)"));
+  }
 }


Mime
View raw message