Fixing equals method on domain objects

This commit is contained in:
Andrew Donald Kennedy 2012-02-08 13:32:25 +00:00
parent 78fb8bd919
commit 9153d887af
9 changed files with 52 additions and 32 deletions

View File

@ -147,7 +147,9 @@ public class Entity extends EntityType<Entity> {
@Override
public boolean equals(Object o) {
if (!super.equals(o))
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Entity that = Entity.class.cast(o);
return super.equals(that);

View File

@ -224,7 +224,9 @@ public class EntityType<T extends EntityType<T>> extends ResourceType<T> {
@Override
public boolean equals(Object o) {
if (!super.equals(o))
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
EntityType<?> that = EntityType.class.cast(o);
return super.equals(that) &&

View File

@ -18,9 +18,14 @@
*/
package org.jclouds.vcloud.director.v1_5.domain;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NS;
import static com.google.common.base.Objects.*;
import static com.google.common.base.Preconditions.*;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.*;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
@ -117,7 +122,7 @@ public class Error {
@XmlAttribute
private String message;
@XmlAttribute
private int majorErrorCode;
private Integer majorErrorCode;
@XmlAttribute
private String minorErrorCode;
@XmlAttribute
@ -125,9 +130,9 @@ public class Error {
@XmlAttribute
private String stackTrace;
private Error(String message, int majorErrorCode, String minorErrorCode) {
private Error(String message, Integer majorErrorCode, String minorErrorCode) {
this.message = checkNotNull(message, "message");
this.majorErrorCode = majorErrorCode;
this.majorErrorCode = checkNotNull(majorErrorCode, "majorErrorCode");
this.minorErrorCode = checkNotNull(minorErrorCode, "minorErrorCode");
}
@ -145,7 +150,7 @@ public class Error {
/**
* The class of the error. Matches the HTTP status code.
*/
public int getMajorErrorCode() {
public Integer getMajorErrorCode() {
return majorErrorCode;
}
@ -182,10 +187,11 @@ public class Error {
this.stackTrace = stackTrace;
}
@Override
@Override
public boolean equals(Object o) {
if (!super.equals(o))
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Error that = (Error) o;
return equal(this.message, that.message) &&
@ -197,15 +203,14 @@ public class Error {
@Override
public int hashCode() {
return super.hashCode() + Objects.hashCode(message, majorErrorCode, minorErrorCode, vendorSpecificErrorCode, stackTrace);
return Objects.hashCode(message, majorErrorCode, minorErrorCode, vendorSpecificErrorCode, stackTrace);
}
@Override
public String toString() {
return Objects.toStringHelper("")
.add("message", message)
.add("majorErrorCode", majorErrorCode)
.add("minorErrorCode", minorErrorCode)
.add("message", message).add("majorErrorCode", majorErrorCode).add("minorErrorCode", minorErrorCode)
.add("vendorSpecificErrorCode", vendorSpecificErrorCode).add("stackTrace", stackTrace)
.toString();
}
}

View File

@ -159,7 +159,9 @@ public class Link extends ReferenceType<Link> {
@Override
public boolean equals(Object o) {
if (!super.equals(o))
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Link that = (Link) o;
return super.equals(that) && equal(this.rel, that.rel);

View File

@ -50,6 +50,7 @@ public class Metadata extends ResourceType<Metadata>{
return new Builder();
}
@Override
public Builder toBuilder() {
return new Builder().fromMetadataList(this);
}
@ -74,6 +75,7 @@ public class Metadata extends ResourceType<Metadata>{
return this;
}
@Override
public Metadata build() {
Metadata metadata = new Metadata(href, metadataEntries);
metadata.setType(type);
@ -140,7 +142,9 @@ public class Metadata extends ResourceType<Metadata>{
@Override
public boolean equals(Object o) {
if (!super.equals(o))
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Metadata that = Metadata.class.cast(o);
return super.equals(that) && equal(metadata, that.metadata);

View File

@ -49,6 +49,7 @@ public class MetadataEntry extends ResourceType<MetadataEntry> {
return new Builder();
}
@Override
public Builder toBuilder() {
return new Builder().fromMetadata(this);
}
@ -73,6 +74,7 @@ public class MetadataEntry extends ResourceType<MetadataEntry> {
return this;
}
@Override
public MetadataEntry build() {
MetadataEntry metadataEntry = new MetadataEntry(href, key, value);
metadataEntry.setType(type);
@ -132,13 +134,12 @@ public class MetadataEntry extends ResourceType<MetadataEntry> {
this.value = checkNotNull(value, "value");
}
@XmlElement(namespace = NS, name = "K")
@XmlElement(namespace = NS, name = "Key")
private String key;
@XmlElement(namespace = NS, name = "Value")
private String value;
/**
*
* @return key of the entry
*/
public String getKey() {
@ -146,17 +147,17 @@ public class MetadataEntry extends ResourceType<MetadataEntry> {
}
/**
*
* @return value of the entry
*/
public String getValue() {
return value;
}
@Override
public boolean equals(Object o) {
if (!super.equals(o))
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
MetadataEntry that = MetadataEntry.class.cast(o);
return super.equals(that) && equal(key, that.key);

View File

@ -183,7 +183,9 @@ public class Org extends EntityType<Org> {
@Override
public boolean equals(Object o) {
if (!super.equals(o))
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Org that = Org.class.cast(o);
return super.equals(that) && equal(fullName, that.fullName);

View File

@ -461,10 +461,13 @@ public class Task extends EntityType<Task> {
@Override
public boolean equals(Object o) {
if (!super.equals(o))
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Task that = Task.class.cast(o);
return super.equals(that) && equal(this.error, that.error) && equal(this.org, that.org) &&
return super.equals(that) &&
equal(this.error, that.error) && equal(this.org, that.org) &&
equal(this.progress, that.progress) && equal(this.status, that.status) &&
equal(this.operation, that.operation) && equal(this.operationName, that.operationName) &&
equal(this.startTime, that.startTime) && equal(this.endTime, that.endTime) &&

View File

@ -28,9 +28,8 @@ import java.util.Set;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import org.jclouds.vcloud.director.v1_5.domain.Org.Builder;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;