Refactor Flavor class so that it is immutable

This commit is contained in:
Matt Stephenson 2011-12-28 10:45:34 -06:00
parent dbb7e5fb5d
commit 481f7a4b2f
2 changed files with 26 additions and 34 deletions

View File

@ -27,65 +27,49 @@ package org.jclouds.openstack.nova.domain;
*/ */
public class Flavor extends Resource { public class Flavor extends Resource {
public Flavor() { private final int id;
private final String name;
private final Integer disk;
private final Integer ram;
private final Integer vcpus;
//Required because of how Gson is being used to do wire marshalling with the Server class
private Flavor(){
id=0;
name=null;
disk=null;
ram=null;
vcpus=null;
} }
@Override public Flavor(int id, String name, Integer disk, Integer ram, Integer vcpus) {
public String toString() {
return "Flavor [disk=" + disk + ", id=" + id + ", name=" + name + ", ram=" + ram + ", vcpus=" + vcpus +"]";
}
public Flavor(int id, String name) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.disk = disk;
this.ram = ram;
this.vcpus = vcpus;
} }
private int id;
private String name;
private Integer disk;
private Integer ram;
private Integer vcpus;
public Integer getDisk() { public Integer getDisk() {
return disk; return disk;
} }
public void setDisk(Integer value) {
this.disk = value;
}
public int getId() { public int getId() {
return id; return id;
} }
public void setId(int value) {
this.id = value;
}
public String getName() { public String getName() {
return name; return name;
} }
public void setName(String value) {
this.name = value;
}
public Integer getRam() { public Integer getRam() {
return ram; return ram;
} }
public void setRam(Integer value) {
this.ram = value;
}
public Integer getVcpus() { public Integer getVcpus() {
return vcpus; return vcpus;
} }
public void setVcpus(Integer value) {
this.vcpus = value;
}
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
@ -132,4 +116,8 @@ public class Flavor extends Resource {
return true; return true;
} }
@Override
public String toString() {
return "Flavor [disk=" + disk + ", id=" + id + ", name=" + name + ", ram=" + ram + ", vcpus=" + vcpus +"]";
}
} }

View File

@ -67,7 +67,11 @@ public class Resource {
}; };
} }
private final ConcurrentSkipListMap<LinkType,URI> orderedSelfReferences = new ConcurrentSkipListMap<LinkType,URI>(); private final ConcurrentSkipListMap<LinkType,URI> orderedSelfReferences;
public Resource(){
orderedSelfReferences = new ConcurrentSkipListMap<LinkType,URI>();
}
private void populateOrderedSelfReferences() { private void populateOrderedSelfReferences() {
for (Map<String, String> linkProperties : links) { for (Map<String, String> linkProperties : links) {