mirror of https://github.com/apache/jclouds.git
Moved to Object.equals and Object.hashCode in domain objects
This commit is contained in:
parent
41a6bb4355
commit
9965d76e91
|
@ -19,8 +19,11 @@
|
|||
|
||||
package org.jclouds.virtualbox.domain;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import org.virtualbox_4_1.DeviceType;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Represents a specification for a device attachment.
|
||||
* <p/>
|
||||
|
@ -56,4 +59,60 @@ public class DeviceDetails {
|
|||
return deviceType;
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private int port;
|
||||
private int deviceSlot;
|
||||
private DeviceType deviceType;
|
||||
|
||||
public Builder port(int port) {
|
||||
this.port = port;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder deviceType(DeviceType deviceType) {
|
||||
this.deviceType = deviceType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder deviceSlot(int slot) {
|
||||
this.deviceSlot = slot;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DeviceDetails build() {
|
||||
checkNotNull(deviceType, "deviceType");
|
||||
return new DeviceDetails(port, deviceSlot, deviceType);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o instanceof DeviceDetails) {
|
||||
DeviceDetails other = (DeviceDetails) o;
|
||||
return Objects.equal(port, other.port) &&
|
||||
Objects.equal(deviceSlot, other.deviceSlot)
|
||||
&& Objects.equal(deviceType, other.deviceType);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(port, deviceSlot, deviceType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DeviceDetails{" +
|
||||
"port=" + port +
|
||||
", deviceSlot=" + deviceSlot +
|
||||
", deviceType=" + deviceType +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,14 +19,17 @@
|
|||
|
||||
package org.jclouds.virtualbox.domain;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* A representation of a hard disk in a VirtualBox VM.
|
||||
*
|
||||
* <p/>
|
||||
* diskPath is an absolute path to the file that is the location of the storage for the hard disk.
|
||||
* diskFormat is any of the formats supported by ISystemProperties.getMediumFormats() in the VirtualBox API.
|
||||
* This call is platform-dependent so the supported formats differ from host to host. The default format used is VDI.
|
||||
* deviceDetails contains information about how the HardDisk is attached to the StorageController.
|
||||
*
|
||||
*/
|
||||
public class HardDisk {
|
||||
|
||||
|
@ -37,6 +40,9 @@ public class HardDisk {
|
|||
private final DeviceDetails deviceDetails;
|
||||
|
||||
public HardDisk(DeviceDetails deviceDetails, String diskPath, String diskFormat) {
|
||||
checkNotNull(deviceDetails, "deviceDetails");
|
||||
checkNotNull(diskPath, "diskPath");
|
||||
checkNotNull(diskFormat, "diskFormat");
|
||||
this.diskPath = diskPath;
|
||||
this.diskFormat = diskFormat;
|
||||
this.deviceDetails = deviceDetails;
|
||||
|
@ -57,23 +63,26 @@ public class HardDisk {
|
|||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
if (o instanceof HardDisk) {
|
||||
HardDisk hardDisk = (HardDisk) o;
|
||||
|
||||
if (deviceDetails != null ? !deviceDetails.equals(hardDisk.deviceDetails) : hardDisk.deviceDetails != null)
|
||||
return Objects.equal(deviceDetails, hardDisk.deviceDetails) &&
|
||||
Objects.equal(diskFormat, hardDisk.diskFormat) &&
|
||||
Objects.equal(diskPath, hardDisk.diskPath);
|
||||
}
|
||||
return false;
|
||||
if (diskFormat != null ? !diskFormat.equals(hardDisk.diskFormat) : hardDisk.diskFormat != null) return false;
|
||||
if (diskPath != null ? !diskPath.equals(hardDisk.diskPath) : hardDisk.diskPath != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = diskFormat != null ? diskFormat.hashCode() : 0;
|
||||
result = 31 * result + (diskPath != null ? diskPath.hashCode() : 0);
|
||||
result = 31 * result + (deviceDetails != null ? deviceDetails.hashCode() : 0);
|
||||
return result;
|
||||
return Objects.hashCode(diskPath, diskFormat, deviceDetails);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "HardDisk{" +
|
||||
"diskFormat='" + diskFormat + '\'' +
|
||||
", diskPath='" + diskPath + '\'' +
|
||||
", deviceDetails=" + deviceDetails +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
|
@ -19,9 +19,11 @@
|
|||
|
||||
package org.jclouds.virtualbox.domain;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
/**
|
||||
* Represents an optical medium (DVD) in a VirtualBox VM.
|
||||
*
|
||||
* <p/>
|
||||
* sourcePath is the location of the .iso file to load the medium from.
|
||||
* deviceDetails contains information about how the Dvd is attached to the StorageController.
|
||||
*/
|
||||
|
@ -45,21 +47,17 @@ public class IsoImage {
|
|||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
IsoImage dvd = (IsoImage) o;
|
||||
|
||||
if (deviceDetails != null ? !deviceDetails.equals(dvd.deviceDetails) : dvd.deviceDetails != null) return false;
|
||||
if (sourcePath != null ? !sourcePath.equals(dvd.sourcePath) : dvd.sourcePath != null) return false;
|
||||
|
||||
return true;
|
||||
if (o instanceof IsoImage) {
|
||||
IsoImage other = (IsoImage) o;
|
||||
return Objects.equal(deviceDetails, other.deviceDetails) &&
|
||||
Objects.equal(sourcePath, other.sourcePath);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = deviceDetails != null ? deviceDetails.hashCode() : 0;
|
||||
result = 31 * result + (sourcePath != null ? sourcePath.hashCode() : 0);
|
||||
return result;
|
||||
return Objects.hashCode(deviceDetails, sourcePath);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,20 +19,21 @@
|
|||
|
||||
package org.jclouds.virtualbox.domain;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.virtualbox_4_1.NATProtocol;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Represents a NAT network adapter in VirtualBox.
|
||||
*
|
||||
* <p/>
|
||||
* redirectRules are the redirect rules that are applied to the network adapter.
|
||||
*/
|
||||
public class NatAdapter {
|
||||
|
||||
private final Set<RedirectRule> redirectRules = new HashSet<RedirectRule>();
|
||||
private final Set<RedirectRule> redirectRules = Sets.newLinkedHashSet();
|
||||
|
||||
public NatAdapter(Set<RedirectRule> redirectRules) {
|
||||
this.redirectRules.addAll(redirectRules);
|
||||
|
@ -44,8 +45,7 @@ public class NatAdapter {
|
|||
|
||||
public static class Builder {
|
||||
|
||||
private Set<RedirectRule> redirectRules = new HashSet<RedirectRule>();
|
||||
private long adapterSlot;
|
||||
private Set<RedirectRule> redirectRules = Sets.newLinkedHashSet();
|
||||
|
||||
public Builder tcpRedirectRule(String host, int hostPort, String guest, int guestPort) {
|
||||
redirectRules.add(new RedirectRule(NATProtocol.TCP, host, hostPort, guest, guestPort));
|
||||
|
@ -70,18 +70,16 @@ public class NatAdapter {
|
|||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
NatAdapter that = (NatAdapter) o;
|
||||
|
||||
if (redirectRules != null ? !redirectRules.equals(that.redirectRules) : that.redirectRules != null) return false;
|
||||
|
||||
return true;
|
||||
if (o instanceof NatAdapter) {
|
||||
NatAdapter other = (NatAdapter) o;
|
||||
return Objects.equal(redirectRules, other.redirectRules);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return redirectRules != null ? redirectRules.hashCode() : 0;
|
||||
return Objects.hashCode(redirectRules);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.jclouds.virtualbox.domain;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import org.virtualbox_4_1.NATProtocol;
|
||||
|
||||
/**
|
||||
|
@ -59,4 +60,34 @@ public class RedirectRule {
|
|||
public int getGuestPort() {
|
||||
return guestPort;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o instanceof RedirectRule) {
|
||||
RedirectRule other = (RedirectRule) o;
|
||||
return Objects.equal(protocol, other.protocol) &&
|
||||
Objects.equal(host, other.host) &&
|
||||
Objects.equal(hostPort, other.hostPort) &&
|
||||
Objects.equal(guest, other.guest) &&
|
||||
Objects.equal(guestPort, other.guestPort);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(protocol, host, hostPort, guest, guestPort);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RedirectRule{" +
|
||||
"protocol=" + protocol +
|
||||
", host='" + host + '\'' +
|
||||
", hostPort=" + hostPort +
|
||||
", guest='" + guest + '\'' +
|
||||
", guestPort=" + guestPort +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
package org.jclouds.virtualbox.domain;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
@ -122,30 +124,21 @@ public class VmSpec {
|
|||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
VmSpec that = (VmSpec) o;
|
||||
|
||||
if (forceOverwrite != that.forceOverwrite) return false;
|
||||
if (controllers != null ? !controllers.equals(that.controllers) : that.controllers != null) return false;
|
||||
if (natNetworkAdapters != null ? !natNetworkAdapters.equals(that.natNetworkAdapters) : that.natNetworkAdapters != null)
|
||||
if (o instanceof VmSpec) {
|
||||
VmSpec other = (VmSpec) o;
|
||||
return Objects.equal(vmId, other.vmId) &&
|
||||
Objects.equal(vmName, other.vmName) &&
|
||||
Objects.equal(osTypeId, other.osTypeId) &&
|
||||
Objects.equal(forceOverwrite, other.forceOverwrite) &&
|
||||
Objects.equal(natNetworkAdapters, other.natNetworkAdapters) &&
|
||||
Objects.equal(controllers, other.controllers);
|
||||
}
|
||||
return false;
|
||||
if (osTypeId != null ? !osTypeId.equals(that.osTypeId) : that.osTypeId != null) return false;
|
||||
if (vmId != null ? !vmId.equals(that.vmId) : that.vmId != null) return false;
|
||||
if (vmName != null ? !vmName.equals(that.vmName) : that.vmName != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = vmName != null ? vmName.hashCode() : 0;
|
||||
result = 31 * result + (osTypeId != null ? osTypeId.hashCode() : 0);
|
||||
result = 31 * result + (vmId != null ? vmId.hashCode() : 0);
|
||||
result = 31 * result + (forceOverwrite ? 1 : 0);
|
||||
result = 31 * result + (natNetworkAdapters != null ? natNetworkAdapters.hashCode() : 0);
|
||||
result = 31 * result + (controllers != null ? controllers.hashCode() : 0);
|
||||
return result;
|
||||
return Objects.hashCode(vmId, vmName, osTypeId, forceOverwrite, natNetworkAdapters, controllers);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
|
|
Loading…
Reference in New Issue