rebase metadata/entry on new base classes

This commit is contained in:
danikov 2012-02-07 15:15:45 +00:00
parent 029b021871
commit 693af6dc25
2 changed files with 107 additions and 66 deletions

View File

@ -4,18 +4,21 @@ import static com.google.common.base.Objects.equal;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NS;
import java.net.URI;
import java.util.Set;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
@XmlRootElement(namespace = NS, name = "MetaDataList")
public class Metadata {
@XmlRootElement(namespace = NS, name = "Metadata")
public class Metadata extends ResourceType<Metadata>{
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
@ -24,28 +27,67 @@ public class Metadata {
return new Builder().fromMetadataList(this);
}
public static class Builder {
public static class Builder extends ResourceType.Builder<Metadata> {
private Set<MetadataEntry> metadata = Sets.newLinkedHashSet();
private Set<MetadataEntry> metadataEntries = Sets.newLinkedHashSet();
/**
* @see OrgList#getOrgs
* @see Metadata#getMetadata()
*/
public Builder metadata(Set<MetadataEntry> orgs) {
this.metadata = Sets.newLinkedHashSet(checkNotNull(orgs, "metadata"));
public Builder metadata(Set<MetadataEntry> metadataEntries) {
this.metadataEntries = Sets.newLinkedHashSet(checkNotNull(metadataEntries, "metadataEntries"));
return this;
}
/**
* @see OrgList#getOrgs
* @see Metadata#getMetadata()
*/
public Builder addMetadata(MetadataEntry org) {
metadata.add(checkNotNull(org, "metadatum"));
public Builder entry(MetadataEntry metadataEntry) {
metadataEntries.add(checkNotNull(metadataEntry, "metadataEntry"));
return this;
}
public Metadata build() {
return new Metadata(metadata);
Metadata metadata = new Metadata(href, metadataEntries);
metadata.setType(type);
metadata.setLinks(links);
return metadata;
}
/**
* @see ResourceType#getHref()
*/
@Override
public Builder href(URI href) {
super.href(href);
return this;
}
/**
* @see ResourceType#getType()
*/
@Override
public Builder type(String type) {
super.type(type);
return this;
}
/**
* @see ResourceType#getLinks()
*/
@Override
public Builder links(Set<Link> links) {
super.links(Sets.newLinkedHashSet(checkNotNull(links, "links")));
return this;
}
/**
* @see ResourceType#getLinks()
*/
@Override
public Builder link(Link link) {
super.link(link);
return this;
}
public Builder fromMetadataList(Metadata in) {
@ -57,11 +99,12 @@ public class Metadata {
// For JAXB and builder use
}
private Metadata(Set<MetadataEntry> orgs) {
this.metadata = ImmutableSet.copyOf(orgs);
private Metadata(URI href, Set<MetadataEntry> metadataEntries) {
super(href);
this.metadata = ImmutableSet.copyOf(metadataEntries);
}
@XmlElement(namespace = NS, name = "MetaData")
@XmlElement(namespace = NS, name = "MetadataEntry")
private Set<MetadataEntry> metadata = Sets.newLinkedHashSet();
public Set<MetadataEntry> getMetadata() {
@ -70,22 +113,20 @@ public class Metadata {
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
if (!super.equals(o))
return false;
Metadata that = Metadata.class.cast(o);
return equal(metadata, that.metadata);
return super.equals(that) && equal(metadata, that.metadata);
}
@Override
public int hashCode() {
return Objects.hashCode(metadata);
return super.hashCode() + Objects.hashCode(metadata);
}
@Override
public String toString() {
return Objects.toStringHelper("").add("metadata", metadata).toString();
public ToStringHelper string() {
return super.string().add("metadata", metadata);
}
}

View File

@ -13,11 +13,10 @@ import javax.xml.bind.annotation.XmlRootElement;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
@XmlRootElement(namespace = NS, name = "org/metadata")
public class MetadataEntry extends BaseResource<MetadataEntry> {
public class MetadataEntry extends ResourceType<MetadataEntry> {
@SuppressWarnings("unchecked")
public static Builder builder() {
@ -25,14 +24,12 @@ public class MetadataEntry extends BaseResource<MetadataEntry> {
}
public Builder toBuilder() {
return new Builder().fromMetadatum(this);
return new Builder().fromMetadata(this);
}
public static class Builder extends BaseResource.Builder<MetadataEntry> {
public static class Builder extends ResourceType.Builder<MetadataEntry> {
private String key;
private String value;
private Set<Link> links = Sets.newLinkedHashSet();
/**
* @see MetadataEntry#getKey
@ -50,38 +47,51 @@ public class MetadataEntry extends BaseResource<MetadataEntry> {
return this;
}
/**
* @see MetadataEntry#?
*/
public Builder links(Set<Link> links) {
this.links = Sets.newLinkedHashSet(checkNotNull(links, "links"));
return this;
}
/**
* @see MetadataEntry#?
*/
public Builder addLink(Link org) {
links.add(checkNotNull(org, "org"));
return this;
}
public MetadataEntry build() {
return new MetadataEntry(href, type, key, value, links);
MetadataEntry metadataEntry = new MetadataEntry(href, key, value);
metadataEntry.setType(type);
metadataEntry.setLinks(links);
return metadataEntry;
}
public Builder fromMetadatum(MetadataEntry in) {
return key(in.getKey()).value(in.getValue());
}
/**
* @see ResourceType#getHref()
*/
@Override
public Builder href(URI href) {
return Builder.class.cast(super.href(href));
super.href(href);
return this;
}
/**
* @see ResourceType#getType()
*/
@Override
public Builder type(String type) {
return Builder.class.cast(super.type(type));
super.type(type);
return this;
}
/**
* @see ResourceType#getLinks()
*/
@Override
public Builder links(Set<Link> links) {
super.links(Sets.newLinkedHashSet(checkNotNull(links, "links")));
return this;
}
/**
* @see ResourceType#getLinks()
*/
@Override
public Builder link(Link link) {
super.link(link);
return this;
}
public Builder fromMetadata(MetadataEntry in) {
return key(in.getKey()).value(in.getValue());
}
}
@ -90,19 +100,16 @@ public class MetadataEntry extends BaseResource<MetadataEntry> {
// For JAXB and builder use
}
private MetadataEntry(URI href, String type, String key, String value, Set<Link> links) {
super(href, type);
this.key = key;
this.value = value;
this.links = ImmutableSet.copyOf(links);
private MetadataEntry(URI href, String key, String value) {
super(href);
this.key = checkNotNull(key, "key");
this.value = checkNotNull(value, "value");
}
@XmlAttribute
private String key;
@XmlElement(namespace = NS, name = "Value")
private String value;
@XmlElement(namespace = NS, name = "Link")
private Set<Link> links = Sets.newLinkedHashSet();
/**
*
@ -120,20 +127,13 @@ public class MetadataEntry extends BaseResource<MetadataEntry> {
return value;
}
/**
* TODO
*/
public Set<Link> getLinks() {
return ImmutableSet.copyOf(links);
}
@Override
public boolean equals(Object o) {
if (!super.equals(o))
return false;
MetadataEntry that = MetadataEntry.class.cast(o);
return equal(key, that.key);
return super.equals(that) && equal(key, that.key);
}
@Override