mirror of https://github.com/apache/jclouds.git
Domain objects implement List/Set where appropriate
This commit is contained in:
parent
1116fcb823
commit
d08a0a99c4
|
@ -29,7 +29,9 @@ import javax.xml.bind.annotation.XmlElement;
|
||||||
import javax.xml.bind.annotation.XmlType;
|
import javax.xml.bind.annotation.XmlType;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
|
import com.google.common.collect.ForwardingList;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,7 +60,8 @@ import com.google.common.collect.Lists;
|
||||||
@XmlType(name = "FilesList", propOrder = {
|
@XmlType(name = "FilesList", propOrder = {
|
||||||
"files"
|
"files"
|
||||||
})
|
})
|
||||||
public class FilesList {
|
public class FilesList extends ForwardingList<File> {
|
||||||
|
|
||||||
public static Builder builder() {
|
public static Builder builder() {
|
||||||
return new Builder();
|
return new Builder();
|
||||||
}
|
}
|
||||||
|
@ -137,4 +140,8 @@ public class FilesList {
|
||||||
.add("file", files).toString();
|
.add("file", files).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<File> delegate() {
|
||||||
|
return getFiles();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,11 @@ import static com.google.common.base.Objects.equal;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ListIterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
@ -32,7 +36,9 @@ import javax.xml.bind.annotation.XmlType;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.ovf.ProductSection;
|
import org.jclouds.vcloud.director.v1_5.domain.ovf.ProductSection;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,10 +65,8 @@ import com.google.common.collect.Sets;
|
||||||
@XmlType(name = "ProductSectionList", propOrder = {
|
@XmlType(name = "ProductSectionList", propOrder = {
|
||||||
"productSections"
|
"productSections"
|
||||||
})
|
})
|
||||||
public class ProductSectionList
|
public class ProductSectionList extends ResourceType<ProductSectionList> implements List<ProductSection> {
|
||||||
extends ResourceType<ProductSectionList>
|
|
||||||
|
|
||||||
{
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static Builder builder() {
|
public static Builder builder() {
|
||||||
return new Builder();
|
return new Builder();
|
||||||
|
@ -135,7 +139,7 @@ public class ProductSectionList
|
||||||
|
|
||||||
public Builder fromProductSectionList(ProductSectionList in) {
|
public Builder fromProductSectionList(ProductSectionList in) {
|
||||||
return fromResourceType(in)
|
return fromResourceType(in)
|
||||||
.productSections(in.getProductSections());
|
.productSections(ImmutableSet.copyOf(in));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,18 +148,18 @@ public class ProductSectionList
|
||||||
}
|
}
|
||||||
|
|
||||||
private ProductSectionList(Set<ProductSection> productSections) {
|
private ProductSectionList(Set<ProductSection> productSections) {
|
||||||
this.productSections = ImmutableSet.copyOf(productSections);
|
this.productSections = ImmutableList.copyOf(productSections);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@XmlElement(name = "ProductSection", namespace = "http://schemas.dmtf.org/ovf/envelope/1")
|
@XmlElement(name = "ProductSection", namespace = "http://schemas.dmtf.org/ovf/envelope/1")
|
||||||
protected Set<ProductSection> productSections = Sets.newLinkedHashSet();
|
protected List<ProductSection> productSections = Lists.newArrayList();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the value of the productSection property.
|
* Gets the value of the productSection property.
|
||||||
*/
|
*/
|
||||||
public Set<ProductSection> getProductSections() {
|
public List<ProductSection> getProductSections() {
|
||||||
return Collections.unmodifiableSet(this.productSections);
|
return Collections.unmodifiableList(this.productSections);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -179,4 +183,127 @@ public class ProductSectionList
|
||||||
.add("productSections", productSections).toString();
|
.add("productSections", productSections).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Methods below are for implementing List; annoying lack of multiple inheritance for using ForwardingList!
|
||||||
|
*/
|
||||||
|
|
||||||
|
private List<ProductSection> delegate() {
|
||||||
|
return getProductSections();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean add(ProductSection arg0) {
|
||||||
|
return delegate().add(arg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void add(int arg0, ProductSection arg1) {
|
||||||
|
delegate().add(arg0, arg1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addAll(Collection<? extends ProductSection> arg0) {
|
||||||
|
return delegate().addAll(arg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addAll(int arg0, Collection<? extends ProductSection> arg1) {
|
||||||
|
return delegate().addAll(arg0, arg1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 ProductSection get(int arg0) {
|
||||||
|
return delegate().get(arg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int indexOf(Object arg0) {
|
||||||
|
return delegate().indexOf(arg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return delegate().isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator<ProductSection> iterator() {
|
||||||
|
return delegate().iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int lastIndexOf(Object arg0) {
|
||||||
|
return delegate().lastIndexOf(arg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ListIterator<ProductSection> listIterator() {
|
||||||
|
return delegate().listIterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ListIterator<ProductSection> listIterator(int arg0) {
|
||||||
|
return delegate().listIterator(arg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean remove(Object arg0) {
|
||||||
|
return delegate().remove(arg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ProductSection remove(int 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 ProductSection set(int arg0, ProductSection arg1) {
|
||||||
|
return delegate().set(arg0, arg1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
return delegate().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ProductSection> subList(int arg0, int arg1) {
|
||||||
|
return delegate().subList(arg0, arg1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object[] toArray() {
|
||||||
|
return delegate().toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T[] toArray(T[] arg0) {
|
||||||
|
return delegate().toArray(arg0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,10 +173,6 @@ public class TasksList extends ResourceType<TasksList> implements Set<Task> {
|
||||||
return Objects.hashCode(super.hashCode(), delegate(), name);
|
return Objects.hashCode(super.hashCode(), delegate(), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<Task> delegate() {
|
|
||||||
return tasks == null ? ImmutableSet.<Task>of() : Collections.unmodifiableSet(tasks);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ToStringHelper string() {
|
public ToStringHelper string() {
|
||||||
return super.string().add("name", name).add("tasks", delegate());
|
return super.string().add("name", name).add("tasks", delegate());
|
||||||
|
@ -187,6 +183,15 @@ public class TasksList extends ResourceType<TasksList> implements Set<Task> {
|
||||||
return new Builder().fromTasksList(this);
|
return new Builder().fromTasksList(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Methods below are for implementing Set; annoying lack of multiple inheritance for using ForwardingSet!
|
||||||
|
*/
|
||||||
|
|
||||||
|
private Set<Task> delegate() {
|
||||||
|
return tasks == null ? ImmutableSet.<Task>of() : Collections.unmodifiableSet(tasks);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<Task> iterator() {
|
public Iterator<Task> iterator() {
|
||||||
return delegate().iterator();
|
return delegate().iterator();
|
||||||
|
|
|
@ -576,7 +576,7 @@ public class Checks {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (template.getFiles() != null) {
|
if (template.getFiles() != null) {
|
||||||
for (File file : template.getFiles().getFiles()) { // TODO FileList should implement List
|
for (File file : template.getFiles()) {
|
||||||
checkFile(file);
|
checkFile(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -953,7 +953,7 @@ public class Checks {
|
||||||
public static void checkProductSectionList(ProductSectionList val) {
|
public static void checkProductSectionList(ProductSectionList val) {
|
||||||
assertNotNull(val, String.format(NOT_NULL_OBJECT_FMT, "ProductSectionList", ""));
|
assertNotNull(val, String.format(NOT_NULL_OBJECT_FMT, "ProductSectionList", ""));
|
||||||
|
|
||||||
for (ProductSection productSection : val.getProductSections()) { // TODO Should implement List
|
for (ProductSection productSection : val) {
|
||||||
checkOvfProductSection(productSection);
|
checkOvfProductSection(productSection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue