mirror of https://github.com/apache/jclouds.git
openstack: adjusting beans in openstack-quantum, openstack-glance and openstack-swift to use ConstructorProperties and Named annotations
This commit is contained in:
parent
294e405593
commit
908e164698
|
@ -108,21 +108,10 @@ public class Resource implements Comparable<Resource> {
|
|||
@ConstructorProperties({
|
||||
"id", "name", "links"
|
||||
})
|
||||
protected Resource(String id, @Nullable String name, Set<Link> links) {
|
||||
protected Resource(String id, @Nullable String name, @Nullable Set<Link> links) {
|
||||
this.id = checkNotNull(id, "id");
|
||||
this.name = name;
|
||||
this.links = ImmutableSet.copyOf(checkNotNull(links, "links"));
|
||||
}
|
||||
|
||||
// leaving till beans in other openstack projects are updated
|
||||
@Deprecated
|
||||
protected Resource(Builder<?> builder) {
|
||||
this(builder.id, builder.name, builder.links);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
protected Resource() {
|
||||
id = null; name = null; links = ImmutableSet.of();
|
||||
this.links = links == null ? ImmutableSet.<Link>of() : ImmutableSet.copyOf(checkNotNull(links, "links"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
|
@ -18,20 +18,30 @@
|
|||
*/
|
||||
package org.jclouds.openstack.glance.v1_0.domain;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.openstack.v2_0.domain.Link;
|
||||
import org.jclouds.openstack.v2_0.domain.Resource;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Objects.ToStringHelper;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
* An image the Glance server knows about
|
||||
*
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @see <a href= "http://glance.openstack.org/glanceapi.html" />
|
||||
* @see <a href= "https://github.com/openstack/glance/blob/master/glance/api/v1/images.py" />
|
||||
*/
|
||||
public class Image extends Resource {
|
||||
|
||||
/**
|
||||
*/
|
||||
public static enum Status {
|
||||
|
||||
UNRECOGNIZED, ACTIVE, SAVING, QUEUED, KILLED, PENDING_DELETE, DELETED;
|
||||
|
@ -49,7 +59,7 @@ public class Image extends Resource {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static Builder<?> builder() {
|
||||
return new ConcreteBuilder();
|
||||
}
|
||||
|
@ -58,16 +68,16 @@ public class Image extends Resource {
|
|||
return new ConcreteBuilder().fromImage(this);
|
||||
}
|
||||
|
||||
public static abstract class Builder<T extends Builder<T>> extends Resource.Builder<T> {
|
||||
private Optional<ContainerFormat> containerFormat = Optional.absent();
|
||||
private Optional<DiskFormat> diskFormat = Optional.absent();
|
||||
private Optional<Long> size = Optional.absent();
|
||||
private Optional<String> checksum = Optional.absent();
|
||||
public static abstract class Builder<T extends Builder<T>> extends Resource.Builder<T> {
|
||||
protected ContainerFormat containerFormat;
|
||||
protected DiskFormat diskFormat;
|
||||
protected Long size;
|
||||
protected String checksum;
|
||||
|
||||
/**
|
||||
* @see Image#getContainerFormat()
|
||||
*/
|
||||
public T containerFormat(Optional<ContainerFormat> containerFormat) {
|
||||
public T containerFormat(ContainerFormat containerFormat) {
|
||||
this.containerFormat = containerFormat;
|
||||
return self();
|
||||
}
|
||||
|
@ -75,7 +85,7 @@ public class Image extends Resource {
|
|||
/**
|
||||
* @see Image#getDiskFormat()
|
||||
*/
|
||||
public T diskFormat(Optional<DiskFormat> diskFormat) {
|
||||
public T diskFormat(DiskFormat diskFormat) {
|
||||
this.diskFormat = diskFormat;
|
||||
return self();
|
||||
}
|
||||
|
@ -83,56 +93,30 @@ public class Image extends Resource {
|
|||
/**
|
||||
* @see Image#getSize()
|
||||
*/
|
||||
public T size(Optional<Long> size) {
|
||||
public T size(Long size) {
|
||||
this.size = size;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Image#getSize()
|
||||
* @see Image#getChecksum()
|
||||
*/
|
||||
public T checksum(Optional<String> checksum) {
|
||||
public T checksum(String checksum) {
|
||||
this.checksum = checksum;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Image#getContainerFormat()
|
||||
*/
|
||||
public T containerFormat(ContainerFormat containerFormat) {
|
||||
return containerFormat(Optional.of(containerFormat));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Image#getDiskFormat()
|
||||
*/
|
||||
public T diskFormat(DiskFormat diskFormat) {
|
||||
return diskFormat(Optional.of(diskFormat));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Image#getSize()
|
||||
*/
|
||||
public T size(long size) {
|
||||
return size(Optional.of(size));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Image#getSize()
|
||||
*/
|
||||
public T checksum(String checksum) {
|
||||
return checksum(Optional.of(checksum));
|
||||
}
|
||||
|
||||
public Image build() {
|
||||
return new Image(this);
|
||||
return new Image(id, name, links, containerFormat, diskFormat, size, checksum);
|
||||
}
|
||||
|
||||
public T fromImage(Image in) {
|
||||
return super.fromResource(in).containerFormat(in.getContainerFormat()).diskFormat(in.getDiskFormat()).size(
|
||||
in.getSize()).checksum(in.getChecksum());
|
||||
return super.fromResource(in)
|
||||
.containerFormat(in.getContainerFormat().orNull())
|
||||
.diskFormat(in.getDiskFormat().orNull())
|
||||
.size(in.getSize().orNull())
|
||||
.checksum(in.getChecksum().orNull());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||
|
@ -142,29 +126,23 @@ public class Image extends Resource {
|
|||
}
|
||||
}
|
||||
|
||||
protected Image() {
|
||||
// we want serializers like Gson to work w/o using sun.misc.Unsafe,
|
||||
// prohibited in GAE. This also implies fields are not final.
|
||||
// see http://code.google.com/p/jclouds/issues/detail?id=925
|
||||
}
|
||||
@Named("container_format")
|
||||
private final Optional<ContainerFormat> containerFormat;
|
||||
@Named("disk_format")
|
||||
private final Optional<DiskFormat> diskFormat;
|
||||
private final Optional<Long> size;
|
||||
private final Optional<String> checksum;
|
||||
|
||||
// | container_format | varchar(20) | YES | | NULL | |
|
||||
@SerializedName("container_format")
|
||||
private Optional<ContainerFormat> containerFormat = Optional.absent();
|
||||
// | disk_format | varchar(20) | YES | | NULL | |
|
||||
@SerializedName("disk_format")
|
||||
private Optional<DiskFormat> diskFormat = Optional.absent();
|
||||
// | size | bigint(20) | YES | | NULL | |
|
||||
private Optional<Long> size = Optional.absent();
|
||||
// | checksum | varchar(32) | YES | | NULL | |
|
||||
private Optional<String> checksum = Optional.absent();
|
||||
|
||||
protected Image(Builder<?> builder) {
|
||||
super(builder);
|
||||
this.containerFormat = builder.containerFormat;
|
||||
this.diskFormat = builder.diskFormat;
|
||||
this.size = builder.size;
|
||||
this.checksum = builder.checksum;
|
||||
@ConstructorProperties({
|
||||
"id", "name", "links", "container_format", "disk_format", "size", "checksum"
|
||||
})
|
||||
protected Image(String id, @Nullable String name, Set<Link> links, @Nullable ContainerFormat containerFormat,
|
||||
@Nullable DiskFormat diskFormat, @Nullable Long size, @Nullable String checksum) {
|
||||
super(id, name, links);
|
||||
this.containerFormat = Optional.fromNullable(containerFormat);
|
||||
this.diskFormat = Optional.fromNullable(diskFormat);
|
||||
this.size = Optional.fromNullable(size);
|
||||
this.checksum = Optional.fromNullable(checksum);
|
||||
}
|
||||
|
||||
public Optional<ContainerFormat> getContainerFormat() {
|
||||
|
@ -180,12 +158,28 @@ public class Image extends Resource {
|
|||
}
|
||||
|
||||
public Optional<String> getChecksum() {
|
||||
return checksum;
|
||||
return this.checksum;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Objects.ToStringHelper string() {
|
||||
return super.string().add("containerFormat", containerFormat).add("diskFormat", diskFormat).add("size", size)
|
||||
.add("checksum", checksum);
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(containerFormat, diskFormat, size, checksum);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null || getClass() != obj.getClass()) return false;
|
||||
Image that = Image.class.cast(obj);
|
||||
return super.equals(that) && Objects.equal(this.containerFormat, that.containerFormat)
|
||||
&& Objects.equal(this.diskFormat, that.diskFormat)
|
||||
&& Objects.equal(this.size, that.size)
|
||||
&& Objects.equal(this.checksum, that.checksum);
|
||||
}
|
||||
|
||||
protected ToStringHelper string() {
|
||||
return super.string()
|
||||
.add("containerFormat", containerFormat).add("diskFormat", diskFormat).add("size", size).add("checksum", checksum);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
|
@ -20,19 +20,24 @@ package org.jclouds.openstack.glance.v1_0.domain;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Predicates;
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.openstack.v2_0.domain.Link;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Objects.ToStringHelper;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
* Detailed listing of an Image
|
||||
*
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @see <a href= "http://glance.openstack.org/glanceapi.html" />
|
||||
* @see <a href= "https://github.com/openstack/glance/blob/master/glance/api/v1/images.py" />
|
||||
|
@ -48,17 +53,17 @@ public class ImageDetails extends Image {
|
|||
return new ConcreteBuilder().fromImageDetails(this);
|
||||
}
|
||||
|
||||
public static abstract class Builder<T extends Builder<T>> extends Image.Builder<T> {
|
||||
private long minDisk;
|
||||
private long minRam;
|
||||
private Optional<String> location = Optional.absent();
|
||||
private Optional<String> owner = Optional.absent();
|
||||
private Date updatedAt;
|
||||
private Date createdAt;
|
||||
private Optional<Date> deletedAt = Optional.absent();
|
||||
private Status status = Status.UNRECOGNIZED;
|
||||
private boolean isPublic;
|
||||
private Map<String, String> properties = ImmutableMap.of();
|
||||
public static abstract class Builder<T extends Builder<T>> extends Image.Builder<T> {
|
||||
protected long minDisk;
|
||||
protected long minRam;
|
||||
protected String location;
|
||||
protected String owner;
|
||||
protected Date updatedAt;
|
||||
protected Date createdAt;
|
||||
protected Date deletedAt;
|
||||
protected Image.Status status;
|
||||
protected boolean isPublic;
|
||||
protected Map<String, String> properties = ImmutableMap.of();
|
||||
|
||||
/**
|
||||
* @see ImageDetails#getMinDisk()
|
||||
|
@ -76,26 +81,11 @@ public class ImageDetails extends Image {
|
|||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ImageDetails#getLocation()
|
||||
*/
|
||||
public T location(Optional<String> location) {
|
||||
this.location = location;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ImageDetails#getLocation()
|
||||
*/
|
||||
public T location(String location) {
|
||||
return location(Optional.of(location));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ImageDetails#getOwner()
|
||||
*/
|
||||
public T owner(Optional<String> owner) {
|
||||
this.owner = owner;
|
||||
this.location = location;
|
||||
return self();
|
||||
}
|
||||
|
||||
|
@ -103,7 +93,8 @@ public class ImageDetails extends Image {
|
|||
* @see ImageDetails#getOwner()
|
||||
*/
|
||||
public T owner(String owner) {
|
||||
return owner(Optional.of(owner));
|
||||
this.owner = owner;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -125,22 +116,15 @@ public class ImageDetails extends Image {
|
|||
/**
|
||||
* @see ImageDetails#getDeletedAt()
|
||||
*/
|
||||
public T deletedAt(Optional<Date> deletedAt) {
|
||||
public T deletedAt(Date deletedAt) {
|
||||
this.deletedAt = deletedAt;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ImageDetails#getDeletedAt()
|
||||
*/
|
||||
public T deletedAt(Date deletedAt) {
|
||||
return deletedAt(Optional.of(deletedAt));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ImageDetails#getStatus()
|
||||
*/
|
||||
public T status(Status status) {
|
||||
public T status(Image.Status status) {
|
||||
this.status = status;
|
||||
return self();
|
||||
}
|
||||
|
@ -157,18 +141,26 @@ public class ImageDetails extends Image {
|
|||
* @see ImageDetails#getProperties()
|
||||
*/
|
||||
public T properties(Map<String, String> properties) {
|
||||
this.properties = properties;
|
||||
this.properties = ImmutableMap.copyOf(checkNotNull(properties, "properties"));
|
||||
return self();
|
||||
}
|
||||
|
||||
public ImageDetails build() {
|
||||
return new ImageDetails(this);
|
||||
return new ImageDetails(id, name, links, containerFormat, diskFormat, size, checksum, minDisk, minRam, location, owner, updatedAt, createdAt, deletedAt, status, isPublic, properties);
|
||||
}
|
||||
|
||||
public T fromImageDetails(ImageDetails in) {
|
||||
return super.fromImage(in).minDisk(in.getMinDisk()).minRam(in.getMinRam()).location(in.getLocation())
|
||||
.updatedAt(in.getUpdatedAt()).createdAt(in.getCreatedAt()).deletedAt(in.getDeletedAt()).status(
|
||||
in.getStatus()).isPublic(in.isPublic()).properties(in.getProperties());
|
||||
return super.fromImage(in)
|
||||
.minDisk(in.getMinDisk())
|
||||
.minRam(in.getMinRam())
|
||||
.location(in.getLocation().orNull())
|
||||
.owner(in.getOwner().orNull())
|
||||
.updatedAt(in.getUpdatedAt())
|
||||
.createdAt(in.getCreatedAt())
|
||||
.deletedAt(in.getDeletedAt().orNull())
|
||||
.status(in.getStatus())
|
||||
.isPublic(in.isPublic())
|
||||
.properties(in.getProperties());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -179,49 +171,42 @@ public class ImageDetails extends Image {
|
|||
}
|
||||
}
|
||||
|
||||
protected ImageDetails() {
|
||||
// we want serializers like Gson to work w/o using sun.misc.Unsafe,
|
||||
// prohibited in GAE. This also implies fields are not final.
|
||||
// see http://code.google.com/p/jclouds/issues/detail?id=925
|
||||
}
|
||||
@Named("min_disk")
|
||||
private final long minDisk;
|
||||
@Named("min_ram")
|
||||
private final long minRam;
|
||||
private final Optional<String> location;
|
||||
private final Optional<String> owner;
|
||||
@Named("updated_at")
|
||||
private final Date updatedAt;
|
||||
@Named("created_at")
|
||||
private final Date createdAt;
|
||||
@Named("deleted_at")
|
||||
private final Optional<Date> deletedAt;
|
||||
private final Image.Status status;
|
||||
@Named("is_public")
|
||||
private final boolean isPublic;
|
||||
private final Map<String, String> properties;
|
||||
|
||||
// | min_disk | int(11) | YES | | NULL | |
|
||||
@SerializedName("min_disk")
|
||||
private long minDisk;
|
||||
// | min_ram | int(11) | YES | | NULL | |
|
||||
@SerializedName("min_ram")
|
||||
private long minRam;
|
||||
// | location | text | YES | | NULL | |
|
||||
private Optional<String> location = Optional.absent();
|
||||
// | owner | varchar(255) | YES | | NULL | |
|
||||
private Optional<String> owner = Optional.absent();
|
||||
// | updated_at | datetime | YES | | NULL | |
|
||||
@SerializedName("updated_at")
|
||||
private Date updatedAt;
|
||||
// | created_at | datetime | NO | | NULL | |
|
||||
@SerializedName("created_at")
|
||||
private Date createdAt;
|
||||
@SerializedName("deleted_at")
|
||||
private Optional<Date> deletedAt = Optional.absent();
|
||||
// | status | varchar(30) | NO | | NULL | |
|
||||
private Status status = Status.UNRECOGNIZED;
|
||||
// | is_public | tinyint(1) | NO | | NULL | |
|
||||
@SerializedName("is_public")
|
||||
private boolean isPublic;
|
||||
private Map<String, String> properties = ImmutableMap.of();
|
||||
|
||||
protected ImageDetails(Builder<?> builder) {
|
||||
super(builder);
|
||||
this.minDisk = builder.minDisk;
|
||||
this.minRam = checkNotNull(builder.minRam, "minRam");
|
||||
this.location = checkNotNull(builder.location, "location");
|
||||
this.owner = checkNotNull(builder.owner, "owner");
|
||||
this.updatedAt = checkNotNull(builder.updatedAt, "updatedAt");
|
||||
this.createdAt = checkNotNull(builder.createdAt, "createdAt");
|
||||
this.deletedAt = checkNotNull(builder.deletedAt, "deletedAt");
|
||||
this.status = checkNotNull(builder.status, "status");
|
||||
this.isPublic = checkNotNull(builder.isPublic, "isPublic");
|
||||
this.properties = ImmutableMap.copyOf(builder.properties);
|
||||
@ConstructorProperties({
|
||||
"id", "name", "links", "container_format", "disk_format", "size", "checksum", "min_disk", "min_ram", "location", "owner", "updated_at", "created_at", "deleted_at", "status", "is_public", "properties"
|
||||
})
|
||||
protected ImageDetails(String id, @Nullable String name, Set<Link> links, @Nullable ContainerFormat containerFormat,
|
||||
@Nullable DiskFormat diskFormat, @Nullable Long size, @Nullable String checksum, long minDisk,
|
||||
long minRam, @Nullable String location, @Nullable String owner, Date updatedAt,
|
||||
Date createdAt, @Nullable Date deletedAt, Image.Status status, boolean isPublic,
|
||||
Map<String, String> properties) {
|
||||
super(id, name, links, containerFormat, diskFormat, size, checksum);
|
||||
this.minDisk = minDisk;
|
||||
this.minRam = minRam;
|
||||
this.location = Optional.fromNullable(location);
|
||||
this.owner = Optional.fromNullable(owner);
|
||||
this.updatedAt = checkNotNull(updatedAt, "updatedAt");
|
||||
this.createdAt = checkNotNull(createdAt, "createdAt");
|
||||
this.deletedAt = Optional.fromNullable(deletedAt);
|
||||
this.status = checkNotNull(status, "status");
|
||||
this.isPublic = isPublic;
|
||||
this.properties = ImmutableMap.copyOf(checkNotNull(properties, "properties"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -238,18 +223,14 @@ public class ImageDetails extends Image {
|
|||
return this.minRam;
|
||||
}
|
||||
|
||||
public Status getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
public Optional<String> getLocation() {
|
||||
return this.location;
|
||||
}
|
||||
|
||||
public Optional<String> getOwner() {
|
||||
return owner;
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
|
||||
public Date getUpdatedAt() {
|
||||
return this.updatedAt;
|
||||
}
|
||||
|
@ -262,22 +243,43 @@ public class ImageDetails extends Image {
|
|||
return this.deletedAt;
|
||||
}
|
||||
|
||||
public Image.Status getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
public boolean isPublic() {
|
||||
return this.isPublic;
|
||||
}
|
||||
|
||||
public Map<String, String> getProperties() {
|
||||
// in case this was assigned in gson
|
||||
return ImmutableMap.copyOf(Maps.filterValues(this.properties, Predicates.notNull()));
|
||||
return this.properties;
|
||||
}
|
||||
|
||||
// hashCode/equals from super is ok
|
||||
|
||||
@Override
|
||||
protected ToStringHelper string() {
|
||||
return super.string().add("minDisk", minDisk).add("minRam", minRam).add("location", location).add("deletedAt",
|
||||
getDeletedAt()).add("updatedAt", updatedAt).add("createdAt", createdAt).add("status", status).add(
|
||||
"location", location).add("owner", owner).add("isPublic", isPublic).add("properties", properties);
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(minDisk, minRam, location, owner, updatedAt, createdAt, deletedAt, status, isPublic, properties);
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null || getClass() != obj.getClass()) return false;
|
||||
ImageDetails that = ImageDetails.class.cast(obj);
|
||||
return super.equals(that) && Objects.equal(this.minDisk, that.minDisk)
|
||||
&& Objects.equal(this.minRam, that.minRam)
|
||||
&& Objects.equal(this.location, that.location)
|
||||
&& Objects.equal(this.owner, that.owner)
|
||||
&& Objects.equal(this.updatedAt, that.updatedAt)
|
||||
&& Objects.equal(this.createdAt, that.createdAt)
|
||||
&& Objects.equal(this.deletedAt, that.deletedAt)
|
||||
&& Objects.equal(this.status, that.status)
|
||||
&& Objects.equal(this.isPublic, that.isPublic)
|
||||
&& Objects.equal(this.properties, that.properties);
|
||||
}
|
||||
|
||||
protected ToStringHelper string() {
|
||||
return super.string()
|
||||
.add("minDisk", minDisk).add("minRam", minRam).add("location", location).add("owner", owner).add("updatedAt", updatedAt).add("createdAt", createdAt).add("deletedAt", deletedAt).add("status", status).add("isPublic", isPublic).add("properties", properties);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,21 +18,7 @@
|
|||
*/
|
||||
package org.jclouds.openstack.glance.v1_0.functions;
|
||||
|
||||
import static org.jclouds.openstack.glance.v1_0.options.ImageField.CHECKSUM;
|
||||
import static org.jclouds.openstack.glance.v1_0.options.ImageField.CONTAINER_FORMAT;
|
||||
import static org.jclouds.openstack.glance.v1_0.options.ImageField.CREATED_AT;
|
||||
import static org.jclouds.openstack.glance.v1_0.options.ImageField.DELETED_AT;
|
||||
import static org.jclouds.openstack.glance.v1_0.options.ImageField.DISK_FORMAT;
|
||||
import static org.jclouds.openstack.glance.v1_0.options.ImageField.ID;
|
||||
import static org.jclouds.openstack.glance.v1_0.options.ImageField.IS_PUBLIC;
|
||||
import static org.jclouds.openstack.glance.v1_0.options.ImageField.LOCATION;
|
||||
import static org.jclouds.openstack.glance.v1_0.options.ImageField.MIN_DISK;
|
||||
import static org.jclouds.openstack.glance.v1_0.options.ImageField.MIN_RAM;
|
||||
import static org.jclouds.openstack.glance.v1_0.options.ImageField.NAME;
|
||||
import static org.jclouds.openstack.glance.v1_0.options.ImageField.OWNER;
|
||||
import static org.jclouds.openstack.glance.v1_0.options.ImageField.SIZE;
|
||||
import static org.jclouds.openstack.glance.v1_0.options.ImageField.STATUS;
|
||||
import static org.jclouds.openstack.glance.v1_0.options.ImageField.UPDATED_AT;
|
||||
import static org.jclouds.openstack.glance.v1_0.options.ImageField.*;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
@ -40,11 +26,10 @@ import org.jclouds.date.DateService;
|
|||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.openstack.glance.v1_0.domain.ContainerFormat;
|
||||
import org.jclouds.openstack.glance.v1_0.domain.DiskFormat;
|
||||
import org.jclouds.openstack.glance.v1_0.domain.ImageDetails;
|
||||
import org.jclouds.openstack.glance.v1_0.domain.Image.Status;
|
||||
import org.jclouds.openstack.glance.v1_0.domain.ImageDetails;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
/**
|
||||
* This parses {@link ImageDetails} from HTTP headers.
|
||||
|
@ -63,14 +48,14 @@ public class ParseImageDetailsFromHeaders implements Function<HttpResponse, Imag
|
|||
ImageDetails.Builder<?> builder = ImageDetails.builder()
|
||||
.id(from.getFirstHeaderOrNull(ID.asHeader()))
|
||||
.name(from.getFirstHeaderOrNull(NAME.asHeader()))
|
||||
.checksum(Optional.fromNullable(from.getFirstHeaderOrNull(CHECKSUM.asHeader())))
|
||||
.checksum(from.getFirstHeaderOrNull(CHECKSUM.asHeader()))
|
||||
.minDisk(Long.parseLong(from.getFirstHeaderOrNull(MIN_DISK.asHeader())))
|
||||
.minRam(Long.parseLong(from.getFirstHeaderOrNull(MIN_RAM.asHeader())))
|
||||
.isPublic(Boolean.parseBoolean(from.getFirstHeaderOrNull(IS_PUBLIC.asHeader())))
|
||||
.createdAt(dateService.iso8601SecondsDateParse(from.getFirstHeaderOrNull(CREATED_AT.asHeader())))
|
||||
.updatedAt(dateService.iso8601SecondsDateParse(from.getFirstHeaderOrNull(UPDATED_AT.asHeader())))
|
||||
.owner(Optional.fromNullable(from.getFirstHeaderOrNull(OWNER.asHeader())))
|
||||
.location(Optional.fromNullable(from.getFirstHeaderOrNull(LOCATION.asHeader())))
|
||||
.owner(from.getFirstHeaderOrNull(OWNER.asHeader()))
|
||||
.location(from.getFirstHeaderOrNull(LOCATION.asHeader()))
|
||||
.status(Status.fromValue(from.getFirstHeaderOrNull(STATUS.asHeader())));
|
||||
|
||||
String containerFormat = from.getFirstHeaderOrNull(CONTAINER_FORMAT.asHeader());
|
||||
|
|
|
@ -53,7 +53,7 @@ public class ParseImageDetailsTest extends BaseItemParserTest<ImageDetails> {
|
|||
.containerFormat(ContainerFormat.BARE)
|
||||
.diskFormat(DiskFormat.RAW)
|
||||
.checksum("6ae4e0fdc3c108a1bfe10ef5e436f4f4")
|
||||
.size(27)
|
||||
.size(27L)
|
||||
.status(Image.Status.ACTIVE)
|
||||
.owner("68a7c7abb7bf45ada1536dfa28ec2115")
|
||||
.isPublic(false)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
|
@ -18,29 +18,30 @@
|
|||
*/
|
||||
package org.jclouds.openstack.quantum.v1_0.domain;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
|
||||
/**
|
||||
* A Quantum attachment
|
||||
*
|
||||
*
|
||||
* @author Adam Lowe
|
||||
* @see <a href="http://docs.openstack.org/api/openstack-network/1.0/content/Attachments.html">api doc</a>
|
||||
*/
|
||||
*/
|
||||
public class Attachment extends Reference {
|
||||
|
||||
public static Builder<?> builder() {
|
||||
public static Builder<?> builder() {
|
||||
return new ConcreteBuilder();
|
||||
}
|
||||
|
||||
public Builder<?> toBuilder() {
|
||||
|
||||
public Builder<?> toBuilder() {
|
||||
return new ConcreteBuilder().fromAttachment(this);
|
||||
}
|
||||
|
||||
public static abstract class Builder<T extends Builder<T>> extends Reference.Builder<T> {
|
||||
protected abstract T self();
|
||||
|
||||
public static abstract class Builder<T extends Builder<T>> extends Reference.Builder<T> {
|
||||
|
||||
public Attachment build() {
|
||||
return new Attachment(this);
|
||||
return new Attachment(id);
|
||||
}
|
||||
|
||||
|
||||
public T fromAttachment(Attachment in) {
|
||||
return super.fromReference(in);
|
||||
}
|
||||
|
@ -53,11 +54,12 @@ public class Attachment extends Reference {
|
|||
}
|
||||
}
|
||||
|
||||
protected Attachment(Builder<?> builder) {
|
||||
super(builder);
|
||||
|
||||
@ConstructorProperties({
|
||||
"id"
|
||||
})
|
||||
protected Attachment(String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
protected Attachment() {
|
||||
// for GSON
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
|
@ -20,31 +20,40 @@ package org.jclouds.openstack.quantum.v1_0.domain;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Objects.ToStringHelper;
|
||||
|
||||
/**
|
||||
* A Quantum network
|
||||
*
|
||||
*
|
||||
* @author Adam Lowe
|
||||
* @see <a href="http://docs.openstack.org/api/openstack-network/1.0/content/Networks.html">api doc</a>
|
||||
*/
|
||||
*/
|
||||
public class Network extends Reference {
|
||||
|
||||
public static Builder<?> builder() {
|
||||
public static Builder<?> builder() {
|
||||
return new ConcreteBuilder();
|
||||
}
|
||||
|
||||
public Builder<?> toBuilder() {
|
||||
|
||||
public Builder<?> toBuilder() {
|
||||
return new ConcreteBuilder().fromNetwork(this);
|
||||
}
|
||||
|
||||
public static abstract class Builder<T extends Builder<T>> extends Reference.Builder<T> {
|
||||
protected abstract T self();
|
||||
|
||||
private String name;
|
||||
|
||||
/**
|
||||
public static abstract class Builder<T extends Builder<T>> extends Reference.Builder<T> {
|
||||
protected String name;
|
||||
|
||||
/**
|
||||
* @see Network#getName()
|
||||
*/
|
||||
public T name(String name) {
|
||||
|
@ -53,11 +62,12 @@ public class Network extends Reference {
|
|||
}
|
||||
|
||||
public Network build() {
|
||||
return new Network(this);
|
||||
return new Network(id, name);
|
||||
}
|
||||
|
||||
|
||||
public T fromNetwork(Network in) {
|
||||
return super.fromReference(in).name(in.getName());
|
||||
return super.fromReference(in)
|
||||
.name(in.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,25 +80,21 @@ public class Network extends Reference {
|
|||
|
||||
private final String name;
|
||||
|
||||
protected Network(Builder<?> builder) {
|
||||
super(builder);
|
||||
this.name = checkNotNull(builder.name, "name");
|
||||
@ConstructorProperties({
|
||||
"id", "name"
|
||||
})
|
||||
protected Network(String id, String name) {
|
||||
super(id);
|
||||
this.name = checkNotNull(name, "name");
|
||||
}
|
||||
|
||||
protected Network() {
|
||||
// for GSON
|
||||
this.name = null;
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(super.hashCode(), name);
|
||||
return Objects.hashCode(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -98,8 +104,10 @@ public class Network extends Reference {
|
|||
Network that = Network.class.cast(obj);
|
||||
return super.equals(that) && Objects.equal(this.name, that.name);
|
||||
}
|
||||
|
||||
|
||||
protected ToStringHelper string() {
|
||||
return super.string().add("name", name);
|
||||
return super.string()
|
||||
.add("name", name);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
|
@ -20,7 +20,7 @@ package org.jclouds.openstack.quantum.v1_0.domain;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.beans.ConstructorProperties;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
@ -29,28 +29,28 @@ import com.google.common.collect.ImmutableSet;
|
|||
|
||||
/**
|
||||
* Details of a Quantum network
|
||||
*
|
||||
*
|
||||
* @author Adam Lowe
|
||||
* @see <a href="http://docs.openstack.org/api/openstack-network/1.0/content/Networks.html">api doc</a>
|
||||
*/
|
||||
*/
|
||||
public class NetworkDetails extends Network {
|
||||
|
||||
public static Builder<?> builder() {
|
||||
public static Builder<?> builder() {
|
||||
return new ConcreteBuilder();
|
||||
}
|
||||
|
||||
public Builder<?> toBuilder() {
|
||||
|
||||
public Builder<?> toBuilder() {
|
||||
return new ConcreteBuilder().fromNetworkDetails(this);
|
||||
}
|
||||
|
||||
public static abstract class Builder<T extends Builder<T>> extends Network.Builder<T> {
|
||||
private Set<Port> ports = ImmutableSet.of();
|
||||
|
||||
/**
|
||||
protected Set<Port> ports = ImmutableSet.of();
|
||||
|
||||
/**
|
||||
* @see NetworkDetails#getPorts()
|
||||
*/
|
||||
public T ports(Set<Port> ports) {
|
||||
this.ports = ports;
|
||||
this.ports = ImmutableSet.copyOf(checkNotNull(ports, "ports"));
|
||||
return self();
|
||||
}
|
||||
|
||||
|
@ -59,11 +59,12 @@ public class NetworkDetails extends Network {
|
|||
}
|
||||
|
||||
public NetworkDetails build() {
|
||||
return new NetworkDetails(this);
|
||||
return new NetworkDetails(id, name, ports);
|
||||
}
|
||||
|
||||
|
||||
public T fromNetworkDetails(NetworkDetails in) {
|
||||
return super.fromNetwork(in).ports(in.getPorts());
|
||||
return super.fromNetwork(in)
|
||||
.ports(in.getPorts());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,20 +77,16 @@ public class NetworkDetails extends Network {
|
|||
|
||||
private final Set<Port> ports;
|
||||
|
||||
protected NetworkDetails(Builder<?> builder) {
|
||||
super(builder);
|
||||
this.ports = ImmutableSet.copyOf(checkNotNull(builder.ports, "ports"));
|
||||
@ConstructorProperties({
|
||||
"id", "name", "ports"
|
||||
})
|
||||
protected NetworkDetails(String id, String name, Set<Port> ports) {
|
||||
super(id, name);
|
||||
this.ports = ImmutableSet.copyOf(checkNotNull(ports, "ports"));
|
||||
}
|
||||
|
||||
protected NetworkDetails() {
|
||||
// for GSON
|
||||
this.ports = ImmutableSet.of();
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public Set<Port> getPorts() {
|
||||
return Collections.unmodifiableSet(this.ports);
|
||||
return this.ports;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -104,9 +101,10 @@ public class NetworkDetails extends Network {
|
|||
NetworkDetails that = NetworkDetails.class.cast(obj);
|
||||
return super.equals(that) && Objects.equal(this.ports, that.ports);
|
||||
}
|
||||
|
||||
|
||||
protected ToStringHelper string() {
|
||||
return super.string().add("ports", ports);
|
||||
return super.string()
|
||||
.add("ports", ports);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
|
@ -20,35 +20,37 @@ package org.jclouds.openstack.quantum.v1_0.domain;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Objects.ToStringHelper;
|
||||
|
||||
/**
|
||||
* A Quantum port
|
||||
*
|
||||
*
|
||||
* @author Adam Lowe
|
||||
* @see <a href="http://docs.openstack.org/api/openstack-network/1.0/content/Ports.html">api doc</a>
|
||||
*/
|
||||
*/
|
||||
public class Port extends Reference {
|
||||
|
||||
/**
|
||||
*/
|
||||
public static enum State {
|
||||
ACTIVE, DOWN
|
||||
}
|
||||
|
||||
public static Builder<?> builder() {
|
||||
public static Builder<?> builder() {
|
||||
return new ConcreteBuilder();
|
||||
}
|
||||
|
||||
public Builder<?> toBuilder() {
|
||||
|
||||
public Builder<?> toBuilder() {
|
||||
return new ConcreteBuilder().fromPort(this);
|
||||
}
|
||||
|
||||
public static abstract class Builder<T extends Builder<T>> extends Reference.Builder<T> {
|
||||
protected abstract T self();
|
||||
|
||||
private Port.State state;
|
||||
|
||||
/**
|
||||
public static abstract class Builder<T extends Builder<T>> extends Reference.Builder<T> {
|
||||
protected Port.State state;
|
||||
|
||||
/**
|
||||
* @see Port#getState()
|
||||
*/
|
||||
public T state(Port.State state) {
|
||||
|
@ -57,11 +59,12 @@ public class Port extends Reference {
|
|||
}
|
||||
|
||||
public Port build() {
|
||||
return new Port(this);
|
||||
return new Port(id, state);
|
||||
}
|
||||
|
||||
|
||||
public T fromPort(Port in) {
|
||||
return fromReference(in).state(in.getState());
|
||||
return super.fromReference(in)
|
||||
.state(in.getState());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,14 +77,12 @@ public class Port extends Reference {
|
|||
|
||||
private final Port.State state;
|
||||
|
||||
protected Port(Builder<?> builder) {
|
||||
super(builder);
|
||||
this.state = checkNotNull(builder.state, "state");
|
||||
}
|
||||
|
||||
protected Port() {
|
||||
// for GSON
|
||||
this.state = null;
|
||||
@ConstructorProperties({
|
||||
"id", "state"
|
||||
})
|
||||
protected Port(String id, Port.State state) {
|
||||
super(id);
|
||||
this.state = checkNotNull(state, "state");
|
||||
}
|
||||
|
||||
public Port.State getState() {
|
||||
|
@ -90,7 +91,7 @@ public class Port extends Reference {
|
|||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(super.hashCode(), state);
|
||||
return Objects.hashCode(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -100,8 +101,10 @@ public class Port extends Reference {
|
|||
Port that = Port.class.cast(obj);
|
||||
return super.equals(that) && Objects.equal(this.state, that.state);
|
||||
}
|
||||
|
||||
|
||||
protected ToStringHelper string() {
|
||||
return super.string().add("state", state);
|
||||
return super.string()
|
||||
.add("state", state);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
package org.jclouds.openstack.quantum.v1_0.domain;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
@ -25,24 +27,24 @@ import com.google.common.base.Objects.ToStringHelper;
|
|||
|
||||
/**
|
||||
* Details of a Quantum Port
|
||||
*
|
||||
*
|
||||
* @author Adam Lowe
|
||||
* @see <a href="http://docs.openstack.org/api/openstack-network/1.0/content/Ports.html">api doc</a>
|
||||
*/
|
||||
*/
|
||||
public class PortDetails extends Port {
|
||||
|
||||
public static Builder<?> builder() {
|
||||
public static Builder<?> builder() {
|
||||
return new ConcreteBuilder();
|
||||
}
|
||||
|
||||
public Builder<?> toBuilder() {
|
||||
|
||||
public Builder<?> toBuilder() {
|
||||
return new ConcreteBuilder().fromPortDetails(this);
|
||||
}
|
||||
|
||||
public static abstract class Builder<T extends Builder<T>> extends Port.Builder<T> {
|
||||
private Attachment attachment;
|
||||
|
||||
/**
|
||||
public static abstract class Builder<T extends Builder<T>> extends Port.Builder<T> {
|
||||
protected Attachment attachment;
|
||||
|
||||
/**
|
||||
* @see PortDetails#getAttachment()
|
||||
*/
|
||||
public T attachment(Attachment attachment) {
|
||||
|
@ -51,11 +53,12 @@ public class PortDetails extends Port {
|
|||
}
|
||||
|
||||
public PortDetails build() {
|
||||
return new PortDetails(this);
|
||||
return new PortDetails(id, state, attachment);
|
||||
}
|
||||
|
||||
|
||||
public T fromPortDetails(PortDetails in) {
|
||||
return super.fromPort(in).attachment(in.getAttachment());
|
||||
return super.fromPort(in)
|
||||
.attachment(in.getAttachment());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,17 +69,14 @@ public class PortDetails extends Port {
|
|||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private final Attachment attachment;
|
||||
|
||||
protected PortDetails(Builder<?> builder) {
|
||||
super(builder);
|
||||
this.attachment = builder.attachment;
|
||||
}
|
||||
|
||||
protected PortDetails() {
|
||||
// for GSON
|
||||
this.attachment = null;
|
||||
@ConstructorProperties({
|
||||
"id", "state", "attachment"
|
||||
})
|
||||
protected PortDetails(String id, Port.State state, @Nullable Attachment attachment) {
|
||||
super(id, state);
|
||||
this.attachment = attachment;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -96,9 +96,10 @@ public class PortDetails extends Port {
|
|||
PortDetails that = PortDetails.class.cast(obj);
|
||||
return super.equals(that) && Objects.equal(this.attachment, that.attachment);
|
||||
}
|
||||
|
||||
|
||||
protected ToStringHelper string() {
|
||||
return super.string().add("attachment", attachment);
|
||||
return super.string()
|
||||
.add("attachment", attachment);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
|
@ -20,32 +20,34 @@ package org.jclouds.openstack.quantum.v1_0.domain;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Objects.ToStringHelper;
|
||||
|
||||
/**
|
||||
* A wrapper around an id in the quantum api
|
||||
*
|
||||
*
|
||||
* @author Adam Lowe
|
||||
* @see <a href="http://docs.openstack.org/api/openstack-network/1.0/content/Networks.html">api doc</a>
|
||||
*/
|
||||
*/
|
||||
public class Reference {
|
||||
|
||||
public static Builder<?> builder() {
|
||||
public static Builder<?> builder() {
|
||||
return new ConcreteBuilder();
|
||||
}
|
||||
|
||||
public Builder<?> toBuilder() {
|
||||
|
||||
public Builder<?> toBuilder() {
|
||||
return new ConcreteBuilder().fromReference(this);
|
||||
}
|
||||
|
||||
public static abstract class Builder<T extends Builder<T>> {
|
||||
protected abstract T self();
|
||||
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* @see org.jclouds.openstack.quantum.v1_0.domain.Reference#getId()
|
||||
protected String id;
|
||||
|
||||
/**
|
||||
* @see Reference#getId()
|
||||
*/
|
||||
public T id(String id) {
|
||||
this.id = id;
|
||||
|
@ -53,11 +55,12 @@ public class Reference {
|
|||
}
|
||||
|
||||
public Reference build() {
|
||||
return new Reference(this);
|
||||
return new Reference(id);
|
||||
}
|
||||
|
||||
|
||||
public T fromReference(Reference in) {
|
||||
return this.id(in.getId());
|
||||
return this
|
||||
.id(in.getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,22 +73,17 @@ public class Reference {
|
|||
|
||||
private final String id;
|
||||
|
||||
protected Reference(Builder<?> builder) {
|
||||
this.id = checkNotNull(builder.id, "id");
|
||||
@ConstructorProperties({
|
||||
"id"
|
||||
})
|
||||
protected Reference(String id) {
|
||||
this.id = checkNotNull(id, "id");
|
||||
}
|
||||
|
||||
protected Reference() {
|
||||
// for GSON
|
||||
this.id = null;
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(id);
|
||||
|
@ -98,14 +96,15 @@ public class Reference {
|
|||
Reference that = Reference.class.cast(obj);
|
||||
return Objects.equal(this.id, that.id);
|
||||
}
|
||||
|
||||
|
||||
protected ToStringHelper string() {
|
||||
return Objects.toStringHelper("").add("id", id);
|
||||
return Objects.toStringHelper(this)
|
||||
.add("id", id);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return string().toString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ package org.jclouds.openstack.swift.v1.domain;
|
|||
import static com.google.common.base.Objects.equal;
|
||||
import static com.google.common.base.Objects.toStringHelper;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Objects.ToStringHelper;
|
||||
|
||||
|
@ -48,17 +50,12 @@ public class AccountMetadata {
|
|||
return containerCount(from.getContainerCount()).bytesUsed(from.getBytesUsed());
|
||||
}
|
||||
}
|
||||
|
||||
protected AccountMetadata() {
|
||||
// we want serializers like Gson to work w/o using sun.misc.Unsafe,
|
||||
// prohibited in GAE. This also implies fields are not final.
|
||||
// see http://code.google.com/p/jclouds/issues/detail?id=925
|
||||
}
|
||||
|
||||
protected int containerCount;
|
||||
protected long bytesUsed;
|
||||
|
||||
public AccountMetadata(int containerCount, long bytesUsed) {
|
||||
@ConstructorProperties({"containerCount", "bytesUsed"})
|
||||
protected AccountMetadata(int containerCount, long bytesUsed) {
|
||||
this.containerCount = containerCount;
|
||||
this.bytesUsed = bytesUsed;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import static com.google.common.base.Objects.equal;
|
|||
import static com.google.common.base.Objects.toStringHelper;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Objects.ToStringHelper;
|
||||
|
||||
|
@ -64,18 +66,13 @@ public class ContainerMetadata implements Comparable<ContainerMetadata> {
|
|||
return name(from.getName()).count(from.getCount()).bytes(from.getBytes());
|
||||
}
|
||||
}
|
||||
|
||||
protected ContainerMetadata() {
|
||||
// we want serializers like Gson to work w/o using sun.misc.Unsafe,
|
||||
// prohibited in GAE. This also implies fields are not final.
|
||||
// see http://code.google.com/p/jclouds/issues/detail?id=925
|
||||
}
|
||||
|
||||
protected String name;
|
||||
protected int count;
|
||||
protected int bytes;
|
||||
|
||||
public ContainerMetadata(String name, int count, int bytes) {
|
||||
@ConstructorProperties({"name", "count", "bytes"})
|
||||
protected ContainerMetadata(String name, int count, int bytes) {
|
||||
this.name = checkNotNull(name, "name");
|
||||
this.count = count;
|
||||
this.bytes = bytes;
|
||||
|
|
Loading…
Reference in New Issue