Change List to Set in CreateServerOptions and Server

This commit is contained in:
Christophe Hamerling 2012-01-17 09:51:47 +01:00
parent 61ff64c8ce
commit 9090625b78
3 changed files with 11 additions and 9 deletions

View File

@ -19,11 +19,11 @@
package org.jclouds.openstack.nova.domain; package org.jclouds.openstack.nova.domain;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.Map; 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.Maps;
import com.google.common.collect.Sets;
import com.google.gson.annotations.SerializedName; 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 * needed when creating a server to specify a set of groups
*/ */
@SerializedName(value="security_groups") @SerializedName(value="security_groups")
private List<SecurityGroup> securityGroups = Lists.newArrayList(); private Set<SecurityGroup> securityGroups = Sets.newHashSet();
private Date created; private Date created;
private Date updated; private Date updated;
@ -213,11 +213,11 @@ public class Server extends Resource {
this.keyName = keyName; this.keyName = keyName;
} }
public List<SecurityGroup> getSecurityGroups() { public Set<SecurityGroup> getSecurityGroups() {
return securityGroups; return securityGroups;
} }
public void setSecurityGroups(List<SecurityGroup> securityGroups) { public void setSecurityGroups(Set<SecurityGroup> securityGroups) {
this.securityGroups = securityGroups; this.securityGroups = securityGroups;
} }

View File

@ -25,6 +25,7 @@ import static com.google.common.base.Preconditions.checkState;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
import javax.inject.Inject; 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.ImmutableMap;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
/** /**
@ -80,7 +82,7 @@ public class CreateServerOptions implements MapBinder {
List<File> personality; List<File> personality;
String key_name; String key_name;
@SerializedName(value="security_groups") @SerializedName(value="security_groups")
List<SecurityGroup> securityGroups; Set<SecurityGroup> securityGroups;
private ServerRequest(String name, String imageRef, String flavorRef) { private ServerRequest(String name, String imageRef, String flavorRef) {
this.name = name; this.name = name;
@ -92,7 +94,7 @@ public class CreateServerOptions implements MapBinder {
private Map<String, String> metadata = Maps.newHashMap(); private Map<String, String> metadata = Maps.newHashMap();
private List<File> files = Lists.newArrayList(); private List<File> files = Lists.newArrayList();
private List<String> securityGroups = Lists.newArrayList(); private Set<String> securityGroups = Sets.newHashSet();
private String keyName; private String keyName;
@Override @Override
@ -107,7 +109,7 @@ public class CreateServerOptions implements MapBinder {
if (keyName != null) if (keyName != null)
server.key_name = keyName; server.key_name = keyName;
if (securityGroups.size() > 0) { if (securityGroups.size() > 0) {
server.securityGroups = Lists.newArrayList(); server.securityGroups = Sets.newHashSet();
for (String groupName : securityGroups) { for (String groupName : securityGroups) {
SecurityGroup group = new SecurityGroup(); SecurityGroup group = new SecurityGroup();
group.setName(groupName); group.setName(groupName);

View File

@ -86,7 +86,7 @@ public class CreateServerOptionsTest {
HttpRequest request = buildRequest(options); HttpRequest request = buildRequest(options);
assertEquals( assertEquals(
request.getPayload().getRawContent(), 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) { private void assertFile(HttpRequest request) {