From deff082a4898ca6c4eb7f4eb9f6302d82242528c Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Tue, 10 Jan 2012 12:19:35 -0800 Subject: [PATCH] allowed http request subclasses to match equals/hashCode when they render the same data; useful in testing --- .../java/org/jclouds/http/HttpRequest.java | 48 ++++--------------- 1 file changed, 9 insertions(+), 39 deletions(-) diff --git a/core/src/main/java/org/jclouds/http/HttpRequest.java b/core/src/main/java/org/jclouds/http/HttpRequest.java index 340ab88fba..67c7ab7a1d 100644 --- a/core/src/main/java/org/jclouds/http/HttpRequest.java +++ b/core/src/main/java/org/jclouds/http/HttpRequest.java @@ -22,13 +22,12 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import java.net.URI; -import java.util.Arrays; import java.util.List; +import org.jclouds.io.Payload; import org.jclouds.javax.annotation.Nullable; -import org.jclouds.io.Payload; - +import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Multimap; @@ -191,55 +190,26 @@ public class HttpRequest extends HttpMessage { public Builder toBuilder() { return Builder.from(this); } - + @Override public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + ((endpoint == null) ? 0 : endpoint.hashCode()); - result = prime * result + ((method == null) ? 0 : method.hashCode()); - result = prime * result + ((payload == null) ? 0 : payload.hashCode()); - result = prime * result + ((headers == null) ? 0 : headers.hashCode()); - result = prime * result + ((requestFilters == null) ? 0 : requestFilters.hashCode()); - result = prime * result + Arrays.hashCode(skips); - return result; + return Objects.hashCode(method, endpoint, headers, payload); } @Override public boolean equals(Object obj) { if (this == obj) return true; - if (!super.equals(obj)) - return false; - if (getClass() != obj.getClass()) + if (!(obj instanceof HttpRequest)) return false; HttpRequest other = (HttpRequest) obj; - if (endpoint == null) { - if (other.endpoint != null) - return false; - } else if (!endpoint.equals(other.endpoint)) + if (!Objects.equal(method, other.method)) return false; - if (method == null) { - if (other.method != null) - return false; - } else if (!method.equals(other.method)) + if (!Objects.equal(endpoint, other.endpoint)) return false; - if (payload == null) { - if (other.payload != null) - return false; - } else if (!payload.equals(other.payload)) + if (!Objects.equal(headers, other.headers)) return false; - if (headers == null) { - if (other.headers != null) - return false; - } else if (!headers.equals(other.headers)) - return false; - if (requestFilters == null) { - if (other.requestFilters != null) - return false; - } else if (!requestFilters.equals(other.requestFilters)) - return false; - if (!Arrays.equals(skips, other.skips)) + if (!Objects.equal(payload, other.payload)) return false; return true; }