diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Actions.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Actions.java index 396aec968f..5633403e8e 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Actions.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Actions.java @@ -26,6 +26,8 @@ import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; +import static com.google.common.base.Preconditions.checkNotNull; + /** * Wraps individual Action elements. * Needed because parsing is done with JAXB and it does not handle Generic collections @@ -38,6 +40,7 @@ public class Actions { @XmlElement(name = "Action") void setAction(Action action) { + checkNotNull(action,"action"); this.actions.add(action); } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/AssignedIpAddresses.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/AssignedIpAddresses.java index f808bd515d..3c34b37b69 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/AssignedIpAddresses.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/AssignedIpAddresses.java @@ -23,6 +23,8 @@ import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource; import javax.xml.bind.annotation.XmlElement; import java.net.URI; +import static com.google.common.base.Preconditions.checkNotNull; + /** * @author Jason King */ @@ -31,13 +33,15 @@ public class AssignedIpAddresses extends BaseResource { //TODO builder stuff @XmlElement(name = "Actions", required = true) - private Actions actions; + private Actions actions = new Actions(); @XmlElement(name = "Networks", required = true) - private DeviceNetworks networks; + private DeviceNetworks networks = new DeviceNetworks(); public AssignedIpAddresses(URI href, String type, Actions actions, DeviceNetworks networks) { super(href, type); + checkNotNull(actions,"actions"); + checkNotNull(networks,"networks"); } protected AssignedIpAddresses() { diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/DeviceIps.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/DeviceIps.java index fbb9315e7b..58db0bb378 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/DeviceIps.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/DeviceIps.java @@ -25,6 +25,9 @@ import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.util.Preconditions2.checkNotEmpty; + /** * Wraps individual IpAddresses * @author Jason King @@ -39,6 +42,8 @@ public class DeviceIps { @XmlElement(name = "IpAddress") void setIpAddress(String ipAddress) { + checkNotNull(ipAddress,"ipAddress"); + checkNotEmpty(ipAddress, "ipAddress"); this.ipAddresses.add(ipAddress); } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/DeviceNetwork.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/DeviceNetwork.java index 0ed42ff4c1..8f82630b51 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/DeviceNetwork.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/DeviceNetwork.java @@ -29,7 +29,7 @@ import javax.xml.bind.annotation.XmlElement; public class DeviceNetwork extends BaseNamedResource { @XmlElement(name = "IpAddresses") - private DeviceIps ipAddresses; + private DeviceIps ipAddresses = new DeviceIps(); protected DeviceNetwork() { //For JAXB diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/DeviceNetworks.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/DeviceNetworks.java index 716c9961d1..07f1282fe8 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/DeviceNetworks.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/DeviceNetworks.java @@ -25,6 +25,8 @@ import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; +import static com.google.common.base.Preconditions.checkNotNull; + /** * Container for DeviceNetwork items * @author Jason King @@ -39,6 +41,7 @@ public class DeviceNetworks { @XmlElement(name = "Network") void setDeviceNetwork(DeviceNetwork deviceNetwork) { + checkNotNull(deviceNetwork,"deviceNetwork"); this.deviceNetworks.add(deviceNetwork); } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Disks.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Disks.java index c660876b04..ccfcaa171a 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Disks.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Disks.java @@ -26,6 +26,8 @@ import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; +import static com.google.common.base.Preconditions.checkNotNull; + /** * Wraps individual Disk elements. * Needed because parsing is done with JAXB and it does not handle Generic collections @@ -38,6 +40,7 @@ public class Disks { @XmlElement(name = "Disk") public void setVirtualDisk(VirtualDisk disk) { + checkNotNull(disk,"disk"); this.disks.add(disk); } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/HardwareConfiguration.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/HardwareConfiguration.java index 7c55a63f99..e01f73ad80 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/HardwareConfiguration.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/HardwareConfiguration.java @@ -51,17 +51,17 @@ public class HardwareConfiguration extends BaseResource { public static class Builder extends BaseResource.Builder { - private Actions actions; + private Actions actions = new Actions(); private int processorCount; private Memory memory; - private Disks disks; - private Nics nics; + private Disks disks = new Disks(); + private Nics nics = new Nics(); /** * @see HardwareConfiguration#getActions */ public Builder actions(Set actions) { - this.actions = new Actions(); + checkNotNull(actions,"actions"); for(Action action:actions) this.actions.setAction(action); return this; } @@ -86,7 +86,7 @@ public class HardwareConfiguration extends BaseResource { * @see HardwareConfiguration#getDisks */ public Builder disks(Disks disks) { - this.disks = disks; + this.disks = checkNotNull(disks,"disks");; return this; } @@ -94,7 +94,7 @@ public class HardwareConfiguration extends BaseResource { * @see HardwareConfiguration#getDisks */ public Builder nics(Nics nics) { - this.nics = nics; + this.nics = checkNotNull(nics,"nics");; return this; } @@ -145,7 +145,7 @@ public class HardwareConfiguration extends BaseResource { } @XmlElement(name = "Actions", required = false) - private Actions actions; + private Actions actions = new Actions(); @XmlElement(name = "ProcessorCount", required = true) private int processorCount; @@ -154,17 +154,17 @@ public class HardwareConfiguration extends BaseResource { private Memory memory; @XmlElement(name = "Disks", required = false) - private Disks disks; + private Disks disks = new Disks(); @XmlElement(name = "Nics", required = false) - private Nics nics; + private Nics nics = new Nics(); - public HardwareConfiguration(@Nullable Actions actions, int processorCount, @Nullable Memory memory, @Nullable Disks disks, @Nullable Nics nics) { + public HardwareConfiguration(Actions actions, int processorCount, @Nullable Memory memory, Disks disks, Nics nics) { this.actions = checkNotNull(actions, "actions"); this.processorCount = processorCount; this.memory = memory; - this.disks = disks; - this.nics = nics; + this.disks = checkNotNull(disks, "disks"); + this.nics = checkNotNull(nics, "nics"); } protected HardwareConfiguration() { @@ -200,14 +200,11 @@ public class HardwareConfiguration extends BaseResource { HardwareConfiguration that = (HardwareConfiguration) o; if (processorCount != that.processorCount) return false; - if (actions != null ? !actions.equals(that.actions) : that.actions != null) - return false; - if (disks != null ? !disks.equals(that.disks) : that.disks != null) - return false; + if (!actions.equals(that.actions)) return false; + if (!disks.equals(that.disks)) return false; if (memory != null ? !memory.equals(that.memory) : that.memory != null) return false; - if (nics != null ? !nics.equals(that.nics) : that.nics != null) - return false; + if (!nics.equals(that.nics)) return false; return true; } @@ -215,11 +212,11 @@ public class HardwareConfiguration extends BaseResource { @Override public int hashCode() { int result = super.hashCode(); - result = 31 * result + (actions != null ? actions.hashCode() : 0); + result = 31 * result + actions.hashCode(); result = 31 * result + processorCount; result = 31 * result + (memory != null ? memory.hashCode() : 0); - result = 31 * result + (disks != null ? disks.hashCode() : 0); - result = 31 * result + (nics != null ? nics.hashCode() : 0); + result = 31 * result + disks.hashCode(); + result = 31 * result + nics.hashCode(); return result; } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Layout.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Layout.java index 97fbcacc6f..c1e165df48 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Layout.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Layout.java @@ -18,6 +18,8 @@ */ package org.jclouds.tmrk.enterprisecloud.domain; +import org.jclouds.javax.annotation.Nullable; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; @@ -38,7 +40,7 @@ public class Layout { @XmlElement(name = "Row") private Row row; - public Layout(Group group, Row row) { + public Layout(@Nullable Group group, @Nullable Row row) { this.group = group; this.row = row; } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/NetworkReference.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/NetworkReference.java index 815b964c63..bc3f6de685 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/NetworkReference.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/NetworkReference.java @@ -135,7 +135,7 @@ public class NetworkReference extends BaseNamedResource { @XmlElement(name = "NetworkType") private NetworkType networkType; - public NetworkReference(URI href, String type, String name, NetworkType networkType) { + public NetworkReference(URI href, String type, String name,@Nullable NetworkType networkType) { super(href, type, name); this.networkType = networkType; } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Tasks.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Tasks.java index 662b58061a..6edd16c4ec 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Tasks.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Tasks.java @@ -26,6 +26,8 @@ import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; +import static com.google.common.base.Preconditions.checkNotNull; + /** * Wraps individual Task elements. * Needed because parsing is done with JAXB and it does not handle Generic collections @@ -38,6 +40,7 @@ public class Tasks { @XmlElement(name = "Task") public void setTask(Task task) { + checkNotNull(task,"task"); tasks.add(task); } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/VirtualMachine.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/VirtualMachine.java index 6c72ce5782..ed53132ccf 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/VirtualMachine.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/VirtualMachine.java @@ -57,9 +57,9 @@ public class VirtualMachine extends BaseNamedResource { } public static class Builder extends BaseNamedResource.Builder { - private Links links; - private Actions actions; - private Tasks tasks; + private Links links = new Links(); + private Actions actions = new Actions(); + private Tasks tasks = new Tasks(); private String description; private VirtualMachineStatus status; @@ -70,13 +70,13 @@ public class VirtualMachine extends BaseNamedResource { private boolean customizationPending; private OperatingSystem operatingSystem; private HardwareConfiguration hardwareConfiguration; - private VirtualMachineIpAddresses ipAddresses; + private VirtualMachineIpAddresses ipAddresses = new VirtualMachineIpAddresses(); /** * @see VirtualMachine#getLinks */ public Builder links(Set links) { - this.links = new Links(); + checkNotNull(links,"links"); for(Link link:links) this.links.setLink(link); return this; } @@ -85,7 +85,7 @@ public class VirtualMachine extends BaseNamedResource { * @see VirtualMachine#getActions */ public Builder actions(Set actions) { - this.actions = new Actions(); + checkNotNull(actions,"actions"); for(Action action:actions) this.actions.setAction(action); return this; } @@ -94,7 +94,7 @@ public class VirtualMachine extends BaseNamedResource { * @see VirtualMachine#getTasks */ public Builder tasks(Set tasks) { - this.tasks = new Tasks(); + checkNotNull(tasks,"tasks"); for(Task task: tasks) this.tasks.setTask(task); return this; } @@ -184,7 +184,7 @@ public class VirtualMachine extends BaseNamedResource { * @see VirtualMachine#getIpAddresses() */ public Builder ipAddresses(VirtualMachineIpAddresses ipAddresses) { - this.ipAddresses = ipAddresses; + this.ipAddresses = checkNotNull(ipAddresses,"ipAddresses"); return this; } @@ -264,13 +264,13 @@ public class VirtualMachine extends BaseNamedResource { } @XmlElement(name = "Links", required = true) - private Links links; + private Links links = new Links(); @XmlElement(name = "Tasks", required = true) - private Tasks tasks; + private Tasks tasks = new Tasks(); @XmlElement(name = "Actions", required = true) - private Actions actions; + private Actions actions = new Actions(); @XmlElement(name = "Description", required = true) private String description; @@ -300,7 +300,7 @@ public class VirtualMachine extends BaseNamedResource { private HardwareConfiguration hardwareConfiguation; @XmlElement(name = "IpAddresses", required = false) - private VirtualMachineIpAddresses ipAddresses; + private VirtualMachineIpAddresses ipAddresses = new VirtualMachineIpAddresses(); public VirtualMachine(URI href, String type, String name, Tasks tasks, Actions actions, Links links, String description, @Nullable Layout layout, VirtualMachineStatus status, boolean poweredOn, @Nullable ToolsStatus toolsStatus, @Nullable VirtualMachineMediaStatus mediaStatus, boolean customizationPending, @@ -319,7 +319,7 @@ public class VirtualMachine extends BaseNamedResource { this.customizationPending = customizationPending; this.operatingSystem = operatingSystem; this.hardwareConfiguation = hardwareConfiguration; - this.ipAddresses = ipAddresses; + this.ipAddresses = checkNotNull(ipAddresses, "ipAddresses"); } protected VirtualMachine() { @@ -393,9 +393,6 @@ public class VirtualMachine extends BaseNamedResource { return operatingSystem; } - /** - * Is optional, so may return null - */ public VirtualMachineIpAddresses getIpAddresses() { return ipAddresses; } @@ -411,11 +408,11 @@ public class VirtualMachine extends BaseNamedResource { if (customizationPending != that.customizationPending) return false; if (poweredOn != that.poweredOn) return false; if (!actions.equals(that.actions)) return false; - if (!description.equals(that.description)) return false; + if (description != null ? !description.equals(that.description) : that.description != null) + return false; if (hardwareConfiguation != null ? !hardwareConfiguation.equals(that.hardwareConfiguation) : that.hardwareConfiguation != null) return false; - if (ipAddresses != null ? !ipAddresses.equals(that.ipAddresses) : that.ipAddresses != null) - return false; + if (!ipAddresses.equals(that.ipAddresses)) return false; if (layout != null ? !layout.equals(that.layout) : that.layout != null) return false; if (!links.equals(that.links)) return false; @@ -435,16 +432,16 @@ public class VirtualMachine extends BaseNamedResource { result = 31 * result + links.hashCode(); result = 31 * result + tasks.hashCode(); result = 31 * result + actions.hashCode(); - result = 31 * result + description.hashCode(); + result = 31 * result + (description != null ? description.hashCode() : 0); result = 31 * result + (layout != null ? layout.hashCode() : 0); - result = 31 * result + status.hashCode(); + result = 31 * result + (status != null ? status.hashCode() : 0); result = 31 * result + (poweredOn ? 1 : 0); result = 31 * result + (toolsStatus != null ? toolsStatus.hashCode() : 0); result = 31 * result + (mediaStatus != null ? mediaStatus.hashCode() : 0); result = 31 * result + (customizationPending ? 1 : 0); result = 31 * result + (operatingSystem != null ? operatingSystem.hashCode() : 0); result = 31 * result + (hardwareConfiguation != null ? hardwareConfiguation.hashCode() : 0); - result = 31 * result + (ipAddresses != null ? ipAddresses.hashCode() : 0); + result = 31 * result + ipAddresses.hashCode(); return result; } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/VirtualMachineIpAddresses.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/VirtualMachineIpAddresses.java index e6a89437cc..0ae352ad2f 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/VirtualMachineIpAddresses.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/VirtualMachineIpAddresses.java @@ -32,7 +32,7 @@ import java.util.Set; public class VirtualMachineIpAddresses { @XmlElement(name = "AssignedIpAddresses") - private AssignedIpAddresses assignedIpAddresses; + private AssignedIpAddresses assignedIpAddresses = new AssignedIpAddresses(); protected VirtualMachineIpAddresses() { // For JAXB