You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by na...@apache.org on 2016/08/30 09:35:54 UTC

[30/50] jclouds git commit: Make DockerTemplateOptions values null safe

Make DockerTemplateOptions values null safe


Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/49f7bc37
Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/49f7bc37
Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/49f7bc37

Branch: refs/heads/master
Commit: 49f7bc37afef7ebd1e2cf74b0d893dd4089cd799
Parents: 047595c
Author: Andrew Donald Kennedy <an...@cloudsoftcorp.com>
Authored: Thu Apr 14 21:05:34 2016 +0100
Committer: Ignasi Barrera <na...@apache.org>
Committed: Tue Apr 19 17:01:18 2016 +0200

----------------------------------------------------------------------
 .../compute/options/DockerTemplateOptions.java  | 22 ++++++++++----------
 .../jclouds/docker/internal/NullSafeCopies.java |  8 +++++++
 2 files changed, 19 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds/blob/49f7bc37/apis/docker/src/main/java/org/jclouds/docker/compute/options/DockerTemplateOptions.java
----------------------------------------------------------------------
diff --git a/apis/docker/src/main/java/org/jclouds/docker/compute/options/DockerTemplateOptions.java b/apis/docker/src/main/java/org/jclouds/docker/compute/options/DockerTemplateOptions.java
index bff0d9c..8a42253 100644
--- a/apis/docker/src/main/java/org/jclouds/docker/compute/options/DockerTemplateOptions.java
+++ b/apis/docker/src/main/java/org/jclouds/docker/compute/options/DockerTemplateOptions.java
@@ -83,15 +83,15 @@ public class DockerTemplateOptions extends TemplateOptions implements Cloneable
    private static final String NO_IMAGE = "jclouds-placeholder-for-image";
 
    protected List<String> dns = ImmutableList.of();
-   protected String hostname;
-   protected Integer memory;
-   protected Integer cpuShares;
-   protected List<String> entrypoint = ImmutableList.of();
-   protected List<String> commands = ImmutableList.of();
+   @Nullable protected String hostname;
+   @Nullable protected Integer memory;
+   @Nullable protected Integer cpuShares;
+   @Nullable List<String> entrypoint;
+   @Nullable List<String> commands;
    protected Map<String, String> volumes = ImmutableMap.of();
-   protected List<String> env = ImmutableList.of();
+   @Nullable protected List<String> env;
    protected Map<Integer, Integer> portBindings = ImmutableMap.of();
-   protected String networkMode;
+   @Nullable protected String networkMode;
    protected Map<String, String> extraHosts = ImmutableMap.of();
    protected List<String> volumesFrom = ImmutableList.of();
    protected boolean privileged;
@@ -189,12 +189,12 @@ public class DockerTemplateOptions extends TemplateOptions implements Cloneable
    }
 
    public DockerTemplateOptions dns(Iterable<String> dns) {
-      this.dns = NullSafeCopies.copyWithNullOf(dns);
+      this.dns = NullSafeCopies.copyOf(dns);
       return this;
    }
 
    public DockerTemplateOptions dns(String...dns) {
-      this.dns = NullSafeCopies.copyWithNullOf(dns);
+      this.dns = NullSafeCopies.copyOf(dns);
       return this;
    }
 
@@ -278,7 +278,7 @@ public class DockerTemplateOptions extends TemplateOptions implements Cloneable
     * @param extraHosts the map of host names to IP addresses
     */
    public DockerTemplateOptions extraHosts(Map<String, String> extraHosts) {
-      this.extraHosts = NullSafeCopies.copyWithNullOf(extraHosts);
+      this.extraHosts = NullSafeCopies.copyOf(extraHosts);
       return this;
    }
 
@@ -288,7 +288,7 @@ public class DockerTemplateOptions extends TemplateOptions implements Cloneable
     * @param volumesFrom the list of container names
     */
    public DockerTemplateOptions volumesFrom(Iterable<String> volumesFrom) {
-      this.volumesFrom = NullSafeCopies.copyWithNullOf(volumesFrom);
+      this.volumesFrom = NullSafeCopies.copyOf(volumesFrom);
       return this;
    }
 

http://git-wip-us.apache.org/repos/asf/jclouds/blob/49f7bc37/apis/docker/src/main/java/org/jclouds/docker/internal/NullSafeCopies.java
----------------------------------------------------------------------
diff --git a/apis/docker/src/main/java/org/jclouds/docker/internal/NullSafeCopies.java b/apis/docker/src/main/java/org/jclouds/docker/internal/NullSafeCopies.java
index b6e190c..f3d9eb8 100644
--- a/apis/docker/src/main/java/org/jclouds/docker/internal/NullSafeCopies.java
+++ b/apis/docker/src/main/java/org/jclouds/docker/internal/NullSafeCopies.java
@@ -34,6 +34,14 @@ public class NullSafeCopies {
       return list != null ? ImmutableList.copyOf(list) : ImmutableList.<E> of();
    }
 
+   public static <E> List<E> copyOf(@Nullable Iterable<E> list) {
+      return list != null ? ImmutableList.copyOf(list) : ImmutableList.<E> of();
+   }
+
+   public static <E> List<E> copyOf(@Nullable E[] array) {
+      return array != null ? ImmutableList.copyOf(array) : ImmutableList.<E> of();
+   }
+
    /**
     * Copies given List with keeping null value if provided.
     *