mirror of
https://github.com/apache/jclouds.git
synced 2025-02-16 06:56:45 +00:00
Issue 695: Ensure collections are not null plus better null checking in other places
This commit is contained in:
parent
f86106cb09
commit
f69d3da354
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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<AssignedIpAddresses> {
|
||||
//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() {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ import javax.xml.bind.annotation.XmlElement;
|
||||
public class DeviceNetwork extends BaseNamedResource<DeviceNetwork> {
|
||||
|
||||
@XmlElement(name = "IpAddresses")
|
||||
private DeviceIps ipAddresses;
|
||||
private DeviceIps ipAddresses = new DeviceIps();
|
||||
|
||||
protected DeviceNetwork() {
|
||||
//For JAXB
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -51,17 +51,17 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
|
||||
|
||||
public static class Builder extends BaseResource.Builder<HardwareConfiguration> {
|
||||
|
||||
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<Action> 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<HardwareConfiguration> {
|
||||
* @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<HardwareConfiguration> {
|
||||
* @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<HardwareConfiguration> {
|
||||
}
|
||||
|
||||
@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<HardwareConfiguration> {
|
||||
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> {
|
||||
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<HardwareConfiguration> {
|
||||
@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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ public class NetworkReference extends BaseNamedResource<NetworkReference> {
|
||||
@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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -57,9 +57,9 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
|
||||
}
|
||||
|
||||
public static class Builder extends BaseNamedResource.Builder<VirtualMachine> {
|
||||
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<VirtualMachine> {
|
||||
private boolean customizationPending;
|
||||
private OperatingSystem operatingSystem;
|
||||
private HardwareConfiguration hardwareConfiguration;
|
||||
private VirtualMachineIpAddresses ipAddresses;
|
||||
private VirtualMachineIpAddresses ipAddresses = new VirtualMachineIpAddresses();
|
||||
|
||||
/**
|
||||
* @see VirtualMachine#getLinks
|
||||
*/
|
||||
public Builder links(Set<Link> 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<VirtualMachine> {
|
||||
* @see VirtualMachine#getActions
|
||||
*/
|
||||
public Builder actions(Set<Action> 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<VirtualMachine> {
|
||||
* @see VirtualMachine#getTasks
|
||||
*/
|
||||
public Builder tasks(Set<Task> 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<VirtualMachine> {
|
||||
* @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<VirtualMachine> {
|
||||
}
|
||||
|
||||
@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<VirtualMachine> {
|
||||
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<VirtualMachine> {
|
||||
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<VirtualMachine> {
|
||||
return operatingSystem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is optional, so may return null
|
||||
*/
|
||||
public VirtualMachineIpAddresses getIpAddresses() {
|
||||
return ipAddresses;
|
||||
}
|
||||
@ -411,11 +408,11 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
|
||||
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<VirtualMachine> {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user