From 9bc2640601b8678622247b4a4df33827ff6b2734 Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Tue, 27 Mar 2012 12:38:12 +0100 Subject: [PATCH] Issue 830: Make RasdItemsList implement Set --- .../director/v1_5/domain/RasdItemsList.java | 92 +++++++++++++++++-- 1 file changed, 85 insertions(+), 7 deletions(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/RasdItemsList.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/RasdItemsList.java index a3d432879b..8f8a444699 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/RasdItemsList.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/RasdItemsList.java @@ -21,7 +21,9 @@ package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.equal; import static com.google.common.base.Preconditions.checkNotNull; -import java.util.List; +import java.util.Collection; +import java.util.Iterator; +import java.util.Set; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; @@ -31,7 +33,7 @@ import org.jclouds.vcloud.director.v1_5.domain.cim.ResourceAllocationSettingData import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; -import com.google.common.collect.Lists; +import com.google.common.collect.Sets; /** * Represents a list of RASD items. @@ -44,12 +46,13 @@ import com.google.common.collect.Lists; */ @XmlRootElement(name = "RasdItemsList") @XmlType(name = "RasdItemsList") -public class RasdItemsList extends ResourceType { +public class RasdItemsList extends ResourceType implements Set { public static Builder builder() { return new ConcreteBuilder(); } + @Override public Builder toBuilder() { return builder().fromRasdItemsList(this); } @@ -59,12 +62,12 @@ public class RasdItemsList extends ResourceType { public static abstract class Builder> extends ResourceType.Builder { - private List items = Lists.newArrayList(); + private Set items = Sets.newLinkedHashSet(); /** * @see RasdItemsList#getItems() */ - public B items(List items) { + public B items(Set items) { this.items = checkNotNull(items, "items"); return self(); } @@ -98,12 +101,12 @@ public class RasdItemsList extends ResourceType { } @XmlElement(name = "Item") - protected List items = Lists.newArrayList(); + protected Set items = Sets.newLinkedHashSet(); /** * A RASD item content. */ - public List getItems() { + public Set getItems() { return items; } @@ -127,4 +130,79 @@ public class RasdItemsList extends ResourceType { return super.string().add("items", items); } + /** + * The delegate always returns a {@link Set} even if {@link #items} is {@literal null}. + * + * The delegated {@link Set} is used by the methods implementing its interface. + *

+ * NOTE Annoying lack of multiple inheritance for using ForwardingList! + */ + private Set delegate() { + return getItems(); + } + + @Override + public boolean add(ResourceAllocationSettingData arg0) { + return delegate().add(arg0); + } + + @Override + public boolean addAll(Collection arg0) { + return delegate().addAll(arg0); + } + + @Override + public void clear() { + delegate().clear(); + } + + @Override + public boolean contains(Object arg0) { + return delegate().contains(arg0); + } + + @Override + public boolean containsAll(Collection arg0) { + return delegate().containsAll(arg0); + } + + @Override + public boolean isEmpty() { + return delegate().isEmpty(); + } + + @Override + public Iterator iterator() { + return delegate().iterator(); + } + + @Override + public boolean remove(Object arg0) { + return delegate().remove(arg0); + } + + @Override + public boolean removeAll(Collection arg0) { + return delegate().removeAll(arg0); + } + + @Override + public boolean retainAll(Collection arg0) { + return delegate().retainAll(arg0); + } + + @Override + public int size() { + return delegate().size(); + } + + @Override + public Object[] toArray() { + return delegate().toArray(); + } + + @Override + public T[] toArray(T[] arg0) { + return delegate().toArray(arg0); + } }