beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@apache.org
Subject [1/2] incubator-beam git commit: [BEAM-551] Add better toString methods for VPs
Date Fri, 11 Nov 2016 22:14:12 GMT
Repository: incubator-beam
Updated Branches:
  refs/heads/master 1ff129fe6 -> 703816dbd


[BEAM-551] Add better toString methods for VPs


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

Branch: refs/heads/master
Commit: 2316c97a1081b73c8ceae0f603918eff49182ce4
Parents: 1ff129f
Author: Sam McVeety <sgmc@google.com>
Authored: Wed Nov 2 14:05:04 2016 -0700
Committer: Davor Bonaci <davor@google.com>
Committed: Fri Nov 11 14:13:53 2016 -0800

----------------------------------------------------------------------
 .../apache/beam/sdk/options/ValueProvider.java  | 24 ++++++++++++++++++++
 .../beam/sdk/options/ValueProviderTest.java     |  7 ++++++
 2 files changed, 31 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/2316c97a/sdks/java/core/src/main/java/org/apache/beam/sdk/options/ValueProvider.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/options/ValueProvider.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/options/ValueProvider.java
index 188b371..2f52ad4 100644
--- a/sdks/java/core/src/main/java/org/apache/beam/sdk/options/ValueProvider.java
+++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/options/ValueProvider.java
@@ -33,6 +33,7 @@ import com.fasterxml.jackson.databind.SerializerProvider;
 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.databind.deser.ContextualDeserializer;
+import com.google.common.base.MoreObjects;
 import java.io.IOException;
 import java.io.Serializable;
 import java.lang.reflect.InvocationHandler;
@@ -91,6 +92,13 @@ public interface ValueProvider<T> {
     public boolean isAccessible() {
       return true;
     }
+
+    @Override
+    public String toString() {
+      return MoreObjects.toStringHelper(this)
+          .add("value", value)
+          .toString();
+    }
   }
 
   /**
@@ -125,6 +133,13 @@ public interface ValueProvider<T> {
     public boolean isAccessible() {
       return value.isAccessible();
     }
+
+    @Override
+    public String toString() {
+      return MoreObjects.toStringHelper(this)
+          .add("value", value)
+          .toString();
+    }
   }
 
   /**
@@ -212,6 +227,15 @@ public interface ValueProvider<T> {
     public String propertyName() {
       return propertyName;
     }
+
+    @Override
+    public String toString() {
+      return MoreObjects.toStringHelper(this)
+          .add("propertyName", propertyName)
+          .add("default", defaultValue)
+          .add("value", isAccessible() ? get() : null)
+          .toString();
+    }
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/2316c97a/sdks/java/core/src/test/java/org/apache/beam/sdk/options/ValueProviderTest.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/test/java/org/apache/beam/sdk/options/ValueProviderTest.java
b/sdks/java/core/src/test/java/org/apache/beam/sdk/options/ValueProviderTest.java
index 660543c..be0f076 100644
--- a/sdks/java/core/src/test/java/org/apache/beam/sdk/options/ValueProviderTest.java
+++ b/sdks/java/core/src/test/java/org/apache/beam/sdk/options/ValueProviderTest.java
@@ -85,6 +85,7 @@ public class ValueProviderTest {
     ValueProvider<String> provider = StaticValueProvider.of("foo");
     assertEquals("foo", provider.get());
     assertTrue(provider.isAccessible());
+    assertEquals("StaticValueProvider{value=foo}", provider.toString());
   }
 
   @Test
@@ -103,6 +104,9 @@ public class ValueProviderTest {
     TestOptions options = PipelineOptionsFactory.as(TestOptions.class);
     ValueProvider<String> provider = options.getFoo();
     assertEquals("foo", ((RuntimeValueProvider) provider).propertyName());
+    assertEquals(
+        "RuntimeValueProvider{propertyName=foo, default=null, value=null}",
+        provider.toString());
   }
 
   @Test
@@ -225,6 +229,9 @@ public class ValueProviderTest {
       });
     assertTrue(nvp.isAccessible());
     assertEquals("foobar", nvp.get());
+    assertEquals(
+        "NestedValueProvider{value=StaticValueProvider{value=foo}}",
+        nvp.toString());
   }
 
   @Test


Mime
View raw message