From 9090625b78e1843e47da20f7b31c17e2e6f24c89 Mon Sep 17 00:00:00 2001 From: Christophe Hamerling Date: Tue, 17 Jan 2012 09:51:47 +0100 Subject: [PATCH] Change List to Set in CreateServerOptions and Server --- .../java/org/jclouds/openstack/nova/domain/Server.java | 10 +++++----- .../openstack/nova/options/CreateServerOptions.java | 8 +++++--- .../nova/options/CreateServerOptionsTest.java | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Server.java b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Server.java index 3a68e789f8..9875fa2f0d 100644 --- a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Server.java +++ b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Server.java @@ -19,11 +19,11 @@ package org.jclouds.openstack.nova.domain; import java.util.Date; -import java.util.List; import java.util.Map; +import java.util.Set; -import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import com.google.common.collect.Sets; import com.google.gson.annotations.SerializedName; /** @@ -56,7 +56,7 @@ public class Server extends Resource { * needed when creating a server to specify a set of groups */ @SerializedName(value="security_groups") - private List securityGroups = Lists.newArrayList(); + private Set securityGroups = Sets.newHashSet(); private Date created; private Date updated; @@ -213,11 +213,11 @@ public class Server extends Resource { this.keyName = keyName; } - public List getSecurityGroups() { + public Set getSecurityGroups() { return securityGroups; } - public void setSecurityGroups(List securityGroups) { + public void setSecurityGroups(Set securityGroups) { this.securityGroups = securityGroups; } diff --git a/apis/nova/src/main/java/org/jclouds/openstack/nova/options/CreateServerOptions.java b/apis/nova/src/main/java/org/jclouds/openstack/nova/options/CreateServerOptions.java index 188a4ccf83..a750af38ac 100644 --- a/apis/nova/src/main/java/org/jclouds/openstack/nova/options/CreateServerOptions.java +++ b/apis/nova/src/main/java/org/jclouds/openstack/nova/options/CreateServerOptions.java @@ -25,6 +25,7 @@ import static com.google.common.base.Preconditions.checkState; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; import javax.inject.Inject; @@ -37,6 +38,7 @@ import org.jclouds.rest.binders.BindToJsonPayload; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import com.google.common.collect.Sets; import com.google.gson.annotations.SerializedName; /** @@ -80,7 +82,7 @@ public class CreateServerOptions implements MapBinder { List personality; String key_name; @SerializedName(value="security_groups") - List securityGroups; + Set securityGroups; private ServerRequest(String name, String imageRef, String flavorRef) { this.name = name; @@ -92,7 +94,7 @@ public class CreateServerOptions implements MapBinder { private Map metadata = Maps.newHashMap(); private List files = Lists.newArrayList(); - private List securityGroups = Lists.newArrayList(); + private Set securityGroups = Sets.newHashSet(); private String keyName; @Override @@ -107,7 +109,7 @@ public class CreateServerOptions implements MapBinder { if (keyName != null) server.key_name = keyName; if (securityGroups.size() > 0) { - server.securityGroups = Lists.newArrayList(); + server.securityGroups = Sets.newHashSet(); for (String groupName : securityGroups) { SecurityGroup group = new SecurityGroup(); group.setName(groupName); diff --git a/apis/nova/src/test/java/org/jclouds/openstack/nova/options/CreateServerOptionsTest.java b/apis/nova/src/test/java/org/jclouds/openstack/nova/options/CreateServerOptionsTest.java index 1efe919f4f..760c3cad84 100644 --- a/apis/nova/src/test/java/org/jclouds/openstack/nova/options/CreateServerOptionsTest.java +++ b/apis/nova/src/test/java/org/jclouds/openstack/nova/options/CreateServerOptionsTest.java @@ -86,7 +86,7 @@ public class CreateServerOptionsTest { HttpRequest request = buildRequest(options); assertEquals( request.getPayload().getRawContent(), - "{\"server\":{\"name\":\"foo\",\"imageRef\":\"1\",\"flavorRef\":\"2\",\"security_groups\":[{\"id\":0,\"name\":\"mygroup\"},{\"id\":0,\"name\":\"myothergroup\"}]}}"); + "{\"server\":{\"name\":\"foo\",\"imageRef\":\"1\",\"flavorRef\":\"2\",\"security_groups\":[{\"id\":0,\"name\":\"myothergroup\"},{\"id\":0,\"name\":\"mygroup\"}]}}"); } private void assertFile(HttpRequest request) {