naming conventions

This commit is contained in:
Adrian Cole 2012-01-30 23:58:30 -08:00
parent 52fc2c2be1
commit 42e8cd4977
8 changed files with 83 additions and 83 deletions

View File

@ -20,15 +20,15 @@ package org.jclouds.glesys.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import com.google.common.base.Joiner;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
import com.google.gson.annotations.SerializedName;
/**
* Lists the allowed arguments for some of the functions in this module such as disksize, cpucores etc.
* Sets the allowed arguments for some of the functions in this module such as disksize, cpucores etc.
*
* @author Adam Lowe
* @see <a href="https://customer.glesys.com/api.php?a=doc#server_allowedarguments" />
@ -39,64 +39,64 @@ public class AllowedArgumentsForCreateServer {
}
public static class Builder {
private List<Integer> diskSizes;
private List<Integer> memorySizes;
private List<Integer> cpuCores;
private List<String> templates;
private List<Integer> transfers;
private List<String> dataCenters;
private Set<Integer> diskSizes;
private Set<Integer> memorySizes;
private Set<Integer> cpuCores;
private Set<String> templates;
private Set<Integer> transfers;
private Set<String> dataCenters;
public Builder diskSizes(Integer... sizes) {
return diskSizes(Arrays.<Integer>asList(sizes));
return diskSizes(ImmutableSet.<Integer>copyOf(sizes));
}
public Builder diskSizes(List<Integer> sizes) {
public Builder diskSizes(Set<Integer> sizes) {
this.diskSizes = sizes;
return this;
}
public Builder memorySizes(Integer... sizes) {
return memorySizes(Arrays.<Integer>asList(sizes));
return memorySizes(ImmutableSet.<Integer>copyOf(sizes));
}
public Builder memorySizes(List<Integer> sizes) {
public Builder memorySizes(Set<Integer> sizes) {
this.memorySizes = sizes;
return this;
}
public Builder cpuCores(Integer... cpuCores) {
this.cpuCores = Arrays.<Integer>asList(cpuCores);
this.cpuCores = ImmutableSet.<Integer>copyOf(cpuCores);
return this;
}
public Builder cpuCores(List<Integer> cpuCores) {
public Builder cpuCores(Set<Integer> cpuCores) {
this.cpuCores = cpuCores;
return this;
}
public Builder templates(String... templates) {
return templates(Arrays.<String>asList(templates));
return templates(ImmutableSet.<String>copyOf(templates));
}
public Builder templates(List<String> templates) {
public Builder templates(Set<String> templates) {
this.templates = templates;
return this;
}
public Builder transfers(Integer... transfers) {
return transfers(Arrays.<Integer>asList(transfers));
return transfers(ImmutableSet.<Integer>copyOf(transfers));
}
public Builder transfers(List<Integer> transfers) {
public Builder transfers(Set<Integer> transfers) {
this.transfers = transfers;
return this;
}
public Builder dataCenters(String... dataCenters) {
return dataCenters(Arrays.<String>asList(dataCenters));
return dataCenters(ImmutableSet.<String>copyOf(dataCenters));
}
public Builder dataCenters(List<String> dataCenters) {
public Builder dataCenters(Set<String> dataCenters) {
this.dataCenters = dataCenters;
return this;
}
@ -106,30 +106,30 @@ public class AllowedArgumentsForCreateServer {
}
public Builder fromAllowedArguments(AllowedArgumentsForCreateServer in) {
return diskSizes(in.getDiskSizes())
.memorySizes(in.getMemorySizes())
.cpuCores(in.getCpuCores())
.templates(in.getTemplates())
.transfers(in.getTransfers())
return diskSizes(in.getDiskSizesInGB())
.memorySizes(in.getMemorySizesInMB())
.cpuCores(in.getCpuCoreOptions())
.templates(in.getTemplateNames())
.transfers(in.getTransfersInGB())
.dataCenters(in.getDataCenters());
}
}
@SerializedName("disksize")
private final List<Integer> diskSizes;
private final Set<Integer> diskSizes;
@SerializedName("memorysize")
private final List<Integer> memorySizes;
private final Set<Integer> memorySizes;
@SerializedName("cpucores")
private final List<Integer> cpuCores;
private final Set<Integer> cpuCores;
@SerializedName("template")
private final List<String> templates;
private final Set<String> templates;
@SerializedName("transfer")
private final List<Integer> transfers;
private final Set<Integer> transfers;
@SerializedName("datacenter")
private final List<String> dataCenters;
private final Set<String> dataCenters;
public AllowedArgumentsForCreateServer(List<Integer> diskSizes, List<Integer> memorySizes, List<Integer> cpuCores,
List<String> templates, List<Integer> transfers, List<String> dataCenters) {
public AllowedArgumentsForCreateServer(Set<Integer> diskSizes, Set<Integer> memorySizes, Set<Integer> cpuCores,
Set<String> templates, Set<Integer> transfers, Set<String> dataCenters) {
checkNotNull(diskSizes, "diskSizes");
checkNotNull(memorySizes, "memorySizes");
checkNotNull(cpuCores, "cpuCores");
@ -147,46 +147,46 @@ public class AllowedArgumentsForCreateServer {
/**
* @return a list of disk sizes, in GB, that can be used for creating servers on this platform
* @see org.jclouds.glesys.domain.Template#getMinDiskSize()
* @see org.jclouds.glesys.domain.OSTemplate#getMinDiskSize()
*/
public List<Integer> getDiskSizes() {
public Set<Integer> getDiskSizesInGB() {
return diskSizes;
}
/**
* @return a list of memory sizes, in MB, that can be used for creating servers on this platform
* @see org.jclouds.glesys.domain.Template#getMinMemSize()
* @see org.jclouds.glesys.domain.OSTemplate#getMinMemSize()
*/
public List<Integer> getMemorySizes() {
public Set<Integer> getMemorySizesInMB() {
return memorySizes;
}
/**
* @return a list of which core counts can be used for creating servers on this platform
*/
public List<Integer> getCpuCores() {
public Set<Integer> getCpuCoreOptions() {
return cpuCores;
}
/**
* @return a list of template names available for creating servers on this platform
* @see org.jclouds.glesys.domain.Template#getName()
* @see org.jclouds.glesys.domain.OSTemplate#getName()
*/
public List<String> getTemplates() {
public Set<String> getTemplateNames() {
return templates;
}
/**
* @return the list of transfer settings available for creating servers on this platform
*/
public List<Integer> getTransfers() {
public Set<Integer> getTransfersInGB() {
return transfers;
}
/**
* @return the list of datacenters available that support creating servers on this platform
*/
public List<String> getDataCenters() {
public Set<String> getDataCenters() {
return dataCenters;
}

View File

@ -28,7 +28,7 @@ import com.google.gson.annotations.SerializedName;
* @author Adam Lowe
* @see <a href= "https://customer.glesys.com/api.php?a=doc#server_templates" />
*/
public class Template implements Comparable<Template>{
public class OSTemplate implements Comparable<OSTemplate>{
public static Builder builder() {
return new Builder();
@ -66,11 +66,11 @@ public class Template implements Comparable<Template>{
return this;
}
public Template build() {
return new Template(name, minDiskSize, minMemSize, os, platform);
public OSTemplate build() {
return new OSTemplate(name, minDiskSize, minMemSize, os, platform);
}
public Builder fromTemplate(Template in) {
public Builder fromTemplate(OSTemplate in) {
return name(in.getName()).minDiskSize(in.getMinDiskSize()).minMemSize(in.getMinMemSize()).os(in.getOs()).platform(in.getPlatform());
}
@ -85,7 +85,7 @@ public class Template implements Comparable<Template>{
private final String os;
private final String platform;
public Template(String name, int minDiskSize, int minMemSize, String os, String platform) {
public OSTemplate(String name, int minDiskSize, int minMemSize, String os, String platform) {
this.name = name;
this.minDiskSize = minDiskSize;
this.minMemSize = minMemSize;
@ -99,7 +99,7 @@ public class Template implements Comparable<Template>{
/**
* @return the minimum allowed disk size in GB
* @see org.jclouds.glesys.domain.AllowedArgumentsForCreateServer#getDiskSizes()
* @see org.jclouds.glesys.domain.AllowedArgumentsForCreateServer#getDiskSizesInGB()
*/
public int getMinDiskSize() {
return minDiskSize;
@ -107,7 +107,7 @@ public class Template implements Comparable<Template>{
/**
* @return the minimum allowed memory size in MB
* @see org.jclouds.glesys.domain.AllowedArgumentsForCreateServer#getMemorySizes()
* @see org.jclouds.glesys.domain.AllowedArgumentsForCreateServer#getMemorySizesInMB()
*/
public int getMinMemSize() {
return minMemSize;
@ -132,8 +132,8 @@ public class Template implements Comparable<Template>{
if (this == object) {
return true;
}
if (object instanceof Template) {
final Template other = (Template) object;
if (object instanceof OSTemplate) {
final OSTemplate other = (OSTemplate) object;
return Objects.equal(name, other.name)
&& Objects.equal(platform, other.platform);
} else {
@ -153,7 +153,7 @@ public class Template implements Comparable<Template>{
}
@Override
public int compareTo(Template arg0) {
public int compareTo(OSTemplate arg0) {
return Ordering.usingToString().compare(this, arg0);
}
}

View File

@ -97,7 +97,7 @@ public class ServerDetails extends Server {
}
public Builder fromServerDetails(ServerDetails in) {
return fromServer(in).templateName(in.getTemplateName()).memorySize(in.getMemorySize()).diskSize(in.getDiskSize()).cpuCores(in.getCpuCores()).cost(in.getCost())
return fromServer(in).templateName(in.getTemplateName()).memorySize(in.getMemorySizeMB()).diskSize(in.getDiskSizeGB()).cpuCores(in.getCpuCores()).cost(in.getCost())
.description(in.getDescription()).ips(in.getIps());
}
@ -171,21 +171,21 @@ public class ServerDetails extends Server {
/**
* @return the disk of the server in GB
*/
public int getDiskSize() {
public int getDiskSizeGB() {
return diskSize;
}
/**
* @return the memory of the server in MB
*/
public int getMemorySize() {
public int getMemorySizeMB() {
return memorySize;
}
/**
* @return the transfer of the server
*/
public int getTransfer() {
public int getTransferGB() {
return transfer;
}

View File

@ -46,7 +46,7 @@ public class ServerSpec {
protected int diskSizeGB;
protected int memorySizeMB;
protected int cpuCores;
protected int transfer;
protected int transferGB;
public Builder datacenter(String datacenter) {
this.datacenter = datacenter;
@ -78,19 +78,19 @@ public class ServerSpec {
return this;
}
public Builder transfer(int transfer) {
this.transfer = transfer;
public Builder transferGB(int transferGB) {
this.transferGB = transferGB;
return this;
}
public ServerSpec build() {
return new ServerSpec(platform, datacenter, memorySizeMB, diskSizeGB, templateName, cpuCores, transfer);
return new ServerSpec(platform, datacenter, memorySizeMB, diskSizeGB, templateName, cpuCores, transferGB);
}
public static Builder fromServerSpecification(ServerSpec in) {
return new Builder().platform(in.getPlatform()).datacenter(in.getDatacenter())
.memorySizeMB(in.getMemorySizeMB()).diskSizeGB(in.getDiskSizeGB()).templateName(in.getTemplateName())
.cpuCores(in.getCpuCores()).transfer(in.getTransfer());
.cpuCores(in.getCpuCores()).transferGB(in.getTransferGB());
}
}
@ -100,17 +100,17 @@ public class ServerSpec {
protected final int diskSizeGB;
protected final String templateName;
protected final int cpuCores;
protected final int transfer;
protected final int transferGB;
protected ServerSpec(String platform, String datacenter, int memorySizeMB, int diskSizeGB, String templateName,
int cpuCores, int transfer) {
int cpuCores, int transferGB) {
this.platform = checkNotNull(platform, "platform");
this.datacenter = checkNotNull(datacenter, "datacenter");
this.memorySizeMB = memorySizeMB;
this.diskSizeGB = diskSizeGB;
this.templateName = checkNotNull(templateName, "templateName");
this.cpuCores = cpuCores;
this.transfer = transfer;
this.transferGB = transferGB;
}
/**
@ -156,10 +156,10 @@ public class ServerSpec {
}
/**
* @return number of transfer
* @return bandwidth of in GB
*/
public int getTransfer() {
return transfer;
public int getTransferGB() {
return transferGB;
}
@Override
@ -172,7 +172,7 @@ public class ServerSpec {
return equal(platform, that.platform) && equal(datacenter, that.datacenter)
&& equal(memorySizeMB, that.memorySizeMB) && equal(diskSizeGB, that.diskSizeGB)
&& equal(templateName, that.templateName) && equal(cpuCores, that.cpuCores)
&& equal(transfer, that.transfer);
&& equal(transferGB, that.transferGB);
} else {
return false;
}
@ -180,13 +180,13 @@ public class ServerSpec {
@Override
public int hashCode() {
return Objects.hashCode(platform, datacenter, memorySizeMB, diskSizeGB, templateName, cpuCores, transfer);
return Objects.hashCode(platform, datacenter, memorySizeMB, diskSizeGB, templateName, cpuCores, transferGB);
}
@Override
public String toString() {
return toStringHelper("").add("platform", platform).add("datacenter", datacenter)
.add("templateName", templateName).add("cpuCores", cpuCores).add("cpuCores", cpuCores)
.add("diskSizeGB", diskSizeGB).add("transfer", transfer).toString();
.add("diskSizeGB", diskSizeGB).add("transferGB", transferGB).toString();
}
}

View File

@ -36,7 +36,7 @@ import org.jclouds.glesys.domain.ServerDetails;
import org.jclouds.glesys.domain.ServerLimit;
import org.jclouds.glesys.domain.ServerSpec;
import org.jclouds.glesys.domain.ServerStatus;
import org.jclouds.glesys.domain.Template;
import org.jclouds.glesys.domain.OSTemplate;
import org.jclouds.glesys.functions.ParseTemplatesFromHttpResponse;
import org.jclouds.glesys.options.CloneServerOptions;
import org.jclouds.glesys.options.CreateServerOptions;
@ -134,7 +134,7 @@ public interface ServerAsyncClient {
@Path("/server/templates/format/json")
@ResponseParser(ParseTemplatesFromHttpResponse.class)
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Set<Template>> getTemplates();
ListenableFuture<Set<OSTemplate>> listTemplates();
/**
* @see ServerClient#stopServer

View File

@ -30,7 +30,7 @@ import org.jclouds.glesys.domain.ServerDetails;
import org.jclouds.glesys.domain.ServerLimit;
import org.jclouds.glesys.domain.ServerSpec;
import org.jclouds.glesys.domain.ServerStatus;
import org.jclouds.glesys.domain.Template;
import org.jclouds.glesys.domain.OSTemplate;
import org.jclouds.glesys.options.CloneServerOptions;
import org.jclouds.glesys.options.CreateServerOptions;
import org.jclouds.glesys.options.DestroyServerOptions;
@ -105,7 +105,7 @@ public interface ServerClient {
*
* @return the set of information about each template
*/
Set<Template> getTemplates();
Set<OSTemplate> listTemplates();
/**
* Get information about valid arguments to #createServer for each platform

View File

@ -25,7 +25,7 @@ import java.util.Set;
import javax.inject.Singleton;
import org.jclouds.glesys.domain.Template;
import org.jclouds.glesys.domain.OSTemplate;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
import org.jclouds.json.internal.GsonWrapper;
@ -40,19 +40,19 @@ import com.google.inject.TypeLiteral;
* @author Adrian Cole
*/
@Singleton
public class ParseTemplatesFromHttpResponse implements Function<HttpResponse, Set<Template>> {
private final ParseFirstJsonValueNamed<Map<String, Set<Template>>> parser;
public class ParseTemplatesFromHttpResponse implements Function<HttpResponse, Set<OSTemplate>> {
private final ParseFirstJsonValueNamed<Map<String, Set<OSTemplate>>> parser;
@Inject
public ParseTemplatesFromHttpResponse(GsonWrapper gsonWrapper) {
this.parser = new ParseFirstJsonValueNamed<Map<String, Set<Template>>>(checkNotNull(gsonWrapper,
"gsonWrapper"), new TypeLiteral<Map<String, Set<Template>>>() {
this.parser = new ParseFirstJsonValueNamed<Map<String, Set<OSTemplate>>>(checkNotNull(gsonWrapper,
"gsonWrapper"), new TypeLiteral<Map<String, Set<OSTemplate>>>() {
}, "templates");
}
public Set<Template> apply(HttpResponse response) {
public Set<OSTemplate> apply(HttpResponse response) {
checkNotNull(response, "response");
Map<String, Set<Template>> toParse = parser.apply(response);
Map<String, Set<OSTemplate>> toParse = parser.apply(response);
checkNotNull(toParse, "parsed result from %s", response);
return ImmutableSet.copyOf(Iterables.concat(toParse.values()));
}

View File

@ -59,7 +59,7 @@ public class CreateServerOptions implements MapBinder {
formParams.put("disksize", serverSpec.getDiskSizeGB() + "");
formParams.put("memorysize", serverSpec.getMemorySizeMB() + "");
formParams.put("cpucores", serverSpec.getCpuCores() + "");
formParams.put("transfer", serverSpec.getTransfer() + "");
formParams.put("transfer", serverSpec.getTransferGB() + "");
if (ip != null)
formParams.put("ip", ip);
if (description != null)