mirror of https://github.com/apache/jclouds.git
Added null checks in contructors and more use of Objects.equal/hashCode.
This commit is contained in:
parent
6d435742e1
commit
1fd77eb348
|
@ -42,6 +42,7 @@ public class DeviceDetails {
|
|||
private final DeviceType deviceType;
|
||||
|
||||
public DeviceDetails(int port, int deviceSlot, DeviceType deviceType) {
|
||||
checkNotNull(deviceType, "deviceType");
|
||||
this.port = port;
|
||||
this.deviceSlot = deviceSlot;
|
||||
this.deviceType = deviceType;
|
||||
|
|
|
@ -21,6 +21,8 @@ package org.jclouds.virtualbox.domain;
|
|||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Represents an optical medium (DVD) in a VirtualBox VM.
|
||||
* <p/>
|
||||
|
@ -32,6 +34,8 @@ public class IsoImage {
|
|||
private String sourcePath;
|
||||
|
||||
public IsoImage(DeviceDetails deviceDetails, String sourcePath) {
|
||||
checkNotNull(deviceDetails, "deviceDetails");
|
||||
checkNotNull(sourcePath, "sourcePath");
|
||||
this.deviceDetails = deviceDetails;
|
||||
this.sourcePath = sourcePath;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@ import org.virtualbox_4_1.NATProtocol;
|
|||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Represents a NAT network adapter in VirtualBox.
|
||||
* <p/>
|
||||
|
@ -36,6 +38,7 @@ public class NatAdapter {
|
|||
private final Set<RedirectRule> redirectRules = Sets.newLinkedHashSet();
|
||||
|
||||
public NatAdapter(Set<RedirectRule> redirectRules) {
|
||||
checkNotNull(redirectRules);
|
||||
this.redirectRules.addAll(redirectRules);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@ package org.jclouds.virtualbox.domain;
|
|||
import com.google.common.base.Objects;
|
||||
import org.virtualbox_4_1.NATProtocol;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* @author Mattias Holmqvist
|
||||
*/
|
||||
|
@ -34,6 +36,9 @@ public class RedirectRule {
|
|||
private final int guestPort;
|
||||
|
||||
public RedirectRule(NATProtocol protocol, String host, int hostPort, String guest, int guestPort) {
|
||||
checkNotNull(protocol);
|
||||
checkNotNull(host);
|
||||
checkNotNull(guest);
|
||||
this.protocol = protocol;
|
||||
this.host = host;
|
||||
this.hostPort = hostPort;
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.jclouds.virtualbox.domain;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import org.virtualbox_4_1.DeviceType;
|
||||
import org.virtualbox_4_1.StorageBus;
|
||||
|
||||
|
@ -30,7 +31,7 @@ import static org.jclouds.virtualbox.domain.HardDisk.DEFAULT_DISK_FORMAT;
|
|||
|
||||
/**
|
||||
* Represents a storage controller in a VirtualBox VM.
|
||||
*
|
||||
* <p/>
|
||||
* name is the unique name of the controller.
|
||||
* bus is the type of connection bus for the controller
|
||||
* hardDisks contains the hard disks that are attached (or should be attached) to this controller
|
||||
|
@ -45,6 +46,10 @@ public class StorageController {
|
|||
private Set<IsoImage> isoImages;
|
||||
|
||||
public StorageController(String name, StorageBus bus, Set<HardDisk> hardDisks, Set<IsoImage> isoImages) {
|
||||
checkNotNull(name, "name");
|
||||
checkNotNull(bus, "bus");
|
||||
checkNotNull(hardDisks, "hardDisks");
|
||||
checkNotNull(isoImages, "isoImages");
|
||||
this.name = name;
|
||||
this.bus = bus;
|
||||
this.hardDisks = hardDisks;
|
||||
|
@ -70,25 +75,19 @@ public class StorageController {
|
|||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
StorageController that = (StorageController) o;
|
||||
|
||||
if (bus != that.bus) return false;
|
||||
if (isoImages != null ? !isoImages.equals(that.isoImages) : that.isoImages != null) return false;
|
||||
if (hardDisks != null ? !hardDisks.equals(that.hardDisks) : that.hardDisks != null) return false;
|
||||
if (name != null ? !name.equals(that.name) : that.name != null) return false;
|
||||
|
||||
return true;
|
||||
if (o instanceof StorageController) {
|
||||
StorageController other = (StorageController) o;
|
||||
return Objects.equal(name, other.name) &&
|
||||
Objects.equal(bus, other.bus) &&
|
||||
Objects.equal(hardDisks, other.hardDisks) &&
|
||||
Objects.equal(isoImages, other.isoImages);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = name != null ? name.hashCode() : 0;
|
||||
result = 31 * result + (bus != null ? bus.hashCode() : 0);
|
||||
result = 31 * result + (hardDisks != null ? hardDisks.hashCode() : 0);
|
||||
result = 31 * result + (isoImages != null ? isoImages.hashCode() : 0);
|
||||
return result;
|
||||
return Objects.hashCode(name, bus, hardDisks, isoImages);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.util.*;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
/**
|
||||
* A description of a Virtual Machine in VirtualBox.
|
||||
|
@ -40,6 +41,11 @@ public class VmSpec {
|
|||
private final Set<StorageController> controllers;
|
||||
|
||||
public VmSpec(String vmId, String vmName, String osTypeId, long memory, boolean forceOverwrite, Set<StorageController> controllers, Map<Long, NatAdapter> natNetworkAdapters) {
|
||||
checkNotNull(vmId, "vmId");
|
||||
checkNotNull(vmName, "vmName");
|
||||
checkArgument(memory > 0, "memory must be > 0");
|
||||
checkNotNull(controllers, "controllers");
|
||||
checkNotNull(natNetworkAdapters, "natNetworkAdapters");
|
||||
this.vmId = vmId;
|
||||
this.vmName = vmName;
|
||||
this.osTypeId = osTypeId;
|
||||
|
|
Loading…
Reference in New Issue