mirror of https://github.com/apache/jclouds.git
rebase metadata/entry on new base classes
This commit is contained in:
parent
029b021871
commit
693af6dc25
|
@ -4,18 +4,21 @@ 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 static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NS;
|
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NS;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
|
import com.google.common.base.Objects.ToStringHelper;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
@XmlRootElement(namespace = NS, name = "MetaDataList")
|
@XmlRootElement(namespace = NS, name = "Metadata")
|
||||||
public class Metadata {
|
public class Metadata extends ResourceType<Metadata>{
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public static Builder builder() {
|
public static Builder builder() {
|
||||||
return new Builder();
|
return new Builder();
|
||||||
}
|
}
|
||||||
|
@ -24,28 +27,67 @@ public class Metadata {
|
||||||
return new Builder().fromMetadataList(this);
|
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) {
|
public Builder metadata(Set<MetadataEntry> metadataEntries) {
|
||||||
this.metadata = Sets.newLinkedHashSet(checkNotNull(orgs, "metadata"));
|
this.metadataEntries = Sets.newLinkedHashSet(checkNotNull(metadataEntries, "metadataEntries"));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see OrgList#getOrgs
|
* @see Metadata#getMetadata()
|
||||||
*/
|
*/
|
||||||
public Builder addMetadata(MetadataEntry org) {
|
public Builder entry(MetadataEntry metadataEntry) {
|
||||||
metadata.add(checkNotNull(org, "metadatum"));
|
metadataEntries.add(checkNotNull(metadataEntry, "metadataEntry"));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Metadata build() {
|
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) {
|
public Builder fromMetadataList(Metadata in) {
|
||||||
|
@ -57,11 +99,12 @@ public class Metadata {
|
||||||
// For JAXB and builder use
|
// For JAXB and builder use
|
||||||
}
|
}
|
||||||
|
|
||||||
private Metadata(Set<MetadataEntry> orgs) {
|
private Metadata(URI href, Set<MetadataEntry> metadataEntries) {
|
||||||
this.metadata = ImmutableSet.copyOf(orgs);
|
super(href);
|
||||||
|
this.metadata = ImmutableSet.copyOf(metadataEntries);
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElement(namespace = NS, name = "MetaData")
|
@XmlElement(namespace = NS, name = "MetadataEntry")
|
||||||
private Set<MetadataEntry> metadata = Sets.newLinkedHashSet();
|
private Set<MetadataEntry> metadata = Sets.newLinkedHashSet();
|
||||||
|
|
||||||
public Set<MetadataEntry> getMetadata() {
|
public Set<MetadataEntry> getMetadata() {
|
||||||
|
@ -70,22 +113,20 @@ public class Metadata {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o)
|
if (!super.equals(o))
|
||||||
return true;
|
|
||||||
if (o == null || getClass() != o.getClass())
|
|
||||||
return false;
|
return false;
|
||||||
Metadata that = Metadata.class.cast(o);
|
Metadata that = Metadata.class.cast(o);
|
||||||
return equal(metadata, that.metadata);
|
return super.equals(that) && equal(metadata, that.metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(metadata);
|
return super.hashCode() + Objects.hashCode(metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public ToStringHelper string() {
|
||||||
return Objects.toStringHelper("").add("metadata", metadata).toString();
|
return super.string().add("metadata", metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,11 +13,10 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
import com.google.common.base.Objects.ToStringHelper;
|
import com.google.common.base.Objects.ToStringHelper;
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
@XmlRootElement(namespace = NS, name = "org/metadata")
|
@XmlRootElement(namespace = NS, name = "org/metadata")
|
||||||
public class MetadataEntry extends BaseResource<MetadataEntry> {
|
public class MetadataEntry extends ResourceType<MetadataEntry> {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static Builder builder() {
|
public static Builder builder() {
|
||||||
|
@ -25,14 +24,12 @@ public class MetadataEntry extends BaseResource<MetadataEntry> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder toBuilder() {
|
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 key;
|
||||||
private String value;
|
private String value;
|
||||||
private Set<Link> links = Sets.newLinkedHashSet();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see MetadataEntry#getKey
|
* @see MetadataEntry#getKey
|
||||||
|
@ -50,38 +47,51 @@ public class MetadataEntry extends BaseResource<MetadataEntry> {
|
||||||
return this;
|
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() {
|
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
|
@Override
|
||||||
public Builder href(URI href) {
|
public Builder href(URI href) {
|
||||||
return Builder.class.cast(super.href(href));
|
super.href(href);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see ResourceType#getType()
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Builder type(String type) {
|
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
|
// For JAXB and builder use
|
||||||
}
|
}
|
||||||
|
|
||||||
private MetadataEntry(URI href, String type, String key, String value, Set<Link> links) {
|
private MetadataEntry(URI href, String key, String value) {
|
||||||
super(href, type);
|
super(href);
|
||||||
this.key = key;
|
this.key = checkNotNull(key, "key");
|
||||||
this.value = value;
|
this.value = checkNotNull(value, "value");
|
||||||
this.links = ImmutableSet.copyOf(links);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlAttribute
|
@XmlAttribute
|
||||||
private String key;
|
private String key;
|
||||||
@XmlElement(namespace = NS, name = "Value")
|
@XmlElement(namespace = NS, name = "Value")
|
||||||
private String 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;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO
|
|
||||||
*/
|
|
||||||
public Set<Link> getLinks() {
|
|
||||||
return ImmutableSet.copyOf(links);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (!super.equals(o))
|
if (!super.equals(o))
|
||||||
return false;
|
return false;
|
||||||
MetadataEntry that = MetadataEntry.class.cast(o);
|
MetadataEntry that = MetadataEntry.class.cast(o);
|
||||||
return equal(key, that.key);
|
return super.equals(that) && equal(key, that.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue