From 0e35b3f623e18596b169147da15011b89f196309 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Sat, 3 Nov 2012 14:38:33 -0700 Subject: [PATCH] Implement Comparable in GoGrid ErrorResponse Gson collects errors in a TreeMap which requires a well-behaved Comparable method. This addresses a Java 7 GoGrid failure seen in GridServerClientExpectTest.testGetServerCredentialsWhenNotFoundThrowsResourceNotFoundExceptionWithNiceMessage: java.lang.ClassCastException: org.jclouds.gogrid.domain.internal.ErrorResponse cannot be cast to java.lang.Comparable --- .../jclouds/gogrid/domain/internal/ErrorResponse.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/providers/gogrid/src/main/java/org/jclouds/gogrid/domain/internal/ErrorResponse.java b/providers/gogrid/src/main/java/org/jclouds/gogrid/domain/internal/ErrorResponse.java index 534a969c73..a776e35a65 100644 --- a/providers/gogrid/src/main/java/org/jclouds/gogrid/domain/internal/ErrorResponse.java +++ b/providers/gogrid/src/main/java/org/jclouds/gogrid/domain/internal/ErrorResponse.java @@ -24,13 +24,14 @@ import java.beans.ConstructorProperties; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.ComparisonChain; /** * Class ErrorResponse * * @author Oleksiy Yarmula */ -public class ErrorResponse { +public class ErrorResponse implements Comparable { public static Builder builder() { return new ConcreteBuilder(); @@ -113,6 +114,14 @@ public class ErrorResponse { && Objects.equal(this.errorCode, that.errorCode); } + @Override + public int compareTo(ErrorResponse that) { + return ComparisonChain.start() + .compare(errorCode, that.errorCode) + .compare(message, that.message) + .result(); + } + protected ToStringHelper string() { return Objects.toStringHelper(this) .add("message", message).add("errorCode", errorCode);